Test this in your engine and post your results

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

tttony
Posts: 268
Joined: Sun Apr 24, 2011 12:33 am

Test this in your engine and post your results

Post by tttony »

Well, I recently discovered something weird that by now it's working

My engine it's based on Vice: https://chessprogramming.wikispaces.com/Vice

I learned many things watching the videos and coding

But trying to get better results I modified a part that was wrong(?) in the code, take a look this part in the file search.c in the AlphaBeta function:

Code: Select all

if(Score > BestScore) {
			BestScore = Score;
			BestMove = list->moves[MoveNum].move;
			if(Score > alpha) {
				if(Score >= beta) {
					if(Legal==1) {
						info->fhf++;
					}
					info->fh++;

					if(!(list->moves[MoveNum].move & MFLAGCAP)) {
						pos->searchKillers[1][pos->ply] = pos->searchKillers[0][pos->ply];
						pos->searchKillers[0][pos->ply] = list->moves[MoveNum].move;
					}

					StoreHashEntry(pos, list->moves[MoveNum].move, beta, HFBETA, depth);

					return beta;
				}
				alpha = Score;

				if(!(list->moves[MoveNum].move & MFLAGCAP)) {
					pos->searchHistory[pos->pieces[FROMSQ(list->moves[MoveNum].move)]][TOSQ(list->moves[MoveNum].move)] += depth;
				}
			}
		}

// ....................


   if(alpha != OldAlpha) {
		StoreHashEntry(pos, BestMove, BestScore, HFEXACT, depth);
	} else {
		StoreHashEntry(pos, BestMove, alpha, HFALPHA, depth);
	}
Take a look the line: BestMove = list->moves[MoveNum].move;, the variable: BestMove is setted after if (Score > BestScore) and should be setted inside if(Score > alpha)

And in the end of the AlphaBeta function you can see when alpha is not improved, it saves the BestMove in the TT:

Code: Select all

