Rev 169 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 169 | Rev 185 | ||
|---|---|---|---|
| Line 4... | Line 4... | ||
| 4 | Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad |
4 | Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad |
| 5 | Copyright (C) 2015- |
5 | Copyright (C) 2015-2019 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad |
| 6 | 6 | ||
| 7 | Stockfish is free software: you can redistribute it and/or modify |
7 | Stockfish is free software: you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation, either version 3 of the License, or |
9 | the Free Software Foundation, either version 3 of the License, or |
| 10 | (at your option) any later version. |
10 | (at your option) any later version. |
| Line 41... | Line 41... | ||
| 41 | Key materialKey; |
41 | Key materialKey; |
| 42 | Value nonPawnMaterial[COLOR_NB]; |
42 | Value nonPawnMaterial[COLOR_NB]; |
| 43 | int castlingRights; |
43 | int castlingRights; |
| 44 | int rule50; |
44 | int rule50; |
| 45 | int pliesFromNull; |
45 | int pliesFromNull; |
| 46 | Score psq; |
- | |
| 47 | Square epSquare; |
46 | Square epSquare; |
| 48 | 47 | ||
| 49 | // Not copied when making a move (will be recomputed anyhow) |
48 | // Not copied when making a move (will be recomputed anyhow) |
| 50 | Key key; |
49 | Key key; |
| 51 | Bitboard checkersBB; |
50 | Bitboard checkersBB; |
| 52 | Piece capturedPiece; |
51 | Piece capturedPiece; |
| 53 | StateInfo* previous; |
52 | StateInfo* previous; |
| 54 | Bitboard blockersForKing[COLOR_NB]; |
53 | Bitboard blockersForKing[COLOR_NB]; |
| 55 | Bitboard |
54 | Bitboard pinners[COLOR_NB]; |
| 56 | Bitboard checkSquares[PIECE_TYPE_NB]; |
55 | Bitboard checkSquares[PIECE_TYPE_NB]; |
| 57 | }; |
56 | }; |
| 58 | 57 | ||
| 59 | /// A list to keep track of the position states along the setup moves (from the |
58 | /// A list to keep track of the position states along the setup moves (from the |
| 60 | /// start position to the position just before the search starts). Needed by |
59 | /// start position to the position just before the search starts). Needed by |
| Line 103... | Line 102... | ||
| 103 | bool castling_impeded(CastlingRight cr) const; |
102 | bool castling_impeded(CastlingRight cr) const; |
| 104 | Square castling_rook_square(CastlingRight cr) const; |
103 | Square castling_rook_square(CastlingRight cr) const; |
| 105 | 104 | ||
| 106 | // Checking |
105 | // Checking |
| 107 | Bitboard checkers() const; |
106 | Bitboard checkers() const; |
| 108 | Bitboard discovered_check_candidates() const; |
- | |
| 109 | Bitboard |
107 | Bitboard blockers_for_king(Color c) const; |
| 110 | Bitboard check_squares(PieceType pt) const; |
108 | Bitboard check_squares(PieceType pt) const; |
| 111 | 109 | ||
| 112 | // Attacks to/from a given square |
110 | // Attacks to/from a given square |
| 113 | Bitboard attackers_to(Square s) const; |
111 | Bitboard attackers_to(Square s) const; |
| 114 | Bitboard attackers_to(Square s, Bitboard occupied) const; |
112 | Bitboard attackers_to(Square s, Bitboard occupied) const; |
| Line 151... | Line 149... | ||
| 151 | Color side_to_move() const; |
149 | Color side_to_move() const; |
| 152 | int game_ply() const; |
150 | int game_ply() const; |
| 153 | bool is_chess960() const; |
151 | bool is_chess960() const; |
| 154 | Thread* this_thread() const; |
152 | Thread* this_thread() const; |
| 155 | bool is_draw(int ply) const; |
153 | bool is_draw(int ply) const; |
| - | 154 | bool has_game_cycle(int ply) const; |
|
| - | 155 | bool has_repeated() const; |
|
| 156 | int rule50_count() const; |
156 | int rule50_count() const; |
| 157 | Score psq_score() const; |
157 | Score psq_score() const; |
| 158 | Value non_pawn_material(Color c) const; |
158 | Value non_pawn_material(Color c) const; |
| 159 | Value non_pawn_material() const; |
159 | Value non_pawn_material() const; |
| 160 | 160 | ||
| Line 185... | Line 185... | ||
| 185 | int castlingRightsMask[SQUARE_NB]; |
185 | int castlingRightsMask[SQUARE_NB]; |
| 186 | Square castlingRookSquare[CASTLING_RIGHT_NB]; |
186 | Square castlingRookSquare[CASTLING_RIGHT_NB]; |
| 187 | Bitboard castlingPath[CASTLING_RIGHT_NB]; |
187 | Bitboard castlingPath[CASTLING_RIGHT_NB]; |
| 188 | int gamePly; |
188 | int gamePly; |
| 189 | Color sideToMove; |
189 | Color sideToMove; |
| - | 190 | Score psq; |
|
| 190 | Thread* thisThread; |
191 | Thread* thisThread; |
| 191 | StateInfo* st; |
192 | StateInfo* st; |
| 192 | bool chess960; |
193 | bool chess960; |
| 193 | }; |
194 | }; |
| - | 195 | ||
| - | 196 | namespace PSQT { |
|
| - | 197 | extern Score psq[PIECE_NB][SQUARE_NB]; |
|
| - | 198 | } |
|
| 194 | 199 | ||
| 195 | extern std::ostream& operator<<(std::ostream& os, const Position& pos); |
200 | extern std::ostream& operator<<(std::ostream& os, const Position& pos); |
| 196 | 201 | ||
| 197 | inline Color Position::side_to_move() const { |
202 | inline Color Position::side_to_move() const { |
| 198 | return sideToMove; |
203 | return sideToMove; |
| Line 294... | Line 299... | ||
| 294 | 299 | ||
| 295 | inline Bitboard Position::checkers() const { |
300 | inline Bitboard Position::checkers() const { |
| 296 | return st->checkersBB; |
301 | return st->checkersBB; |
| 297 | } |
302 | } |
| 298 | 303 | ||
| 299 | inline Bitboard Position::discovered_check_candidates() const { |
- | |
| 300 | return st->blockersForKing[~sideToMove] & pieces(sideToMove); |
- | |
| 301 | } |
- | |
| 302 | - | ||
| 303 | inline Bitboard Position:: |
304 | inline Bitboard Position::blockers_for_king(Color c) const { |
| 304 | return st->blockersForKing[c] |
305 | return st->blockersForKing[c]; |
| 305 | } |
306 | } |
| 306 | 307 | ||
| 307 | inline Bitboard Position::check_squares(PieceType pt) const { |
308 | inline Bitboard Position::check_squares(PieceType pt) const { |
| 308 | return st->checkSquares[pt]; |
309 | return st->checkSquares[pt]; |
| 309 | } |
310 | } |
| Line 328... | Line 329... | ||
| 328 | inline Key Position::material_key() const { |
329 | inline Key Position::material_key() const { |
| 329 | return st->materialKey; |
330 | return st->materialKey; |
| 330 | } |
331 | } |
| 331 | 332 | ||
| 332 | inline Score Position::psq_score() const { |
333 | inline Score Position::psq_score() const { |
| 333 | return |
334 | return psq; |
| 334 | } |
335 | } |
| 335 | 336 | ||
| 336 | inline Value Position::non_pawn_material(Color c) const { |
337 | inline Value Position::non_pawn_material(Color c) const { |
| 337 | return st->nonPawnMaterial[c]; |
338 | return st->nonPawnMaterial[c]; |
| 338 | } |
339 | } |
| Line 385... | Line 386... | ||
| 385 | byTypeBB[type_of(pc)] |= s; |
386 | byTypeBB[type_of(pc)] |= s; |
| 386 | byColorBB[color_of(pc)] |= s; |
387 | byColorBB[color_of(pc)] |= s; |
| 387 | index[s] = pieceCount[pc]++; |
388 | index[s] = pieceCount[pc]++; |
| 388 | pieceList[pc][index[s]] = s; |
389 | pieceList[pc][index[s]] = s; |
| 389 | pieceCount[make_piece(color_of(pc), ALL_PIECES)]++; |
390 | pieceCount[make_piece(color_of(pc), ALL_PIECES)]++; |
| - | 391 | psq += PSQT::psq[pc][s]; |
|
| 390 | } |
392 | } |
| 391 | 393 | ||
| 392 | inline void Position::remove_piece(Piece pc, Square s) { |
394 | inline void Position::remove_piece(Piece pc, Square s) { |
| 393 | 395 | ||
| 394 | // WARNING: This is not a reversible operation. If we remove a piece in |
396 | // WARNING: This is not a reversible operation. If we remove a piece in |
| Line 402... | Line 404... | ||
| 402 | Square lastSquare = pieceList[pc][--pieceCount[pc]]; |
404 | Square lastSquare = pieceList[pc][--pieceCount[pc]]; |
| 403 | index[lastSquare] = index[s]; |
405 | index[lastSquare] = index[s]; |
| 404 | pieceList[pc][index[lastSquare]] = lastSquare; |
406 | pieceList[pc][index[lastSquare]] = lastSquare; |
| 405 | pieceList[pc][pieceCount[pc]] = SQ_NONE; |
407 | pieceList[pc][pieceCount[pc]] = SQ_NONE; |
| 406 | pieceCount[make_piece(color_of(pc), ALL_PIECES)]--; |
408 | pieceCount[make_piece(color_of(pc), ALL_PIECES)]--; |
| - | 409 | psq -= PSQT::psq[pc][s]; |
|
| 407 | } |
410 | } |
| 408 | 411 | ||
| 409 | inline void Position::move_piece(Piece pc, Square from, Square to) { |
412 | inline void Position::move_piece(Piece pc, Square from, Square to) { |
| 410 | 413 | ||
| 411 | // index[from] is not updated and becomes stale. This works as long as index[] |
414 | // index[from] is not updated and becomes stale. This works as long as index[] |
| 412 | // is accessed just by known occupied squares. |
415 | // is accessed just by known occupied squares. |
| 413 | Bitboard |
416 | Bitboard fromTo = SquareBB[from] ^ SquareBB[to]; |
| 414 | byTypeBB[ALL_PIECES] ^= |
417 | byTypeBB[ALL_PIECES] ^= fromTo; |
| 415 | byTypeBB[type_of(pc)] ^= |
418 | byTypeBB[type_of(pc)] ^= fromTo; |
| 416 | byColorBB[color_of(pc)] ^= |
419 | byColorBB[color_of(pc)] ^= fromTo; |
| 417 | board[from] = NO_PIECE; |
420 | board[from] = NO_PIECE; |
| 418 | board[to] = pc; |
421 | board[to] = pc; |
| 419 | index[to] = index[from]; |
422 | index[to] = index[from]; |
| 420 | pieceList[pc][index[to]] = to; |
423 | pieceList[pc][index[to]] = to; |
| - | 424 | psq += PSQT::psq[pc][to] - PSQT::psq[pc][from]; |
|
| 421 | } |
425 | } |
| 422 | 426 | ||
| 423 | inline void Position::do_move(Move m, StateInfo& newSt) { |
427 | inline void Position::do_move(Move m, StateInfo& newSt) { |
| 424 | do_move(m, newSt, gives_check(m)); |
428 | do_move(m, newSt, gives_check(m)); |
| 425 | } |
429 | } |