Transposition table mate score problem ?

Discussion of chess software programming and technical issues.

Moderator: Ras

MahmoudUthman
Posts: 237
Joined: Sat Jan 17, 2015 11:54 pm

Transposition table mate score problem ?

Post by MahmoudUthman »

in a winning position the engine played a move(b1b3) that will result in -mate in 1 reporting it as mate in 1 ?
probe,store mate score handling code:

Code: Select all

bool  TTProbe(TTEntry& entry)
{
	entry = TT[Positionkey&IndexMask];
	if (entry.Key == Positionkey)
	{
		if (entry.move.Score >= Value_Mate_In_Max_Ply) entry.move.Score -= ply;
		else if (entry.move.Score <= Value_Mated_In_Max_Ply) entry.move.Score += ply;
		return true;
	}
	return false;
}
void TTStore(Move BestMove, int Depth, BoundType BT, int Score)
{
		if (Score >= Value_Mate_In_Max_Ply) Score += ply;
		else if (Score <= Value_Mated_In_Max_Ply) Score -= ply;
}
In ID after making a root move I call alphabeta with (-Value_Mate,Value_Mate),
Values:

Code: Select all

Value_Mate = SHRT_MAX,
Value_Mate_In_Max_Ply = Value_Mate - MaxPly,
	Value_Mated_In_Max_Ply = -Value_Mate + MaxPly
From the engine output I can see the problem in the last 2 searches , where in the last store the score after modification =mate_value+1 , but I don't understand why this happens ?

Code: Select all

position startpos moves e2e4 e7e5 f1c4 b8c6 g1f3 f8c5 d2d4 e5d4 f3g5 g8h6 g5f7 c5b4 c2c3 h6f7 c4f7 e8f7 c3b4 d8e7 e1g1 e7b4 d1h5 g7g6 h5d5 f7g7 b1a3 h8e8 a3c2 b4b6 d5g5 e8e4 b2b4 c6b4 a1b1 c7c5 a2a3 b4c2 b1b6 a7b6 g5h6 g7g8 h6d2 c2a3 d2a2 c5c4 c1a3 d7d5 a2b2 d4d3 b2b6 c8e6 f2f3 e4e2 a3b2 a8a2 b6d8 g8f7 d8f6 f7e8 b2e5 e6f7 f1b1 f7g8 f6h8 b7b5 h8g8 e8e7
depth 10
info depth 1 seldepth 0 score cp 955 EBF 9.055385 nodes 82 time 1 nps 95000 pv g8d5
info depth 2 seldepth 1 score cp 911 EBF 10.392305 nodes 190 time 3 nps 68333 pv g8d5
info depth 3 seldepth 3 score cp 911 EBF 1.000000 nodes 316 time 6 nps 56833 pv g8d5
info depth 4 seldepth 3 score cp 911 EBF 2.000000 nodes 760 time 10 nps 84900 pv g8d5
info depth 5 seldepth 6 score cp 911 EBF 3.872983 nodes 2657 time 14 nps 237428 pv g8d5
info depth 6 seldepth 6 score cp 911 EBF 1.000000 nodes 3337 time 17 nps 240764 pv g8d5
info depth 7 seldepth 11 score cp 911 EBF 1.414214 nodes 8655 time 23 nps 465913 pv g8d5
info depth 8 seldepth 11 score cp 911 EBF 2.645751 nodes 13704 time 27 nps 619222 pv g8d5
info depth 9 seldepth 15 score cp 911 EBF 6.708204 nodes 257888 time 141 nps 2556801 pv g8d5 e2g2
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Store:
Args: BestMove: c4b3    Depth: 2        Ply: 11 Bound: Lower    Score: -2389    Score(Modified): -2389
   a   b   c   d   e   f   g   h
 _________________________________
8|   |   |   |   |   |   |   |   |8
 _________________________________
7|   |   |   | k |   |   |   |   |7
 _________________________________
6|   |   |   |   |   | Q |   |   |6
 _________________________________
5|   |   |   | p | B |   |   |   |5
 _________________________________
4|   |   | p |   |   |   |   |   |4
 _________________________________
3|   | R |   | p |   | P |   |   |3
 _________________________________