if(alpha != OldAlpha) {
		StoreHashEntry(pos, BestMove, BestScore, HFEXACT, depth);
	} else {
		StoreHashEntry&#40;pos, BestMove, alpha, HFALPHA, depth&#41;; // <-- Here!
	&#125;
I've tested and here are some results:

5s + 100ms 5000 games

Code: Select all

    Program                          Elo    +   -   Games   Score   Av.Op.  Draws

  1 Vice10 x64                     &#58; 1404    8   8  5000    51.3 %   1396   27.7 %
  2 Vice10 x64 BM                  &#58; 1396    8   8  5000    48.7 %   1404   27.7 %

Individual statistics&#58;

1 Vice10 x64                &#58; 1409  1297 (+449,=464,-384&#41;, 52.5 %

Vice10 x64 BM                 &#58; 1297 (+449,=464,-384&#41;, 52.5 %

2 Vice10 x64 BM             &#58; 1391  1297 (+384,=464,-449&#41;, 47.5 %

Vice10 x64                    &#58; 1297 (+384,=464,-449&#41;, 47.5 %

Right now I'm running 5000 games 2m + 2s and the results for now are:

Code: Select all

    Program                          Elo    +   -   Games   Score   Av.Op.  Draws

  1 Vice10 x64                     &#58; 1409   15  15  1297    52.5 %   1391   35.8 %
  2 Vice10 x64 BM                  &#58; 1391   15  15  1297    47.5 %   1409   35.8 %

Individual statistics&#58;

1 Vice10 x64                &#58; 1409  1297 (+449,=464,-384&#41;, 52.5 %

Vice10 x64 BM                 &#58; 1297 (+449,=464,-384&#41;, 52.5 %

2 Vice10 x64 BM             &#58; 1391  1297 (+384,=464,-449&#41;, 47.5 %

Vice10 x64                    &#58; 1297 (+384,=464,-449&#41;, 47.5 %
Vice10 x64 it's untouched and Vice10 x64 BM, BestMove variable it's setted inside if (Score > alpha)

I tested using cutechess and for the opening 10-PGN-Books\2moves_v1.pgn

I've looked some engines sources and all set the bestmove var inside score > alpha

What is wrong?
jdart
Posts: 4366
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Test this in your engine and post your results

Post by jdart »

With PVS, if all moves fail to improve alpha, all you know about the position is that the score is <= alpha. You don't know anything about the relative scores of the moves. So generally there is no sense saving a 'best" move. I do however in these cases save in the hashtable any move that was returned from an IID search. So the next time the node is visited, it will skip the IID search and use the stored move.

--Jon
Last edited by jdart on Sat Nov 07, 2015 4:23 am, edited 1 time in total.
jeffreyan11
Posts: 46
Joined: Sat Sep 12, 2015 5:23 am
Location: United States

Re: Test this in your engine and post your results

Post by jeffreyan11 »

Do you do IID when no hash move is available?

My guess is that when these ALL nodes become PV or CUT nodes later, the "best" move you stored from fail soft, while not necessarily good, is still better than storing no move at all and having no best move to work with (which is what happens if you set best move if score > alpha). So while storing a best move at ALL nodes is technically incorrect, it could be an elo gain...
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Test this in your engine and post your results

Post by bob »

jdart wrote:With PVS, if all moves fail to improve alpha, all you know about the position is that the score is <= alpha. You don't know anything about the relative scores of the moves. So generally there is no sense saving a 'best" move. I do however in these cases save in the hashtable any move that was returned from an IID search. So the next time the node is visited, it will skip the IID search and use the stored move.

--Jon
There are a couple of reasons for storing a "best move" at ALL nodes.

The easiest to understand is the hash move. If the hash move fails low, it is still a good move since it was stored as best somewhere. Nothing wrong with saving it and storing it in the hash table.

Even better, just remember the FIRST move you search, then store that when you save the hash entry after everything fails low. If you have a hash move on entry, then that will be the first move. Otherwise, you can store whatever you searched first. As if you reach this position again, with no hash move at all, THIS is the move you will search first then as well, assuming it is the hash move, or a good capture, or a killer/etc...

It does two things. (1) preserves a hash move through a fail-low node, which is better than nothing; (2) will cause you to search the same first move next time you reach this position as you searched here, which might produce a cutoff the next time around, bypassing a move generation.
tttony
Posts: 268
Joined: Sun Apr 24, 2011 12:33 am

Re: Test this in your engine and post your results

Post by tttony »

Vice it's a simple engine, it does not have IID, only null move pruning and a very basic eval

Oops the 5s + 100s stats it's wrong, here the correct results:

Code: Select all

Individual statistics&#58;

1 Vice10 x64                &#58; 1404  5000 (+1873,=1383,-1744&#41;, 51.3 %

Vice10 x64 BM                 &#58; 5000 (+1873,=1383,-1744&#41;, 51.3 %

2 Vice10 x64 BM             &#58; 1396  5000 (+1744,=1383,-1873&#41;, 48.7 %

Vice10 x64                    &#58; 5000 (+1744,=1383,-1873&#41;, 48.7 %
Karlo Bala
Posts: 373
Joined: Wed Mar 22, 2006 10:17 am
Location: Novi Sad, Serbia
Full name: Karlo Balla

Re: Test this in your engine and post your results

Post by Karlo Bala »

tttony wrote:Well, I recently discovered something weird that by now it's working

My engine it's based on Vice: https://chessprogramming.wikispaces.com/Vice

I learned many things watching the videos and coding

But trying to get better results I modified a part that was wrong(?) in the code, take a look this part in the file search.c in the AlphaBeta function:

Code: Select all

if&#40;Score > BestScore&#41; &#123;
			BestScore = Score;
			BestMove = list->moves&#91;MoveNum&#93;.move;
			if&#40;Score > alpha&#41; &#123;
				if&#40;Score >= beta&#41; &#123;
					if&#40;Legal==1&#41; &#123;
						info->fhf++;
					&#125;
					info->fh++;

					if&#40;!&#40;list->moves&#91;MoveNum&#93;.move & MFLAGCAP&#41;) &#123;
						pos->searchKillers&#91;1&#93;&#91;pos->ply&#93; = pos->searchKillers&#91;0&#93;&#91;pos->ply&#93;;
						pos->searchKillers&#91;0&#93;&#91;pos->ply&#93; = list->moves&#91;MoveNum&#93;.move;
					&#125;

					StoreHashEntry&#40;pos, list->moves&#91;MoveNum&#93;.move, beta, HFBETA, depth&#41;;

					return beta;
				&#125;
				alpha = Score;

				if&#40;!&#40;list->moves&#91;MoveNum&#93;.move & MFLAGCAP&#41;) &#123;
					pos->searchHistory&#91;pos->pieces&#91;FROMSQ&#40;list->moves&#91;MoveNum&#93;.move&#41;&#93;&#93;&#91;TOSQ&#40;list->moves&#91;MoveNum&#93;.move&#41;&#93; += depth;
				&#125;
			&#125;
		&#125;

// ....................


   if&#40;alpha != OldAlpha&#41; &#123;
		StoreHashEntry&#40;pos, BestMove, BestScore, HFEXACT, depth&#41;;
	&#125; else &#123;
		StoreHashEntry&#40;pos, BestMove, alpha, HFALPHA, depth&#41;;
	&#125;
Take a look the line: BestMove = list->moves[MoveNum].move;, the variable: BestMove is setted after if (Score > BestScore) and should be setted inside if(Score > alpha)

And in the end of the AlphaBeta function you can see when alpha is not improved, it saves the BestMove in the TT:

Code: Select all

if&#40;alpha != OldAlpha&#41; &#123;
		StoreHashEntry&#40;pos, BestMove, BestScore, HFEXACT, depth&#41;;
	&#125; else &#123;
		StoreHashEntry&#40;pos, BestMove, alpha, HFALPHA, depth&#41;; // <-- Here!
	&#125;

What is wrong?
Make a small test. At CUT and ALL nodes (beta - alpha ==1):

Code: Select all

if&#40;Score > alpha&#41; 
   BestMove = list->moves&#91;MoveNum&#93;.move;
At PV nodes (beta - alpha > 1):

Code: Select all

if&#40;Score > BestScore&#41; 
   BestMove = list->moves&#91;MoveNum&#93;.move;
I'd like to see results.
Best Regards,
Karlo Balla Jr.
tttony
Posts: 268
Joined: Sun Apr 24, 2011 12:33 am

Re: Test this in your engine and post your results

Post by tttony »

As I said, Vice is very simple engine, it does not have PVS or LMR, just

Code: Select all

if (!MakeMove&#40;pos,list->moves&#91;MoveNum&#93;.move&#41;)  &#123;
            continue;
        &#125;

		Legal++;
		Score = -AlphaBeta&#40; -beta, -alpha, depth-1, pos, info, TRUE&#41;;
		TakeMove&#40;pos&#41;;

		if&#40;info->stopped == TRUE&#41; &#123;
			return 0;
		&#125;
Anyway, I will test it
tttony
Posts: 268
Joined: Sun Apr 24, 2011 12:33 am

Re: Test this in your engine and post your results

Post by tttony »

I've tested the Karlo Bala method and here the results:

5s+100ms

Code: Select all

    Program                          Elo    +   -   Games   Score   Av.Op.  Draws

  1 Vice10 x64                     &#58; 1402    8   8  5000    50.6 %   1398   27.9 %
  2 Vice10 x64 BM_CUT_ALL          &#58; 1398    8   8  5000    49.4 %   1402   27.9 %

Individual statistics&#58;

1 Vice10 x64                &#58; 1402  5000 (+1832,=1395,-1773&#41;, 50.6 %

Vice10 x64 BM_CUT_ALL         &#58; 5000 (+1832,=1395,-1773&#41;, 50.6 %

2 Vice10 x64 BM_CUT_ALL     &#58; 1398  5000 (+1773,=1395,-1832&#41;, 49.4 %

Vice10 x64                    &#58; 5000 (+1773,=1395,-1832&#41;, 49.4 %

The 2m+2s was aborted, there was a blackout in my city so I will not run it again, here the results:

Code: Select all

    Program                          Elo    +   -   Games   Score   Av.Op.  Draws

  1 Vice10 x64                     &#58; 1407   15  15  1365    52.1 %   1393   35.2 %
  2 Vice10 x64 BM                  &#58; 1393   15  15  1365    47.9 %   1407   35.2 %

Individual statistics&#58;

1 Vice10 x64                &#58; 1407  1365 (+471,=480,-414&#41;, 52.1 %

Vice10 x64 BM                 &#58; 1365 (+471,=480,-414&#41;, 52.1 %

2 Vice10 x64 BM             &#58; 1393  1365 (+414,=480,-471&#41;, 47.9 %

Vice10 x64                    &#58; 1365 (+414,=480,-471&#41;, 47.9 %

So by now I will let the Bestmove as it was before in the original Vice, anyway I'm still waiting for someone to test in their engine
AlvaroBegue
Posts: 931
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: Test this in your engine and post your results

Post by AlvaroBegue »

[...]anyway I'm still waiting for someone to test in their engine
This is such a minute detail that I doubt your change even makes sense in other engines. My engine RuyDos doesn't even have a notion of `BestScore' different from `alpha'.
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Test this in your engine and post your results

Post by cdani »

AlvaroBegue wrote:
[...]anyway I'm still waiting for someone to test in their engine
This is such a minute detail that I doubt your change even makes sense in other engines. My engine RuyDos doesn't even have a notion of `BestScore' different from `alpha'.
Andscacs also does not have a different BestScore. Anyway I tested and was not good, but probably it requires some other adjustments...