Disappointing LMR Results

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

theturk1234
Posts: 52
Joined: Tue Jul 12, 2016 5:28 am

Disappointing LMR Results

Post by theturk1234 »

I've tried lately to add LMR to my engine, but the results are not looking good. I'm losing like 100 ELO with the changes.
Here's the code for the LMR part of the engine:

Code: Select all

for&#40;int i = 0; i < moves.length&#40;); i++)
    &#123;
        Nodes++;
        move.From = moves&#91;i&#93;.From;
        move.To = moves&#91;i&#93;.To;
        move.Move_Type = moves&#91;i&#93;.Move_Type;
        MakeMove&#40;move&#41;;
        int score;
        bool dofullsearch = true;
        if&#40;depth > 2
		   && i > 3
		   && (!moves&#91;i&#93;.isCapture&#41;)
		   &#123;
		   		score = -AlphaBeta&#40;-&#40;alpha + 1&#41;, -alpha, depth - 2, &line, true&#41;;
		   		dofullsearch = score > alpha;
		   &#125;
		  if&#40;dofullsearch&#41;
		  &#123;
			  score = -AlphaBeta&#40;-beta, -alpha, depth - 1, &line, true&#41;;
		  &#125;
        move.Undo_Move&#40;);
        if&#40;score >= beta&#41;
        &#123;
        	TT.save&#40;depth, beta, pline->argmove&#91;0&#93;, Beta, Get_Current_Hash_Key&#40;));
        	return beta;
        &#125;
        if&#40;score > alpha&#41;
        &#123;
        	pline->argmove&#91;0&#93; = move;
            pline->score = score;
            memcpy&#40;pline->argmove + 1, line.argmove, line.cmove * sizeof&#40;Move&#41;);
            pline->cmove = line.cmove + 1;
            alpha = score;
            node = Exact;
        &#125;
    &#125;
I know Stockfish tests if the current node is a PV node and does not reduce in this case. How do I determine if the current node is a PV node?
Also, am I doing anything obviously wrong with LMR here?

Thanks,
David Cimbalista
tttony
Posts: 264
Joined: Sun Apr 24, 2011 12:33 am

Re: Disappointing LMR Results

Post by tttony »

You are missing some important things, take a look here: https://web.archive.org/web/20150212051 ... m/lmr.html

To know the node type: https://chessprogramming.wikispaces.com/Node+Types

Also I recommend to implement some heuristic like: https://chessprogramming.wikispaces.com ... +Heuristic
smatovic
Posts: 2576
Joined: Wed Mar 10, 2010 10:18 pm
Location: Hamburg, Germany
Full name: Srdja Matovic

Re: Disappointing LMR Results

Post by smatovic »

To implement some of these conditions could help:

http://chessprogramming.wikispaces.com/ ... Conditions

--
Srdja
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: Disappointing LMR Results

Post by lauriet »

Hopefully your move ordering is correct, otherwise lmr wont work
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: Disappointing LMR Results

Post by lauriet »

Hopefully your move ordering is correct, otherwise lmr wont work
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: Disappointing LMR Results

Post by lauriet »

Hopefully your move ordering is correct, otherwise lmr wont work
Karlo Bala
Posts: 373
Joined: Wed Mar 22, 2006 10:17 am
Location: Novi Sad, Serbia
Full name: Karlo Balla

Re: Disappointing LMR Results

Post by Karlo Bala »

lauriet wrote:Hopefully your move ordering is correct, otherwise lmr wont work
LMR works even with randomly sorted move list.
Best Regards,
Karlo Balla Jr.
Karlo Bala
Posts: 373
Joined: Wed Mar 22, 2006 10:17 am
Location: Novi Sad, Serbia
Full name: Karlo Balla

Re: Disappointing LMR Results

Post by Karlo Bala »

theturk1234 wrote:I've tried lately to add LMR to my engine, but the results are not looking good. I'm losing like 100 ELO with the changes.
Here's the code for the LMR part of the engine:

Code: Select all

for&#40;int i = 0; i < moves.length&#40;); i++)
    &#123;
        Nodes++;
        move.From = moves&#91;i&#93;.From;
        move.To = moves&#91;i&#93;.To;
        move.Move_Type = moves&#91;i&#93;.Move_Type;
        MakeMove&#40;move&#41;;
        int score;
        bool dofullsearch = true;
        if&#40;depth > 2
		   && i > 3
		   && (!moves&#91;i&#93;.isCapture&#41;)
		   &#123;
		   		score = -AlphaBeta&#40;-&#40;alpha + 1&#41;, -alpha, depth - 2, &line, true&#41;;
		   		dofullsearch = score > alpha;
		   &#125;
		  if&#40;dofullsearch&#41;
		  &#123;
			  score = -AlphaBeta&#40;-beta, -alpha, depth - 1, &line, true&#41;;
		  &#125;
        move.Undo_Move&#40;);
        if&#40;score >= beta&#41;
        &#123;
        	TT.save&#40;depth, beta, pline->argmove&#91;0&#93;, Beta, Get_Current_Hash_Key&#40;));
        	return beta;
        &#125;
        if&#40;score > alpha&#41;
        &#123;
        	pline->argmove&#91;0&#93; = move;
            pline->score = score;
            memcpy&#40;pline->argmove + 1, line.argmove, line.cmove * sizeof&#40;Move&#41;);
            pline->cmove = line.cmove + 1;
            alpha = score;
            node = Exact;
        &#125;
    &#125;
I know Stockfish tests if the current node is a PV node and does not reduce in this case. How do I determine if the current node is a PV node?
Also, am I doing anything obviously wrong with LMR here?

Thanks,
David Cimbalista
I do not know which version of AB you are using, but re-search with an open window could be very expensive in a plain vanilla AB. Basically, average depth must be higher when using LMR. If it is not, then you have some bug.
Best Regards,
Karlo Balla Jr.
theturk1234
Posts: 52
Joined: Tue Jul 12, 2016 5:28 am

Re: Disappointing LMR Results

Post by theturk1234 »

Yes, my move ordering is decent at the moment, but it can use some improvement!
I was looking for that glauringchess.com page but it went offline but the link you gave works; thanks Tony!
Well, what should I do if the LMR search returns above alpha? I could try opening the window a little, but risk having to research with a full window if that search is above alpha. I just thought searching immediately with an open window was best.....

Thanks,
David
jdart
Posts: 4361
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Disappointing LMR Results

Post by jdart »

You can try first a zero-width search but with no reduction. Then if that still fails high, you can widen the window (again with no reduction).

LMR is highly dependent on move ordering especially if you increase the reduction with the move index. So if your move ordering is bad expect bad results from LMR.

--Jon