2| r |   |   |   | r |   | P | P |2
 _________________________________
1|   |   |   |   |   |   |   | K |1
 _________________________________
   a   b   c   d   e   f   g   h
SideToMove: Black
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

info depth 10 seldepth 21 score cp 985 EBF 51.400389 nodes 13600789 time 5875 nps 3257897 pv g8g7 e7e8 g1h1 d3d2 g7g8 e8e7 g8h7 e7e6 h7g6 e6e5 g6e8 e5f6 e8e2 c4c3 e2e3
bestmove g8g7
position startpos moves e2e4 e7e5 f1c4 b8c6 g1f3 f8c5 d2d4 e5d4 f3g5 g8h6 g5f7 c5b4 c2c3 h6f7 c4f7 e8f7 c3b4 d8e7 e1g1 e7b4 d1h5 g7g6 h5d5 f7g7 b1a3 h8e8 a3c2 b4b6 d5g5 e8e4 b2b4 c6b4 a1b1 c7c5 a2a3 b4c2 b1b6 a7b6 g5h6 g7g8 h6d2 c2a3 d2a2 c5c4 c1a3 d7d5 a2b2 d4d3 b2b6 c8e6 f2f3 e4e2 a3b2 a8a2 b6d8 g8f7 d8f6 f7e8 b2e5 e6f7 f1b1 f7g8 f6h8 b7b5 h8g8 e8e7 g8g7 e7e8
depth 10
info depth 1 seldepth 0 score cp 939 EBF 8.831761 nodes 78 time 1 nps 87000 pv b1b5
info depth 2 seldepth 2 score cp 985 EBF 14.035669 nodes 275 time 2 nps 166500 pv g1h1
info depth 3 seldepth 2 score cp 985 EBF 1.000000 nodes 421 time 6 nps 84000 pv g1h1
info depth 4 seldepth 4 score cp 985 EBF 1.414214 nodes 876 time 9 nps 124444 pv g1h1
info depth 5 seldepth 4 score cp 985 EBF 0.000000 nodes 977 time 12 nps 102083 pv g1h1
info depth 6 seldepth 4 score cp 985 EBF 0.000000 nodes 1180 time 15 nps 96000 pv g1h1
info depth 7 seldepth 4 score cp 985 EBF 1.000000 nodes 1284 time 18 nps 85777 pv g1h1
info depth 8 seldepth 8 score cp 985 EBF 1.000000 nodes 1605 time 21 nps 92761 pv g1h1
info depth 9 seldepth 8 score cp 985 EBF 1.000000 nodes 1712 time 24 nps 85625 pv g1h1
info depth 10 seldepth 18 score cp 985 EBF 76.347888 nodes 1872964 time 849 nps 3257995 pv g1h1 d3d2 g7g8
bestmove g1h1
position startpos moves e2e4 e7e5 f1c4 b8c6 g1f3 f8c5 d2d4 e5d4 f3g5 g8h6 g5f7 c5b4 c2c3 h6f7 c4f7 e8f7 c3b4 d8e7 e1g1 e7b4 d1h5 g7g6 h5d5 f7g7 b1a3 h8e8 a3c2 b4b6 d5g5 e8e4 b2b4 c6b4 a1b1 c7c5 a2a3 b4c2 b1b6 a7b6 g5h6 g7g8 h6d2 c2a3 d2a2 c5c4 c1a3 d7d5 a2b2 d4d3 b2b6 c8e6 f2f3 e4e2 a3b2 a8a2 b6d8 g8f7 d8f6 f7e8 b2e5 e6f7 f1b1 f7g8 f6h8 b7b5 h8g8 e8e7 g8g7 e7e8 g1h1 b5b4
depth 7
info depth 1 seldepth 0 score cp 927 EBF 8.717798 nodes 76 time 1 nps 90000 pv b1b4
info depth 2 seldepth 2 score cp 927 EBF 21.517435 nodes 539 time 2 nps 398500 pv g7g8 e8e7 g8d5
info depth 3 seldepth 3 score cp 927 EBF 3.872983 nodes 1703 time 4 nps 610000 pv g7g8
info depth 4 seldepth 6 score cp 922 EBF 5.477226 nodes 15670 time 12 nps 1911500 pv g7g8 e8e7 g8h7 e7e6 e5g3 e2g2
info depth 5 seldepth 7 score cp 968 EBF 3.464102 nodes 29928 time 20 nps 2152050 pv g7h7 e2e5 h7h8 e8d7 h8e5 d3d2
info depth 6 seldepth 11 score cp 968 EBF 2.828427 nodes 142630 time 95 nps 2131210 pv g7h7 e2e5 h7h8
info depth 7 seldepth 11 score cp 1035 EBF 3.741657 nodes 354735 time 192 nps 2627734 pv g7h7 a2a6 h7g8 e8e7 g8d5 a6e6 d5b7 e7d8 f3f4
bestmove g7h7
position startpos moves e2e4 e7e5 f1c4 b8c6 g1f3 f8c5 d2d4 e5d4 f3g5 g8h6 g5f7 c5b4 c2c3 h6f7 c4f7 e8f7 c3b4 d8e7 e1g1 e7b4 d1h5 g7g6 h5d5 f7g7 b1a3 h8e8 a3c2 b4b6 d5g5 e8e4 b2b4 c6b4 a1b1 c7c5 a2a3 b4c2 b1b6 a7b6 g5h6 g7g8 h6d2 c2a3 d2a2 c5c4 c1a3 d7d5 a2b2 d4d3 b2b6 c8e6 f2f3 e4e2 a3b2 a8a2 b6d8 g8f7 d8f6 f7e8 b2e5 e6f7 f1b1 f7g8 f6h8 b7b5 h8g8 e8e7 g8g7 e7e8 g1h1 b5b4 g7h7 b4b3
depth 7
info depth 1 seldepth 0 score cp 942 EBF 8.944272 nodes 80 time 1 nps 101000 pv h7g6
info depth 2 seldepth 1 score cp 1047 EBF 11.747340 nodes 218 time 2 nps 149500 pv h7g6
info depth 3 seldepth 3 score cp 1047 EBF 3.464102 nodes 1243 time 6 nps 275500 pv h7g6
info depth 4 seldepth 4 score cp 1047 EBF 5.196152 nodes 5079 time 10 nps 727300 pv h7g6
info depth 5 seldepth 6 score cp 1047 EBF 1.000000 nodes 6617 time 12 nps 775833 pv h7g6
info depth 6 seldepth 6 score cp 1047 EBF 1.000000 nodes 14233 time 16 nps 1194375 pv h7g6

