Rev 33 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 33 | Rev 108 | ||
|---|---|---|---|
| Line 22... | Line 22... | ||
| 22 | ******************************************************************************* |
22 | ******************************************************************************* |
| 23 | */ |
23 | */ |
| 24 | void ValidatePosition(TREE * RESTRICT tree, int ply, int move, char *caller) { |
24 | void ValidatePosition(TREE * RESTRICT tree, int ply, int move, char *caller) { |
| 25 | uint64_t temp, temp1, temp_occ; |
25 | uint64_t temp, temp1, temp_occ; |
| 26 | uint64_t temp_occx; |
26 | uint64_t temp_occx; |
| 27 | int i, square, error; |
27 | int i, square, error = 0; |
| 28 | int side, piece, temp_score; |
28 | int side, piece, temp_score; |
| 29 | 29 | ||
| 30 | /* |
30 | /* |
| 31 | ************************************************************ |
31 | ************************************************************ |
| 32 | * * |
32 | * * |
| 33 | * First, test occupied[side] which should match the OR * |
33 | * First, test occupied[side] which should match the OR * |
| 34 | * result of all pieces[side]. * |
34 | * result of all pieces[side]. * |
| 35 | * * |
35 | * * |
| 36 | ************************************************************ |
36 | ************************************************************ |
| 37 | */ |
37 | */ |
| 38 | error = 0; |
- | |
| 39 | for (side = black; side <= white; side++) { |
38 | for (side = black; side <= white; side++) { |
| 40 | temp_occ = |
39 | temp_occ = |
| 41 | Pawns(side) | Knights(side) | Bishops(side) | Rooks(side) | |
40 | Pawns(side) | Knights(side) | Bishops(side) | Rooks(side) | |
| 42 | Queens(side) |
41 | Queens(side) |
| 43 | | Kings(side); |
42 | | Kings(side); |
| 44 | if (Occupied(side) ^ temp_occ) { |
43 | if (Occupied(side) ^ temp_occ) { |
| - | 44 | if (!error) |
|
| - | 45 | Print(2048, "\n"); |
|
| 45 | Print( |
46 | Print(2048, "ERROR %s occupied squares is bad!\n", |
| 46 | (side) ? "white" : "black"); |
47 | (side) ? "white" : "black"); |
| 47 | Display2BitBoards(temp_occ, Occupied(white)); |
48 | Display2BitBoards(temp_occ, Occupied(white)); |
| 48 | error = 1; |
49 | error = 1; |
| 49 | } |
50 | } |
| 50 | } |
51 | } |
| Line 65... | Line 66... | ||
| 65 | temp_occx = |
66 | temp_occx = |
| 66 | Pawns(white) | Knights(white) | Bishops(white) | Rooks(white) | |
67 | Pawns(white) | Knights(white) | Bishops(white) | Rooks(white) | |
| 67 | Queens(white) | Pawns(black) | Knights(black) | Bishops(black) | |
68 | Queens(white) | Pawns(black) | Knights(black) | Bishops(black) | |
| 68 | Rooks(black) | Queens(black) | Kings(white) | Kings(black); |
69 | Rooks(black) | Queens(black) | Kings(white) | Kings(black); |
| 69 | if (temp_occ ^ temp_occx) { |
70 | if (temp_occ ^ temp_occx) { |
| - | 71 | if (!error) |
|
| - | 72 | Print(2048, "\n"); |
|
| 70 | Print( |
73 | Print(2048, "ERROR two pieces on same square\n"); |
| 71 | error = 1; |
74 | error = 1; |
| 72 | } |
75 | } |
| 73 | /* |
76 | /* |
| 74 | ************************************************************ |
77 | ************************************************************ |
| 75 | * * |
78 | * * |
| Line 81... | Line 84... | ||
| 81 | temp_score = 0; |
84 | temp_score = 0; |
| 82 | for (side = black; side <= white; side++) |
85 | for (side = black; side <= white; side++) |
| 83 | for (piece = pawn; piece < king; piece++) |
86 | for (piece = pawn; piece < king; piece++) |
| 84 | temp_score += PopCnt(Pieces(side, piece)) * PieceValues(side, piece); |
87 | temp_score += PopCnt(Pieces(side, piece)) * PieceValues(side, piece); |
| 85 | if (temp_score != Material) { |
88 | if (temp_score != Material) { |
| - | 89 | if (!error) |
|
| - | 90 | Print(2048, "\n"); |
|
| 86 | Print( |
91 | Print(2048, "ERROR material evaluation is wrong, good=%d, bad=%d\n", |
| 87 | temp_score, Material); |
92 | temp_score, Material); |
| 88 | error = 1; |
93 | error = 1; |
| 89 | } |
94 | } |
| 90 | /* |
95 | /* |
| 91 | ************************************************************ |
96 | ************************************************************ |
| Line 98... | Line 103... | ||
| 98 | for (side = black; side <= white; side++) { |
103 | for (side = black; side <= white; side++) { |
| 99 | temp_score = 0; |
104 | temp_score = 0; |
| 100 | for (piece = knight; piece < king; piece++) |
105 | for (piece = knight; piece < king; piece++) |
| 101 | temp_score += PopCnt(Pieces(side, piece)) * p_vals[piece]; |
106 | temp_score += PopCnt(Pieces(side, piece)) * p_vals[piece]; |
| 102 | if (temp_score != TotalPieces(side, occupied)) { |
107 | if (temp_score != TotalPieces(side, occupied)) { |
| - | 108 | if (!error) |
|
| - | 109 | Print(2048, "\n"); |
|
| 103 | Print( |
110 | Print(2048, "ERROR %s pieces is wrong, good=%d, bad=%d\n", |
| 104 | (side) ? "white" : "black", temp_score, TotalPieces(side, |
111 | (side) ? "white" : "black", temp_score, TotalPieces(side, |
| 105 | occupied)); |
112 | occupied)); |
| 106 | error = 1; |
113 | error = 1; |
| 107 | } |
114 | } |
| 108 | } |
115 | } |
| 109 | for (side = black; side <= white; side++) { |
116 | for (side = black; side <= white; side++) { |
| 110 | temp_score = PopCnt(Pawns(side)); |
117 | temp_score = PopCnt(Pawns(side)); |
| 111 | if (temp_score != TotalPieces(side, pawn)) { |
118 | if (temp_score != TotalPieces(side, pawn)) { |
| - | 119 | if (!error) |
|
| - | 120 | Print(2048, "\n"); |
|
| 112 | Print( |
121 | Print(2048, "ERROR %s pawns is wrong, good=%d, bad=%d\n", |
| 113 | (side) ? "white" : "black", temp_score, TotalPieces(side, pawn)); |
122 | (side) ? "white" : "black", temp_score, TotalPieces(side, pawn)); |
| 114 | error = 1; |
123 | error = 1; |
| 115 | } |
124 | } |
| 116 | } |
125 | } |
| 117 | i = PopCnt(OccupiedSquares); |
126 | i = PopCnt(OccupiedSquares); |
| 118 | if (i != TotalAllPieces) { |
127 | if (i != TotalAllPieces) { |
| - | 128 | if (!error) |
|
| - | 129 | Print(2048, "\n"); |
|
| 119 | Print( |
130 | Print(2048, "ERROR! TotalAllPieces is wrong, correct=%d bad=%d\n", i, |
| 120 | TotalAllPieces); |
131 | TotalAllPieces); |
| 121 | error = 1; |
132 | error = 1; |
| 122 | } |
133 | } |
| 123 | /* |
134 | /* |
| 124 | ************************************************************ |
135 | ************************************************************ |
| Line 133... | Line 144... | ||
| 133 | for (piece = pawn; piece <= king; piece++) { |
144 | for (piece = pawn; piece <= king; piece++) { |
| 134 | temp = Pieces(side, piece); |
145 | temp = Pieces(side, piece); |
| 135 | while (temp) { |
146 | while (temp) { |
| 136 | square = LSB(temp); |
147 | square = LSB(temp); |
| 137 | if (PcOnSq(square) != pieces[side][piece]) { |
148 | if (PcOnSq(square) != pieces[side][piece]) { |
| - | 149 | if (!error) |
|
| - | 150 | Print(2048, "\n"); |
|
| 138 | Print( |
151 | Print(2048, "ERROR! board[%d]=%d, should be %d\n", square, |
| 139 | PcOnSq(square), pieces[side][piece]); |
152 | PcOnSq(square), pieces[side][piece]); |
| 140 | error = 1; |
153 | error = 1; |
| 141 | } |
154 | } |
| 142 | temp &= temp - 1; |
155 | temp &= temp - 1; |
| 143 | } |
156 | } |
| Line 155... | Line 168... | ||
| 155 | if (!PcOnSq(i)) |
168 | if (!PcOnSq(i)) |
| 156 | continue; |
169 | continue; |
| 157 | side = (PcOnSq(i) > 0) ? 1 : 0; |
170 | side = (PcOnSq(i) > 0) ? 1 : 0; |
| 158 | if (SetMask(i) & Pieces(side, Abs(PcOnSq(i)))) |
171 | if (SetMask(i) & Pieces(side, Abs(PcOnSq(i)))) |
| 159 | continue; |
172 | continue; |
| - | 173 | if (!error) |
|
| - | 174 | Print(2048, "\n"); |
|
| 160 | Print( |
175 | Print(2048, "ERROR! bitboards/board[%d] don't agree!\n", i); |
| 161 | error = 1; |
176 | error = 1; |
| 162 | break; |
177 | break; |
| 163 | } |
178 | } |
| 164 | /* |
179 | /* |
| 165 | ************************************************************ |
180 | ************************************************************ |
| Line 172... | Line 187... | ||
| 172 | */ |
187 | */ |
| 173 | temp = ~(temp_occ | temp_occx); |
188 | temp = ~(temp_occ | temp_occx); |
| 174 | while (temp) { |
189 | while (temp) { |
| 175 | square = LSB(temp); |
190 | square = LSB(temp); |
| 176 | if (PcOnSq(square)) { |
191 | if (PcOnSq(square)) { |
| - | 192 | if (!error) |
|
| - | 193 | Print(2048, "\n"); |
|
| 177 | Print( |
194 | Print(2048, "ERROR! board[%d]=%d, should be 0\n", square, |
| 178 | PcOnSq(square)); |
195 | PcOnSq(square)); |
| 179 | error = 1; |
196 | error = 1; |
| 180 | } |
197 | } |
| 181 | temp &= temp - 1; |
198 | temp &= temp - 1; |
| 182 | } |
199 | } |
| Line 204... | Line 221... | ||
| 204 | temp ^= castle_random[0][side]; |
221 | temp ^= castle_random[0][side]; |
| 205 | if (Castle(ply, side) < 0 || !(Castle(ply, side) & 2)) |
222 | if (Castle(ply, side) < 0 || !(Castle(ply, side) & 2)) |
| 206 | temp ^= castle_random[1][side]; |
223 | temp ^= castle_random[1][side]; |
| 207 | } |
224 | } |
| 208 | if (temp ^ HashKey) { |
225 | if (temp ^ HashKey) { |
| - | 226 | if (!error) |
|
| - | 227 | Print(2048, "\n"); |
|
| 209 | Print( |
228 | Print(2048, "ERROR! hash_key is bad.\n"); |
| 210 | error = 1; |
229 | error = 1; |
| 211 | } |
230 | } |
| 212 | if (temp1 ^ PawnHashKey) { |
231 | if (temp1 ^ PawnHashKey) { |
| - | 232 | if (!error) |
|
| - | 233 | Print(2048, "\n"); |
|
| 213 | Print( |
234 | Print(2048, "ERROR! pawn_hash_key is bad.\n"); |
| 214 | error = 1; |
235 | error = 1; |
| 215 | } |
236 | } |
| 216 | /* |
237 | /* |
| 217 | ************************************************************ |
238 | ************************************************************ |
| 218 | * * |
239 | * * |
| Line 221... | Line 242... | ||
| 221 | * help pinpoint the source of the problem. * |
242 | * help pinpoint the source of the problem. * |
| 222 | * * |
243 | * * |
| 223 | ************************************************************ |
244 | ************************************************************ |
| 224 | */ |
245 | */ |
| 225 | if (error) { |
246 | if (error) { |
| - | 247 | Lock(lock_smp); |
|
| - | 248 | Unlock(lock_smp); |
|
| 226 | Print( |
249 | Print(2048, "ply=%d\n", tree->ply); |
| 227 | Print( |
250 | Print(2048, "phase[%d]=%d current move:\n", ply, tree->phase[ply]); |
| 228 | DisplayChessMove("move=", move); |
251 | DisplayChessMove("move=", move); |
| 229 | DisplayChessBoard(stdout, tree->position); |
252 | DisplayChessBoard(stdout, tree->position); |
| 230 | Print( |
253 | Print(2048, "called from %s, ply=%d\n", caller, ply); |
| 231 | Print( |
254 | Print(2048, "node=%" PRIu64 "\n", tree->nodes_searched); |
| 232 | Print( |
255 | Print(2048, "active path:\n"); |
| 233 | for (i = 1; i <= ply; i++) |
256 | for (i = 1; i <= ply; i++) { |
| - | 257 | Print(2048, "ply=%d ", i); |
|
| 234 | DisplayChessMove("move=", tree->curmv[i]); |
258 | DisplayChessMove("move=", tree->curmv[i]); |
| - | 259 | } |
|
| 235 | CraftyExit(1); |
260 | CraftyExit(1); |
| 236 | } |
261 | } |
| 237 | } |
262 | } |
| 238 | #endif |
263 | #endif |