****************************************************************
Probe:
Args: BestMove: c4b3    Depth: 2        Ply: 5  Bound: Lower    Score: -2389    Score(Modified): -2389
   a   b   c   d   e   f   g   h
 _________________________________
8|   |   |   |   |   |   |   |   |8
 _________________________________
7|   |   |   | k |   |   |   |   |7
 _________________________________
6|   |   |   |   |   | Q |   |   |6
 _________________________________
5|   |   |   | p | B |   |   |   |5
 _________________________________
4|   |   | p |   |   |   |   |   |4
 _________________________________
3|   | R |   | p |   | P |   |   |3
 _________________________________
2| r |   |   |   | r |   | P | P |2
 _________________________________
1|   |   |   |   |   |   |   | K |1
 _________________________________
   a   b   c   d   e   f   g   h
SideToMove: Black
****************************************************************


****************************************************************
Probe:
Args: BestMove: c4b3    Depth: 2        Ply: 5  Bound: Lower    Score: -2389    Score(Modified): -2389
   a   b   c   d   e   f   g   h
 _________________________________
8|   |   |   |   |   |   |   |   |8
 _________________________________
7|   |   |   | k |   |   |   |   |7
 _________________________________
6|   |   |   |   |   | Q |   |   |6
 _________________________________
5|   |   |   | p | B |   |   |   |5
 _________________________________
4|   |   | p |   |   |   |   |   |4
 _________________________________
3|   | R |   | p |   | P |   |   |3
 _________________________________
2| r |   |   |   | r |   | P | P |2
 _________________________________
1|   |   |   |   |   |   |   | K |1
 _________________________________
   a   b   c   d   e   f   g   h
SideToMove: Black
****************************************************************


@SearchEnd
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Store:
Args: BestMove: e2e1    Depth: 4        Ply: 5  Bound: Exact    Score: 32761    Score(Modified): 32766
   a   b   c   d   e   f   g   h
 _________________________________
8|   |   |   |   |   |   |   |   |8
 _________________________________
7|   |   |   | k |   |   |   |   |7
 _________________________________
6|   |   |   |   |   | Q |   |   |6
 _________________________________
5|   |   |   | p | B |   |   |   |5
 _________________________________
4|   |   | p |   |   |   |   |   |4
 _________________________________
3|   | R |   | p |   | P |   |   |3
 _________________________________
2| r |   |   |   | r |   | P | P |2
 _________________________________
1|   |   |   |   |   |   |   | K |1
 _________________________________
   a   b   c   d   e   f   g   h
SideToMove: Black
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

info depth 7 seldepth 13 score cp 1086 EBF 21.142375 nodes 702232 time 427 nps 2227103 pv h7g6 e8d7 g6d6 d7e8 d6d5 e2c2 d5e6 e8f8 e6f6 f8e8 h1g1
bestmove h7g6
position startpos moves e2e4 e7e5 f1c4 b8c6 g1f3 f8c5 d2d4 e5d4 f3g5 g8h6 g5f7 c5b4 c2c3 h6f7 c4f7 e8f7 c3b4 d8e7 e1g1 e7b4 d1h5 g7g6 h5d5 f7g7 b1a3 h8e8 a3c2 b4b6 d5g5 e8e4 b2b4 c6b4 a1b1 c7c5 a2a3 b4c2 b1b6 a7b6 g5h6 g7g8 h6d2 c2a3 d2a2 c5c4 c1a3 d7d5 a2b2 d4d3 b2b6 c8e6 f2f3 e4e2 a3b2 a8a2 b6d8 g8f7 d8f6 f7e8 b2e5 e6f7 f1b1 f7g8 f6h8 b7b5 h8g8 e8e7 g8g7 e7e8 g1h1 b5b4 g7h7 b4b3 h7g6 e8e7
depth 8
info depth 1 seldepth 0 score cp 945 EBF 9.486833 nodes 90 time 1 nps 115000 pv g6f6
info depth 2 seldepth 2 score cp 959 EBF 22.360680 nodes 590 time 2 nps 363500 pv g6f6 e7d7 h1g1
info depth 3 seldepth 3 score cp 959 EBF 3.464102 nodes 1750 time 6 nps 380166 pv g6f6

****************************************************************
Probe:
Args: BestMove: e2e1    Depth: 4        Ply: 3  Bound: Exact    Score: 32766    Score(Modified): 32763
   a   b   c   d   e   f   g   h
 _________________________________
8|   |   |   |   |   |   |   |   |8
 _________________________________
7|   |   |   | k |   |   |   |   |7
 _________________________________
6|   |   |   |   |   | Q |   |   |6
 _________________________________
5|   |   |   | p | B |   |   |   |5
 _________________________________
4|   |   | p |   |   |   |   |   |4
 _________________________________
3|   | R |   | p |   | P |   |   |3
 _________________________________
2| r |   |   |   | r |   | P | P |2
 _________________________________
1|   |   |   |   |   |   |   | K |1
 _________________________________
   a   b   c   d   e   f   g   h
SideToMove: Black
****************************************************************

info depth 4 seldepth 6 score cp 1086 EBF 4.123106 nodes 10705 time 48 nps 286645 pv g6f6 e7d7 f6d6
info depth 5 seldepth 6 score cp 1086 EBF 1.414214 nodes 13195 time 51 nps 333980 pv g6f6

****************************************************************
Probe:
Args: BestMove: e2e1    Depth: 4        Ply: 3  Bound: Exact    Score: 32766    Score(Modified): 32763
   a   b   c   d   e   f   g   h
 _________________________________
8|   |   |   |   |   |   |   |   |8
 _________________________________
7|   |   |   | k |   |   |   |   |7
 _________________________________
6|   |   |   |   |   | Q |   |   |6
 _________________________________
5|   |   |   | p | B |   |   |   |5
 _________________________________
4|   |   | p |   |   |   |   |   |4
 _________________________________
3|   | R |   | p |   | P |   |   |3
 _________________________________
2| r |   |   |   | r |   | P | P |2
 _________________________________
1|   |   |   |   |   |   |   | K |1
 _________________________________
   a   b   c   d   e   f   g   h
SideToMove: Black
****************************************************************

info depth 6 seldepth 11 score cp 1086 EBF 2.645751 nodes 77879 time 109 nps 909449 pv g6f6 e7d7 f6d6
info depth 7 seldepth 11 score cp 1086 EBF 2.236068 nodes 91924 time 116 nps 1014715 pv g6f6

****************************************************************
Probe:
Args: BestMove: e2e1    Depth: 4        Ply: 3  Bound: Exact    Score: 32766    Score(Modified): 32763
   a   b   c   d   e   f   g   h
 _________________________________
8|   |   |   |   |   |   |   |   |8
 _________________________________
7|   |   |   | k |   |   |   |   |7
 _________________________________
6|   |   |   |   |   | Q |   |   |6
 _________________________________
5|   |   |   | p | B |   |   |   |5
 _________________________________
4|   |   | p |   |   |   |   |   |4
 _________________________________
3|   | R |   | p |   | P |   |   |3
 _________________________________
2| r |   |   |   | r |   | P | P |2
 _________________________________
1|   |   |   |   |   |   |   | K |1
 _________________________________
   a   b   c   d   e   f   g   h
SideToMove: Black
****************************************************************

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Store:
Args: BestMove: e2e1    Depth: 6        Ply: 3  Bound: Lower    Score: 32763    Score(Modified): 32766
   a   b   c   d   e   f   g   h
 _________________________________
8|   |   |   |   |   |   |   |   |8
 _________________________________
7|   |   |   | k |   |   |   |   |7
 _________________________________
6|   |   |   |   |   | Q |   |   |6
 _________________________________
5|   |   |   | p | B |   |   |   |5
 _________________________________
4|   |   | p |   |   |   |   |   |4
 _________________________________
3|   | R |   | p |   | P |   |   |3
 _________________________________
2| r |   |   |   | r |   | P | P |2
 _________________________________
1|   |   |   |   |   |   |   | K |1
 _________________________________
   a   b   c   d   e   f   g   h
SideToMove: Black
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


****************************************************************
Probe:
Args: BestMove: e2e1    Depth: 6        Ply: 5  Bound: Lower    Score: 32766    Score(Modified): 32761
   a   b   c   d   e   f   g   h
 _________________________________
8|   |   |   |   |   |   |   |   |8
 _________________________________
7|   |   |   | k |   |   |   |   |7
 _________________________________
6|   |   |   |   |   | Q |   |   |6
 _________________________________
5|   |   |   | p | B |   |   |   |5
 _________________________________
4|   |   | p |   |   |   |   |   |4
 _________________________________
3|   | R |   | p |   | P |   |   |3
 _________________________________
2| r |   |   |   | r |   | P | P |2
 _________________________________
1|   |   |   |   |   |   |   | K |1
 _________________________________
   a   b   c   d   e   f   g   h
SideToMove: Black
****************************************************************


****************************************************************
Probe:
Args: BestMove: e2e1    Depth: 6        Ply: 5  Bound: Lower    Score: 32766    Score(Modified): 32761
   a   b   c   d   e   f   g   h
 _________________________________
8|   |   |   |   |   |   |   |   |8
 _________________________________
7|   |   |   | k |   |   |   |   |7
 _________________________________
6|   |   |   |   |   | Q |   |   |6
 _________________________________
5|   |   |   | p | B |   |   |   |5
 _________________________________
4|   |   | p |   |   |   |   |   |4
 _________________________________
3|   | R |   | p |   | P |   |   |3
 _________________________________
2| r |   |   |   | r |   | P | P |2
 _________________________________
1|   |   |   |   |   |   |   | K |1
 _________________________________
   a   b   c   d   e   f   g   h
SideToMove: Black
****************************************************************


@SearchEnd
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Store:
Args: BestMove: a1a1    Depth: 2        Ply: 5  Bound: Upper    Score: 32763    Score(Modified): 32768
   a   b   c   d   e   f   g   h
 _________________________________
8|   |   |   |   |   |   |   |   |8
 _________________________________
7|   |   |   | k |   |   |   |   |7
 _________________________________
6|   |   |   |   |   | Q |   |   |6
 _________________________________
5|   |   |   | p | B |   |   |   |5
 _________________________________
4|   |   | p |   |   |   |   |   |4
 _________________________________
3|   | R |   | p |   | P |   |   |3
 _________________________________
2| r |   |   |   | r |   | P | P |2
 _________________________________
1|   |   |   |   |   |   |   | K |1
 _________________________________
   a   b   c   d   e   f   g   h
SideToMove: Black
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

info depth 8 seldepth 15 score cp 1086 EBF 4.898979 nodes 1645747 time 931 nps 2448789 pv g6f6 e7d7 f6d6
bestmove g6f6
position startpos moves e2e4 e7e5 f1c4 b8c6 g1f3 f8c5 d2d4 e5d4 f3g5 g8h6 g5f7 c5b4 c2c3 h6f7 c4f7 e8f7 c3b4 d8e7 e1g1 e7b4 d1h5 g7g6 h5d5 f7g7 b1a3 h8e8 a3c2 b4b6 d5g5 e8e4 b2b4 c6b4 a1b1 c7c5 a2a3 b4c2 b1b6 a7b6 g5h6 g7g8 h6d2 c2a3 d2a2 c5c4 c1a3 d7d5 a2b2 d4d3 b2b6 c8e6 f2f3 e4e2 a3b2 a8a2 b6d8 g8f7 d8f6 f7e8 b2e5 e6f7 f1b1 f7g8 f6h8 b7b5 h8g8 e8e7 g8g7 e7e8 g1h1 b5b4 g7h7 b4b3 h7g6 e8e7 g6f6 e7d7
depth 2
info depth 1 seldepth 0 score cp 959 EBF 8.944272 nodes 80 time 1 nps 89000 pv h1g1

****************************************************************
Probe:
Args: BestMove: a1a1    Depth: 2        Ply: 1  Bound: Upper    Score: -32768   Score(Modified): -32767
   a   b   c   d   e   f   g   h
 _________________________________
8|   |   |   |   |   |   |   |   |8
 _________________________________
7|   |   |   | k |   |   |   |   |7
 _________________________________
6|   |   |   |   |   | Q |   |   |6
 _________________________________
5|   |   |   | p | B |   |   |   |5
 _________________________________
4|   |   | p |   |   |   |   |   |4
 _________________________________
3|   | R |   | p |   | P |   |   |3
 _________________________________
2| r |   |   |   | r |   | P | P |2
 _________________________________
1|   |   |   |   |   |   |   | K |1
 _________________________________
   a   b   c   d   e   f   g   h
SideToMove: Black
****************************************************************

info depth 2 seldepth 1 score mate 1 EBF 10.295630 nodes 186 time 45 nps 4488 pv b1b3
bestmove b1b3
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Transposition table mate score problem ?

Post by Sven »

MahmoudUthman wrote:in a winning position the engine played a move(b1b3) that will result in -mate in 1 reporting it as mate in 1 ?
probe,store mate score handling code:

Code: Select all

bool  TTProbe(TTEntry& entry)
{
	entry = TT[Positionkey&IndexMask];
	if (entry.Key == Positionkey)
	{
		if (entry.move.Score >= Value_Mate_In_Max_Ply) entry.move.Score -= ply;
		else if (entry.move.Score <= Value_Mated_In_Max_Ply) entry.move.Score += ply;
		return true;
	}
	return false;
}
void TTStore(Move BestMove, int Depth, BoundType BT, int Score)
{
		if (Score >= Value_Mate_In_Max_Ply) Score += ply;
		else if (Score <= Value_Mated_In_Max_Ply) Score -= ply;
}
TTProbe() and TTStore() look ok (although I guess your real TTStore() does a bit more, e.g. store something ...). I would watch out for some sign-flipping error. Can you perfectly reproduce the problem? And if so, can you also reproduce it after switching off TT?
MahmoudUthman
Posts: 237
Joined: Sat Jan 17, 2015 11:54 pm

Re: Transposition table mate score problem ?

Post by MahmoudUthman »

Sven Schüle wrote:
MahmoudUthman wrote:in a winning position the engine played a move(b1b3) that will result in -mate in 1 reporting it as mate in 1 ?
probe,store mate score handling code:

Code: Select all

bool  TTProbe(TTEntry& entry)
{
	entry = TT[Positionkey&IndexMask];
	if (entry.Key == Positionkey)
	{
		if (entry.move.Score >= Value_Mate_In_Max_Ply) entry.move.Score -= ply;
		else if (entry.move.Score <= Value_Mated_In_Max_Ply) entry.move.Score += ply;
		return true;
	}
	return false;
}
void TTStore(Move BestMove, int Depth, BoundType BT, int Score)
{
		if (Score >= Value_Mate_In_Max_Ply) Score += ply;
		else if (Score <= Value_Mated_In_Max_Ply) Score -= ply;
}
TTProbe() and TTStore() look ok (although I guess your real TTStore() does a bit more, e.g. store something ...). I would watch out for some sign-flipping error. Can you perfectly reproduce the problem? And if so, can you also reproduce it after switching off TT?
Yes I only added the code that modifies the score.
Yes , actually the output that I provided is a reproduction (the game was one in which I disable time control inside alphabeta , so the engine always finished ID iteration) , I reproduce the exact problem by feeding the engine the same input it received during the game with the depth it reached.
No, Only when the TT is on.
I just added this line

Code: Select all

if (abs(Score) >= SHRT_MAX) std::cout << Score<<"\t TT >=SHRT_MAX " << std::endl;
and it turns out a lot of scores exceed shrtmax after adjustment but I don't know why ?
In the alphabeta & Qsearch when I encounter a mate I return -Value_Mate+Ply , any idea what I'm doing wrong ?
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Transposition table mate score problem ?

Post by Sven »

Is "ply" the current distance to the root node or the number of plies made from the beginning of the game? In the latter case you might be off a bit ...
MahmoudUthman
Posts: 237
Joined: Sat Jan 17, 2015 11:54 pm

Re: Transposition table mate score problem ?

Post by MahmoudUthman »

Sven Schüle wrote:Is "ply" the current distance to the root node or the number of plies made from the beginning of the game? In the latter case you might be off a bit ...
Distance from the root .
The ply is incremented/decremented in normal make/unmake and when doing a null move could this be the problem "I don't allow consecutive null search"?
also after receiving a "go" command I call the root search that contains the ID loop in which I Make a root move then call AlphaBeta routine , which means the first call to alphaBeta "but after making a Root move" happens with ply==1 , so distance from root, right ?

could it have something to do with this ?
& this "2*MaxPLY" In SF ?

Code: Select all

VALUE_MATE_IN_MAX_PLY  =  VALUE_MATE - 2 * MAX_PLY,
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY,
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Transposition table mate score problem ?

Post by Sven »

MahmoudUthman wrote:The ply is incremented/decremented in normal make/unmake and when doing a null move could this be the problem "I don't allow consecutive null search"?
Why should that cause a wrong mate score?
MahmoudUthman wrote:also after receiving a "go" command I call the root search that contains the ID loop in which I Make a root move then call AlphaBeta routine , which means the first call to alphaBeta "but after making a Root move" happens with ply==1 , so distance from root, right ?
Yes, sounds right.
MahmoudUthman wrote:could it have something to do with this ?
No, I think you are using the "classical" mate scoring approach (checkmated = -(infinite - distance_to_root)) so that thread is not directly related. (As an aside, I saw only now that I did not continue the discussion in that thread back then - 5 years ago -, even though I did - and do - not agree with some of its contents.)
MahmoudUthman wrote:& this "2*MaxPLY" In SF ?

Code: Select all

VALUE_MATE_IN_MAX_PLY  =  VALUE_MATE - 2 * MAX_PLY,
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY,
There will be some reason why these constants are defined like this in SF. But I don't think that would be important for your engine.

How do you decide whether you display a positive or a negative number when reporting a mate score via UCI? Maybe you only have a display problem?
MahmoudUthman
Posts: 237
Joined: Sat Jan 17, 2015 11:54 pm

Re: Transposition table mate score problem ?

Post by MahmoudUthman »

Sven Schüle wrote:
MahmoudUthman wrote:The ply is incremented/decremented in normal make/unmake and when doing a null move could this be the problem "I don't allow consecutive null search"?
Why should that cause a wrong mate score?
MahmoudUthman wrote:also after receiving a "go" command I call the root search that contains the ID loop in which I Make a root move then call AlphaBeta routine , which means the first call to alphaBeta "but after making a Root move" happens with ply==1 , so distance from root, right ?
Yes, sounds right.
MahmoudUthman wrote:could it have something to do with this ?
No, I think you are using the "classical" mate scoring approach (checkmated = -(infinite - distance_to_root)) so that thread is not directly related. (As an aside, I saw only now that I did not continue the discussion in that thread back then - 5 years ago -, even though I did - and do - not agree with some of its contents.)
MahmoudUthman wrote:& this "2*MaxPLY" In SF ?

Code: Select all

VALUE_MATE_IN_MAX_PLY  =  VALUE_MATE - 2 * MAX_PLY,
VALUE_MATED_IN_MAX_PLY = -VALUE_MATE + 2 * MAX_PLY,
There will be some reason why these constants are defined like this in SF. But I don't think that would be important for your engine.

How do you decide whether you display a positive or a negative number when reporting a mate score via UCI? Maybe you only have a display problem?
-It shouldn't as far as I understand , I was jus making sure.
-Actually I don't have "Infinity" defined , and the thread I mentioned "although I don't understand why !" and SF values made me think this was the problem , specifically this sentence
so there has to be a safety range between mate in one and +infinity and also between checkmated and -infinity. This safety margin length has to be at least as long as the greatest possible search ply.
-

Code: Select all

		if (abs(alpha)>=Value_Mate_In_Max_Ply)
		{
			auto MateIn = (Value_Mate - abs(alpha))/2;
			MateIn = alpha > 0 ? MateIn+1 : -MateIn;
		}
but it isn't just a display problem since the engine blunders into Check

Code: Select all

position startpos moves e2e4 e7e5 f1c4 b8c6 g1f3 f8c5 d2d4 e5d4 f3g5 g8h6 g5f7 c5b4 c2c3 h6f7 c4f7 e8f7 c3b4 d8e7 e1g1 e7b4 d1h5 g7g6 h5d5 f7g7 b1a3 h8e8 a3c2 b4b6 d5g5 e8e4 b2b4 c6b4 a1b1 c7c5 a2a3 b4c2 b1b6 a7b6 g5h6 g7g8 h6d2 c2a3 d2a2 c5c4 c1a3 d7d5 a2b2 d4d3 b2b6 c8e6 f2f3 e4e2 a3b2 a8a2 b6d8 g8f7 d8f6 f7e8 b2e5 e6f7 f1b1 f7g8 f6h8 b7b5 h8g8 e8e7 g8g7 e7e8 g1h1 b5b4 g7h7 b4b3 h7g6 e8e7 g6f6 e7d7 
 depth 2 
 info depth 1 seldepth 0 score cp 959 EBF 8.944272 nodes 80 time 1 nps 89000 pv h1g1 
 info depth 2 seldepth 1 score mate 1 EBF 10.295630 nodes 186 time 45 nps 4488 pv b1b3 
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Transposition table mate score problem ?

Post by Sven »

Ok. So there is some bug that turns a "mated in 1" into a "mate in 1", and it only happens with TT switched on. You can reproduce it with a 2-ply search.

Print the tree with all relevant information! It is only ~200 nodes, so you should be able to figure out the problem immediately.
MahmoudUthman
Posts: 237
Joined: Sat Jan 17, 2015 11:54 pm

Re: Transposition table mate score problem ?

Post by MahmoudUthman »

Sven Schüle wrote:Ok. So there is some bug that turns a "mated in 1" into a "mate in 1", and it only happens with TT switched on. You can reproduce it with a 2-ply search.

Print the tree with all relevant information! It is only ~200 nodes, so you should be able to figure out the problem immediately.
I can't reproduce it with a 2 ply search without replaying the entire game to fill the TT first .