]> git.sesse.net Git - stockfish/commitdiff
Big Position renaming
authorMarco Costalba <mcostalba@gmail.com>
Mon, 2 Apr 2012 17:21:17 +0000 (18:21 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 4 Apr 2012 06:35:49 +0000 (07:35 +0100)
No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/endgame.cpp
src/evaluate.cpp
src/position.cpp
src/position.h
src/search.cpp
src/thread.cpp
src/uci.cpp

index 763a402e7bd3a4683b0e49a05b989877b68f9da5..0e70efe1d386fd387018d787be94acce38bc7d25 100644 (file)
@@ -148,7 +148,7 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
 
   if (   pos.piece_count(strongerSide, QUEEN)
       || pos.piece_count(strongerSide, ROOK)
 
   if (   pos.piece_count(strongerSide, QUEEN)
       || pos.piece_count(strongerSide, ROOK)
-      || pos.both_color_bishops(strongerSide)) {
+      || pos.bishop_pair(strongerSide)) {
     result += VALUE_KNOWN_WIN;
   }
 
     result += VALUE_KNOWN_WIN;
   }
 
index e61a93e11d41189dad6c9b73647c3d28b936914c..4d47b7e6df64a681bdc1b979626a04d942643d32 100644 (file)
@@ -364,14 +364,14 @@ Value do_evaluate(const Position& pos, Value& margin) {
 
   // Initialize score by reading the incrementally updated scores included
   // in the position object (material + piece square tables).
 
   // Initialize score by reading the incrementally updated scores included
   // in the position object (material + piece square tables).
-  score = pos.value();
+  score = pos.psq_score();
 
   // margins[] store the uncertainty estimation of position's evaluation
   // that typically is used by the search for pruning decisions.
   margins[WHITE] = margins[BLACK] = VALUE_ZERO;
 
   // Probe the material hash table
 
   // margins[] store the uncertainty estimation of position's evaluation
   // that typically is used by the search for pruning decisions.
   margins[WHITE] = margins[BLACK] = VALUE_ZERO;
 
   // Probe the material hash table
-  ei.mi = Threads[pos.thread()].materialTable.probe(pos);
+  ei.mi = Threads[pos.this_thread()].materialTable.probe(pos);
   score += ei.mi->material_value();
 
   // If we have a specialized evaluation function for the current material
   score += ei.mi->material_value();
 
   // If we have a specialized evaluation function for the current material
@@ -383,7 +383,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
   }
 
   // Probe the pawn hash table
   }
 
   // Probe the pawn hash table
-  ei.pi = Threads[pos.thread()].pawnTable.probe(pos);
+  ei.pi = Threads[pos.this_thread()].pawnTable.probe(pos);
   score += ei.pi->pawns_value();
 
   // Initialize attack and king safety bitboards
   score += ei.pi->pawns_value();
 
   // Initialize attack and king safety bitboards
@@ -427,7 +427,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
   // If we don't already have an unusual scale factor, check for opposite
   // colored bishop endgames, and use a lower scale for those.
   if (   ei.mi->game_phase() < PHASE_MIDGAME
   // If we don't already have an unusual scale factor, check for opposite
   // colored bishop endgames, and use a lower scale for those.
   if (   ei.mi->game_phase() < PHASE_MIDGAME
-      && pos.opposite_colored_bishops()
+      && pos.opposite_bishops()
       && sf == SCALE_FACTOR_NORMAL)
   {
       // Only the two bishops ?
       && sf == SCALE_FACTOR_NORMAL)
   {
       // Only the two bishops ?
@@ -451,7 +451,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
   // In case of tracing add all single evaluation contributions for both white and black
   if (Trace)
   {
   // In case of tracing add all single evaluation contributions for both white and black
   if (Trace)
   {
-      trace_add(PST, pos.value());
+      trace_add(PST, pos.psq_score());
       trace_add(IMBALANCE, ei.mi->material_value());
       trace_add(PAWN, ei.pi->pawns_value());
       trace_add(MOBILITY, apply_weight(mobilityWhite, Weights[Mobility]), apply_weight(mobilityBlack, Weights[Mobility]));
       trace_add(IMBALANCE, ei.mi->material_value());
       trace_add(PAWN, ei.pi->pawns_value());
       trace_add(MOBILITY, apply_weight(mobilityWhite, Weights[Mobility]), apply_weight(mobilityBlack, Weights[Mobility]));
@@ -610,7 +610,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
                 Square d = pawn_push(Us) + (file_of(s) == FILE_A ? DELTA_E : DELTA_W);
                 if (pos.piece_on(s + d) == make_piece(Us, PAWN))
                 {
                 Square d = pawn_push(Us) + (file_of(s) == FILE_A ? DELTA_E : DELTA_W);
                 if (pos.piece_on(s + d) == make_piece(Us, PAWN))
                 {
-                    if (!pos.square_is_empty(s + d + pawn_push(Us)))
+                    if (!pos.square_empty(s + d + pawn_push(Us)))
                         score -= 2*TrappedBishopA1H1Penalty;
                     else if (pos.piece_on(s + 2*d) == make_piece(Us, PAWN))
                         score -= TrappedBishopA1H1Penalty;
                         score -= 2*TrappedBishopA1H1Penalty;
                     else if (pos.piece_on(s + 2*d) == make_piece(Us, PAWN))
                         score -= TrappedBishopA1H1Penalty;
@@ -891,7 +891,7 @@ Value do_evaluate(const Position& pos, Value& margin) {
                 ebonus -= Value(square_distance(pos.king_square(Us), blockSq + pawn_push(Us)) * rr);
 
             // If the pawn is free to advance, increase bonus
                 ebonus -= Value(square_distance(pos.king_square(Us), blockSq + pawn_push(Us)) * rr);
 
             // If the pawn is free to advance, increase bonus
-            if (pos.square_is_empty(blockSq))
+            if (pos.square_empty(blockSq))
             {
                 squaresToQueen = squares_in_front_of(Us, s);
                 defendedSquares = squaresToQueen & ei.attackedBy[Us][0];
             {
                 squaresToQueen = squares_in_front_of(Us, s);
                 defendedSquares = squaresToQueen & ei.attackedBy[Us][0];
index e3ee3d26ea59e20965036dc5788e741ad88324dd..57d6dc09bce917c7d9014f1d31340b6ed6134dd8 100644 (file)
@@ -66,7 +66,7 @@ const Value PieceValueEndgame[17] = {
 namespace {
 
   // Bonus for having the side to move (modified by Joona Kiiski)
 namespace {
 
   // Bonus for having the side to move (modified by Joona Kiiski)
-  const Score TempoValue = make_score(48, 22);
+  const Score Tempo = make_score(48, 22);
 
   // To convert a Piece to and from a FEN char
   const string PieceToChar(" PNBRQK  pnbrqk  .");
 
   // To convert a Piece to and from a FEN char
   const string PieceToChar(" PNBRQK  pnbrqk  .");
@@ -229,7 +229,7 @@ void Position::from_fen(const string& fenStr, bool isChess960) {
   st->key = compute_key();
   st->pawnKey = compute_pawn_key();
   st->materialKey = compute_material_key();
   st->key = compute_key();
   st->pawnKey = compute_pawn_key();
   st->materialKey = compute_material_key();
-  st->value = compute_value();
+  st->psqScore = compute_psq_score();
   st->npMaterial[WHITE] = compute_non_pawn_material(WHITE);
   st->npMaterial[BLACK] = compute_non_pawn_material(BLACK);
   st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove);
   st->npMaterial[WHITE] = compute_non_pawn_material(WHITE);
   st->npMaterial[BLACK] = compute_non_pawn_material(BLACK);
   st->checkersBB = attackers_to(king_square(sideToMove)) & pieces(~sideToMove);
@@ -283,7 +283,7 @@ const string Position::to_fen() const {
       {
           sq = make_square(file, rank);
 
       {
           sq = make_square(file, rank);
 
-          if (square_is_empty(sq))
+          if (square_empty(sq))
               emptyCnt++;
           else
           {
               emptyCnt++;
           else
           {
@@ -336,7 +336,7 @@ void Position::print(Move move) const {
 
   if (move)
   {
 
   if (move)
   {
-      Position p(*this, thread());
+      Position p(*this, this_thread());
       cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "") << move_to_san(p, move);
   }
 
       cout << "\nMove is: " << (sideToMove == BLACK ? ".." : "") << move_to_san(p, move);
   }
 
@@ -434,7 +434,7 @@ bool Position::move_attacks_square(Move m, Square s) const {
   Square to = to_sq(m);
   Piece piece = piece_moved(m);
 
   Square to = to_sq(m);
   Piece piece = piece_moved(m);
 
-  assert(!square_is_empty(from));
+  assert(!square_empty(from));
 
   // Update occupancy as if the piece is moving
   occ = pieces() ^ from ^ to;
 
   // Update occupancy as if the piece is moving
   occ = pieces() ^ from ^ to;
@@ -576,7 +576,7 @@ bool Position::is_pseudo_legal(const Move m) const {
       case DELTA_N:
       case DELTA_S:
       // Pawn push. The destination square must be empty.
       case DELTA_N:
       case DELTA_S:
       // Pawn push. The destination square must be empty.
-      if (!square_is_empty(to))
+      if (!square_empty(to))
           return false;
       break;
 
           return false;
       break;
 
@@ -585,8 +585,8 @@ bool Position::is_pseudo_legal(const Move m) const {
       // rank, and both the destination square and the square between the
       // source and destination squares must be empty.
       if (   rank_of(to) != RANK_4
       // rank, and both the destination square and the square between the
       // source and destination squares must be empty.
       if (   rank_of(to) != RANK_4
-          || !square_is_empty(to)
-          || !square_is_empty(from + DELTA_N))
+          || !square_empty(to)
+          || !square_empty(from + DELTA_N))
           return false;
       break;
 
           return false;
       break;
 
@@ -595,8 +595,8 @@ bool Position::is_pseudo_legal(const Move m) const {
       // rank, and both the destination square and the square between the
       // source and destination squares must be empty.
       if (   rank_of(to) != RANK_5
       // rank, and both the destination square and the square between the
       // source and destination squares must be empty.
       if (   rank_of(to) != RANK_5
-          || !square_is_empty(to)
-          || !square_is_empty(from + DELTA_S))
+          || !square_empty(to)
+          || !square_empty(from + DELTA_S))
           return false;
       break;
 
           return false;
       break;
 
@@ -724,7 +724,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
     Key pawnKey, materialKey;
     Value npMaterial[2];
     int castleRights, rule50, pliesFromNull;
     Key pawnKey, materialKey;
     Value npMaterial[2];
     int castleRights, rule50, pliesFromNull;
-    Score value;
+    Score psq_score;
     Square epSquare;
   };
 
     Square epSquare;
   };
 
@@ -808,7 +808,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
       st->materialKey ^= zobrist[them][capture][pieceCount[them][capture]];
 
       // Update incremental scores
       st->materialKey ^= zobrist[them][capture][pieceCount[them][capture]];
 
       // Update incremental scores
-      st->value -= pst(make_piece(them, capture), capsq);
+      st->psqScore -= pieceSquareTable[make_piece(them, capture)][capsq];
 
       // Reset rule 50 counter
       st->rule50 = 0;
 
       // Reset rule 50 counter
       st->rule50 = 0;
@@ -888,8 +888,8 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
                             ^ zobrist[us][PAWN][pieceCount[us][PAWN]];
 
           // Update incremental score
                             ^ zobrist[us][PAWN][pieceCount[us][PAWN]];
 
           // Update incremental score
-          st->value +=  pst(make_piece(us, promotion), to)
-                      - pst(make_piece(us, PAWN), to);
+          st->psqScore +=  pieceSquareTable[make_piece(us, promotion)][to]
+                         - pieceSquareTable[make_piece(us, PAWN)][to];
 
           // Update material
           st->npMaterial[us] += PieceValueMidgame[promotion];
 
           // Update material
           st->npMaterial[us] += PieceValueMidgame[promotion];
@@ -907,7 +907,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
   prefetch((char*)Threads[threadID].materialTable.entries[st->materialKey]);
 
   // Update incremental scores
   prefetch((char*)Threads[threadID].materialTable.entries[st->materialKey]);
 
   // Update incremental scores
-  st->value += pst_delta(piece, from, to);
+  st->psqScore += psq_delta(piece, from, to);
 
   // Set capture piece
   st->capturedType = capture;
 
   // Set capture piece
   st->capturedType = capture;
@@ -942,7 +942,7 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
 
   // Finish
   sideToMove = ~sideToMove;
 
   // Finish
   sideToMove = ~sideToMove;
-  st->value += (sideToMove == WHITE ?  TempoValue : -TempoValue);
+  st->psqScore += (sideToMove == WHITE ?  Tempo : -Tempo);
 
   assert(pos_is_ok());
 }
 
   assert(pos_is_ok());
 }
@@ -971,7 +971,7 @@ void Position::undo_move(Move m) {
   PieceType pt = type_of(piece);
   PieceType capture = st->capturedType;
 
   PieceType pt = type_of(piece);
   PieceType capture = st->capturedType;
 
-  assert(square_is_empty(from));
+  assert(square_empty(from));
   assert(color_of(piece) == us);
   assert(capture != KING);
 
   assert(color_of(piece) == us);
   assert(capture != KING);
 
@@ -1120,8 +1120,8 @@ void Position::do_castle_move(Move m) {
       st->capturedType = NO_PIECE_TYPE;
 
       // Update incremental scores
       st->capturedType = NO_PIECE_TYPE;
 
       // Update incremental scores
-      st->value += pst_delta(king, kfrom, kto);
-      st->value += pst_delta(rook, rfrom, rto);
+      st->psqScore += psq_delta(king, kfrom, kto);
+      st->psqScore += psq_delta(rook, rfrom, rto);
 
       // Update hash key
       st->key ^= zobrist[us][KING][kfrom] ^ zobrist[us][KING][kto];
 
       // Update hash key
       st->key ^= zobrist[us][KING][kfrom] ^ zobrist[us][KING][kto];
@@ -1143,7 +1143,7 @@ void Position::do_castle_move(Move m) {
 
       // Finish
       sideToMove = ~sideToMove;
 
       // Finish
       sideToMove = ~sideToMove;
-      st->value += (sideToMove == WHITE ?  TempoValue : -TempoValue);
+      st->psqScore += (sideToMove == WHITE ?  Tempo : -Tempo);
   }
   else
       // Undo: point our state pointer back to the previous state
   }
   else
       // Undo: point our state pointer back to the previous state
@@ -1169,7 +1169,7 @@ void Position::do_null_move(StateInfo& backupSt) {
 
   dst->key      = src->key;
   dst->epSquare = src->epSquare;
 
   dst->key      = src->key;
   dst->epSquare = src->epSquare;
-  dst->value    = src->value;
+  dst->psqScore = src->psqScore;
   dst->rule50   = src->rule50;
   dst->pliesFromNull = src->pliesFromNull;
 
   dst->rule50   = src->rule50;
   dst->pliesFromNull = src->pliesFromNull;
 
@@ -1186,7 +1186,7 @@ void Position::do_null_move(StateInfo& backupSt) {
       st->epSquare = SQ_NONE;
       st->rule50++;
       st->pliesFromNull = 0;
       st->epSquare = SQ_NONE;
       st->rule50++;
       st->pliesFromNull = 0;
-      st->value += (sideToMove == WHITE) ?  TempoValue : -TempoValue;
+      st->psqScore += (sideToMove == WHITE ?  Tempo : -Tempo);
   }
 
   assert(pos_is_ok());
   }
 
   assert(pos_is_ok());
@@ -1361,7 +1361,7 @@ Key Position::compute_key() const {
   Key result = zobCastle[st->castleRights];
 
   for (Square s = SQ_A1; s <= SQ_H8; s++)
   Key result = zobCastle[st->castleRights];
 
   for (Square s = SQ_A1; s <= SQ_H8; s++)
-      if (!square_is_empty(s))
+      if (!square_empty(s))
           result ^= zobrist[color_of(piece_on(s))][type_of(piece_on(s))][s];
 
   if (ep_square() != SQ_NONE)
           result ^= zobrist[color_of(piece_on(s))][type_of(piece_on(s))][s];
 
   if (ep_square() != SQ_NONE)
@@ -1414,11 +1414,11 @@ Key Position::compute_material_key() const {
 }
 
 
 }
 
 
-/// Position::compute_value() compute the incremental scores for the middle
+/// Position::compute_psq_score() computes the incremental scores for the middle
 /// game and the endgame. These functions are used to initialize the incremental
 /// scores when a new position is set up, and to verify that the scores are correctly
 /// updated by do_move and undo_move when the program is running in debug mode.
 /// game and the endgame. These functions are used to initialize the incremental
 /// scores when a new position is set up, and to verify that the scores are correctly
 /// updated by do_move and undo_move when the program is running in debug mode.
-Score Position::compute_value() const {
+Score Position::compute_psq_score() const {
 
   Bitboard b;
   Score result = SCORE_ZERO;
 
   Bitboard b;
   Score result = SCORE_ZERO;
@@ -1428,10 +1428,10 @@ Score Position::compute_value() const {
       {
           b = pieces(pt, c);
           while (b)
       {
           b = pieces(pt, c);
           while (b)
-              result += pst(make_piece(c, pt), pop_1st_bit(&b));
+              result += pieceSquareTable[make_piece(c, pt)][pop_1st_bit(&b)];
       }
 
       }
 
-  result += (sideToMove == WHITE ? TempoValue / 2 : -TempoValue / 2);
+  result += (sideToMove == WHITE ? Tempo / 2 : -Tempo / 2);
   return result;
 }
 
   return result;
 }
 
@@ -1540,20 +1540,20 @@ void Position::init() {
 }
 
 
 }
 
 
-/// Position::flip_me() flips position with the white and black sides reversed. This
+/// Position::flip() flips position with the white and black sides reversed. This
 /// is only useful for debugging especially for finding evaluation symmetry bugs.
 
 /// is only useful for debugging especially for finding evaluation symmetry bugs.
 
-void Position::flip_me() {
+void Position::flip() {
 
   // Make a copy of current position before to start changing
   const Position pos(*this, threadID);
 
   clear();
 
   // Make a copy of current position before to start changing
   const Position pos(*this, threadID);
 
   clear();
-  threadID = pos.thread();
+  threadID = pos.this_thread();
 
   // Board
   for (Square s = SQ_A1; s <= SQ_H8; s++)
 
   // Board
   for (Square s = SQ_A1; s <= SQ_H8; s++)
-      if (!pos.square_is_empty(s))
+      if (!pos.square_empty(s))
           put_piece(Piece(pos.piece_on(s) ^ 8), ~s);
 
   // Side to move
           put_piece(Piece(pos.piece_on(s) ^ 8), ~s);
 
   // Side to move
@@ -1582,7 +1582,7 @@ void Position::flip_me() {
   st->materialKey = compute_material_key();
 
   // Incremental scores
   st->materialKey = compute_material_key();
 
   // Incremental scores
-  st->value = compute_value();
+  st->psqScore = compute_psq_score();
 
   // Material
   st->npMaterial[WHITE] = compute_non_pawn_material(WHITE);
 
   // Material
   st->npMaterial[WHITE] = compute_non_pawn_material(WHITE);
@@ -1704,7 +1704,7 @@ bool Position::pos_is_ok(int* failedStep) const {
 
   // Incremental eval OK?
   if (failedStep) (*failedStep)++;
 
   // Incremental eval OK?
   if (failedStep) (*failedStep)++;
-  if (debugIncrementalEval && st->value != compute_value())
+  if (debugIncrementalEval && st->psqScore != compute_psq_score())
       return false;
 
   // Non-pawn material OK?
       return false;
 
   // Non-pawn material OK?
index 488ed09f0a649b5dd4f9ff7e16904eea3497697b..b51002eb5eb929253188db27072bc36101638539 100644 (file)
@@ -50,7 +50,7 @@ struct StateInfo {
   Key pawnKey, materialKey;
   Value npMaterial[2];
   int castleRights, rule50, pliesFromNull;
   Key pawnKey, materialKey;
   Value npMaterial[2];
   int castleRights, rule50, pliesFromNull;
-  Score value;
+  Score psqScore;
   Square epSquare;
 
   Key key;
   Square epSquare;
 
   Key key;
@@ -99,49 +99,33 @@ public:
   const std::string to_fen() const;
   void print(Move m = MOVE_NONE) const;
 
   const std::string to_fen() const;
   void print(Move m = MOVE_NONE) const;
 
-  // The piece on a given square
-  Piece piece_on(Square s) const;
-  Piece piece_moved(Move m) const;
-  bool square_is_empty(Square s) const;
-
-  // Side to move
-  Color side_to_move() const;
-
-  // Bitboard representation of the position
+  // Position representation
   Bitboard pieces() const;
   Bitboard pieces(Color c) const;
   Bitboard pieces(PieceType pt) const;
   Bitboard pieces(PieceType pt, Color c) const;
   Bitboard pieces(PieceType pt1, PieceType pt2) const;
   Bitboard pieces(PieceType pt1, PieceType pt2, Color c) const;
   Bitboard pieces() const;
   Bitboard pieces(Color c) const;
   Bitboard pieces(PieceType pt) const;
   Bitboard pieces(PieceType pt, Color c) const;
   Bitboard pieces(PieceType pt1, PieceType pt2) const;
   Bitboard pieces(PieceType pt1, PieceType pt2, Color c) const;
-
-  // Number of pieces of each color and type
-  int piece_count(Color c, PieceType pt) const;
-
-  // The en passant square
-  Square ep_square() const;
-
-  // Current king position for each color
+  Piece piece_on(Square s) const;
   Square king_square(Color c) const;
   Square king_square(Color c) const;
+  Square ep_square() const;
+  bool square_empty(Square s) const;
+  const Square* piece_list(Color c, PieceType pt) const;
+  int piece_count(Color c, PieceType pt) const;
 
 
-  // Castling rights
+  // Castling
   bool can_castle(CastleRight f) const;
   bool can_castle(Color c) const;
   bool castle_impeded(CastleRight f) const;
   Square castle_rook_square(CastleRight f) const;
 
   bool can_castle(CastleRight f) const;
   bool can_castle(Color c) const;
   bool castle_impeded(CastleRight f) const;
   Square castle_rook_square(CastleRight f) const;
 
-  // Bitboards for pinned pieces and discovered check candidates
+  // Checking
+  bool in_check() const;
+  Bitboard checkers() const;
   Bitboard discovered_check_candidates() const;
   Bitboard pinned_pieces() const;
 
   Bitboard discovered_check_candidates() const;
   Bitboard pinned_pieces() const;
 
-  // Checking pieces and under check information
-  Bitboard checkers() const;
-  bool in_check() const;
-
-  // Piece lists
-  const Square* piece_list(Color c, PieceType pt) const;
-
-  // Information about attacks to or from a given square
+  // Attacks to/from a given square
   Bitboard attackers_to(Square s) const;
   Bitboard attackers_to(Square s, Bitboard occ) const;
   Bitboard attacks_from(Piece p, Square s) const;
   Bitboard attackers_to(Square s) const;
   Bitboard attackers_to(Square s, Bitboard occ) const;
   Bitboard attacks_from(Piece p, Square s) const;
@@ -157,12 +141,14 @@ public:
   bool is_capture(Move m) const;
   bool is_capture_or_promotion(Move m) const;
   bool is_passed_pawn_push(Move m) const;
   bool is_capture(Move m) const;
   bool is_capture_or_promotion(Move m) const;
   bool is_passed_pawn_push(Move m) const;
-
-  // Piece captured with previous moves
+  Piece piece_moved(Move m) const;
   PieceType captured_piece_type() const;
 
   PieceType captured_piece_type() const;
 
-  // Information about pawns
+  // Piece specific
   bool pawn_is_passed(Color c, Square s) const;
   bool pawn_is_passed(Color c, Square s) const;
+  bool pawn_on_7th(Color c) const;
+  bool opposite_bishops() const;
+  bool bishop_pair(Color c) const;
 
   // Doing and undoing moves
   void do_move(Move m, StateInfo& st);
 
   // Doing and undoing moves
   void do_move(Move m, StateInfo& st);
@@ -180,32 +166,29 @@ public:
   Key pawn_key() const;
   Key material_key() const;
 
   Key pawn_key() const;
   Key material_key() const;
 
-  // Incremental evaluation
-  Score value() const;
+  // Incremental piece-square evaluation
+  Score psq_score() const;
+  Score psq_delta(Piece p, Square from, Square to) const;
   Value non_pawn_material(Color c) const;
   Value non_pawn_material(Color c) const;
-  Score pst_delta(Piece piece, Square from, Square to) const;
 
   // Other properties of the position
 
   // Other properties of the position
-  template<bool SkipRepetition> bool is_draw() const;
+  Color side_to_move() const;
   int startpos_ply_counter() const;
   int startpos_ply_counter() const;
-  bool opposite_colored_bishops() const;
-  bool both_color_bishops(Color c) const;
-  bool has_pawn_on_7th(Color c) const;
   bool is_chess960() const;
   bool is_chess960() const;
-  int thread() const;
+  int this_thread() const;
   int64_t nodes_searched() const;
   void set_nodes_searched(int64_t n);
   int64_t nodes_searched() const;
   void set_nodes_searched(int64_t n);
+  template<bool SkipRepetition> bool is_draw() const;
 
   // Position consistency check, for debugging
   bool pos_is_ok(int* failedStep = NULL) const;
 
   // Position consistency check, for debugging
   bool pos_is_ok(int* failedStep = NULL) const;
-  void flip_me();
+  void flip();
 
   // Global initialization
   static void init();
 
 private:
 
   // Global initialization
   static void init();
 
 private:
-
-  // Initialization helper functions (used while setting up a position)
+  // Initialization helpers (used while setting up a position)
   void clear();
   void put_piece(Piece p, Square s);
   void set_castle_right(Color c, Square rfrom);
   void clear();
   void put_piece(Piece p, Square s);
   void set_castle_right(Color c, Square rfrom);
@@ -221,21 +204,14 @@ private:
   Key compute_material_key() const;
 
   // Computing incremental evaluation scores and material counts
   Key compute_material_key() const;
 
   // Computing incremental evaluation scores and material counts
-  Score pst(Piece p, Square s) const;
-  Score compute_value() const;
+  Score compute_psq_score() const;
   Value compute_non_pawn_material(Color c) const;
 
   Value compute_non_pawn_material(Color c) const;
 
-  // Board
+  // Board and pieces
   Piece board[64];             // [square]
   Piece board[64];             // [square]
-
-  // Bitboards
   Bitboard byTypeBB[8];        // [pieceType]
   Bitboard byColorBB[2];       // [color]
   Bitboard byTypeBB[8];        // [pieceType]
   Bitboard byColorBB[2];       // [color]
-
-  // Piece counts
   int pieceCount[2][8];        // [color][pieceType]
   int pieceCount[2][8];        // [color][pieceType]
-
-  // Piece lists
   Square pieceList[2][8][16];  // [color][pieceType][index]
   int index[64];               // [square]
 
   Square pieceList[2][8][16];  // [color][pieceType][index]
   int index[64];               // [square]
 
@@ -276,7 +252,7 @@ inline Piece Position::piece_moved(Move m) const {
   return board[from_sq(m)];
 }
 
   return board[from_sq(m)];
 }
 
-inline bool Position::square_is_empty(Square s) const {
+inline bool Position::square_empty(Square s) const {
   return board[s] == NO_PIECE;
 }
 
   return board[s] == NO_PIECE;
 }
 
@@ -342,6 +318,7 @@ inline Square Position::castle_rook_square(CastleRight f) const {
 
 template<PieceType Pt>
 inline Bitboard Position::attacks_from(Square s) const {
 
 template<PieceType Pt>
 inline Bitboard Position::attacks_from(Square s) const {
+
   return  Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, pieces())
         : Pt == QUEEN  ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
         : StepAttacksBB[Pt][s];
   return  Pt == BISHOP || Pt == ROOK ? attacks_bb<Pt>(s, pieces())
         : Pt == QUEEN  ? attacks_from<ROOK>(s) | attacks_from<BISHOP>(s)
         : StepAttacksBB[Pt][s];
@@ -396,16 +373,12 @@ inline Key Position::material_key() const {
   return st->materialKey;
 }
 
   return st->materialKey;
 }
 
-inline Score Position::pst(Piece p, Square s) const {
-  return pieceSquareTable[p][s];
-}
-
-inline Score Position::pst_delta(Piece piece, Square from, Square to) const {
-  return pieceSquareTable[piece][to] - pieceSquareTable[piece][from];
+inline Score Position::psq_delta(Piece p, Square from, Square to) const {
+  return pieceSquareTable[p][to] - pieceSquareTable[p][from];
 }
 
 }
 
-inline Score Position::value() const {
-  return st->value;
+inline Score Position::psq_score() const {
+  return st->psqScore;
 }
 
 inline Value Position::non_pawn_material(Color c) const {
 }
 
 inline Value Position::non_pawn_material(Color c) const {
@@ -414,7 +387,7 @@ inline Value Position::non_pawn_material(Color c) const {
 
 inline bool Position::is_passed_pawn_push(Move m) const {
 
 
 inline bool Position::is_passed_pawn_push(Move m) const {
 
-  return   board[from_sq(m)] == make_piece(sideToMove, PAWN)
+  return   type_of(piece_moved(m)) == PAWN
         && pawn_is_passed(sideToMove, to_sq(m));
 }
 
         && pawn_is_passed(sideToMove, to_sq(m));
 }
 
@@ -422,20 +395,20 @@ inline int Position::startpos_ply_counter() const {
   return startPosPly + st->pliesFromNull; // HACK
 }
 
   return startPosPly + st->pliesFromNull; // HACK
 }
 
-inline bool Position::opposite_colored_bishops() const {
+inline bool Position::opposite_bishops() const {
 
   return   pieceCount[WHITE][BISHOP] == 1
         && pieceCount[BLACK][BISHOP] == 1
         && opposite_colors(pieceList[WHITE][BISHOP][0], pieceList[BLACK][BISHOP][0]);
 }
 
 
   return   pieceCount[WHITE][BISHOP] == 1
         && pieceCount[BLACK][BISHOP] == 1
         && opposite_colors(pieceList[WHITE][BISHOP][0], pieceList[BLACK][BISHOP][0]);
 }
 
-inline bool Position::both_color_bishops(Color c) const {
-  // Assumes that there are only two bishops
-  return  pieceCount[c][BISHOP] >= 2 &&
-          opposite_colors(pieceList[c][BISHOP][0], pieceList[c][BISHOP][1]);
+inline bool Position::bishop_pair(Color c) const {
+
+  return   pieceCount[c][BISHOP] >= 2
+        && opposite_colors(pieceList[c][BISHOP][0], pieceList[c][BISHOP][1]);
 }
 
 }
 
-inline bool Position::has_pawn_on_7th(Color c) const {
+inline bool Position::pawn_on_7th(Color c) const {
   return pieces(PAWN, c) & rank_bb(relative_rank(c, RANK_7));
 }
 
   return pieces(PAWN, c) & rank_bb(relative_rank(c, RANK_7));
 }
 
@@ -446,21 +419,21 @@ inline bool Position::is_chess960() const {
 inline bool Position::is_capture_or_promotion(Move m) const {
 
   assert(is_ok(m));
 inline bool Position::is_capture_or_promotion(Move m) const {
 
   assert(is_ok(m));
-  return is_special(m) ? !is_castle(m) : !square_is_empty(to_sq(m));
+  return is_special(m) ? !is_castle(m) : !square_empty(to_sq(m));
 }
 
 inline bool Position::is_capture(Move m) const {
 
   // Note that castle is coded as "king captures the rook"
   assert(is_ok(m));
 }
 
 inline bool Position::is_capture(Move m) const {
 
   // Note that castle is coded as "king captures the rook"
   assert(is_ok(m));
-  return (!square_is_empty(to_sq(m)) && !is_castle(m)) || is_enpassant(m);
+  return (!square_empty(to_sq(m)) && !is_castle(m)) || is_enpassant(m);
 }
 
 inline PieceType Position::captured_piece_type() const {
   return st->capturedType;
 }
 
 }
 
 inline PieceType Position::captured_piece_type() const {
   return st->capturedType;
 }
 
-inline int Position::thread() const {
+inline int Position::this_thread() const {
   return threadID;
 }
 
   return threadID;
 }
 
index b8ac4ab3cd2940e13d3890effdddc69e4f0e4a45..da70c1221988d17e20452586415643e1382a9422 100644 (file)
@@ -332,7 +332,7 @@ finalize:
   // but if we are pondering or in infinite search, we shouldn't print the best
   // move before we are told to do so.
   if (!Signals.stop && (Limits.ponder || Limits.infinite))
   // but if we are pondering or in infinite search, we shouldn't print the best
   // move before we are told to do so.
   if (!Signals.stop && (Limits.ponder || Limits.infinite))
-      Threads[pos.thread()].wait_for_stop_or_ponderhit();
+      Threads[pos.this_thread()].wait_for_stop_or_ponderhit();
 
   // Best move could be MOVE_NONE when searching on a stalemate position
   cout << "bestmove " << move_to_uci(RootMoves[0].pv[0], Chess960)
 
   // Best move could be MOVE_NONE when searching on a stalemate position
   cout << "bestmove " << move_to_uci(RootMoves[0].pv[0], Chess960)
@@ -530,7 +530,7 @@ namespace {
     assert(alpha >= -VALUE_INFINITE && alpha < beta && beta <= VALUE_INFINITE);
     assert((alpha == beta - 1) || PvNode);
     assert(depth > DEPTH_ZERO);
     assert(alpha >= -VALUE_INFINITE && alpha < beta && beta <= VALUE_INFINITE);
     assert((alpha == beta - 1) || PvNode);
     assert(depth > DEPTH_ZERO);
-    assert(pos.thread() >= 0 && pos.thread() < Threads.size());
+    assert(pos.this_thread() >= 0 && pos.this_thread() < Threads.size());
 
     Move movesSearched[MAX_MOVES];
     StateInfo st;
 
     Move movesSearched[MAX_MOVES];
     StateInfo st;
@@ -544,7 +544,7 @@ namespace {
     bool isPvMove, inCheck, singularExtensionNode, givesCheck;
     bool captureOrPromotion, dangerous, doFullDepthSearch;
     int moveCount = 0, playedMoveCount = 0;
     bool isPvMove, inCheck, singularExtensionNode, givesCheck;
     bool captureOrPromotion, dangerous, doFullDepthSearch;
     int moveCount = 0, playedMoveCount = 0;
-    Thread& thread = Threads[pos.thread()];
+    Thread& thread = Threads[pos.this_thread()];
     SplitPoint* sp = NULL;
 
     refinedValue = bestValue = value = -VALUE_INFINITE;
     SplitPoint* sp = NULL;
 
     refinedValue = bestValue = value = -VALUE_INFINITE;
@@ -670,7 +670,7 @@ namespace {
         &&  refinedValue + razor_margin(depth) < beta
         &&  ttMove == MOVE_NONE
         &&  abs(beta) < VALUE_MATE_IN_MAX_PLY
         &&  refinedValue + razor_margin(depth) < beta
         &&  ttMove == MOVE_NONE
         &&  abs(beta) < VALUE_MATE_IN_MAX_PLY
-        && !pos.has_pawn_on_7th(pos.side_to_move()))
+        && !pos.pawn_on_7th(pos.side_to_move()))
     {
         Value rbeta = beta - razor_margin(depth);
         Value v = qsearch<NonPV>(pos, ss, rbeta-1, rbeta, DEPTH_ZERO);
     {
         Value rbeta = beta - razor_margin(depth);
         Value v = qsearch<NonPV>(pos, ss, rbeta-1, rbeta, DEPTH_ZERO);
@@ -847,7 +847,7 @@ split_point_start: // At split points actual search starts from here
       {
           Signals.firstRootMove = (moveCount == 1);
 
       {
           Signals.firstRootMove = (moveCount == 1);
 
-          if (pos.thread() == 0 && SearchTime.elapsed() > 2000)
+          if (pos.this_thread() == 0 && SearchTime.elapsed() > 2000)
               cout << "info depth " << depth / ONE_PLY
                    << " currmove " << move_to_uci(move, Chess960)
                    << " currmovenumber " << moveCount + PVIdx << endl;
               cout << "info depth " << depth / ONE_PLY
                    << " currmove " << move_to_uci(move, Chess960)
                    << " currmovenumber " << moveCount + PVIdx << endl;
@@ -1054,7 +1054,7 @@ split_point_start: // At split points actual search starts from here
       if (   !SpNode
           && depth >= Threads.min_split_depth()
           && bestValue < beta
       if (   !SpNode
           && depth >= Threads.min_split_depth()
           && bestValue < beta
-          && Threads.available_slave_exists(pos.thread())
+          && Threads.available_slave_exists(pos.this_thread())
           && !Signals.stop
           && !thread.cutoff_occurred())
           bestValue = Threads.split<FakeSplit>(pos, ss, alpha, beta, bestValue, &bestMove,
           && !Signals.stop
           && !thread.cutoff_occurred())
           bestValue = Threads.split<FakeSplit>(pos, ss, alpha, beta, bestValue, &bestMove,
@@ -1131,7 +1131,7 @@ split_point_start: // At split points actual search starts from here
     assert(alpha >= -VALUE_INFINITE && alpha < beta && beta <= VALUE_INFINITE);
     assert((alpha == beta - 1) || PvNode);
     assert(depth <= DEPTH_ZERO);
     assert(alpha >= -VALUE_INFINITE && alpha < beta && beta <= VALUE_INFINITE);
     assert((alpha == beta - 1) || PvNode);
     assert(depth <= DEPTH_ZERO);
-    assert(pos.thread() >= 0 && pos.thread() < Threads.size());
+    assert(pos.this_thread() >= 0 && pos.this_thread() < Threads.size());
 
     StateInfo st;
     Move ttMove, move, bestMove;
 
     StateInfo st;
     Move ttMove, move, bestMove;
index 8d66988029dd2ebc98a8e882e7eed10da0df0f0e..4ae268eb77b9ae885554bf4e60c78ef1e2ebf032 100644 (file)
@@ -309,7 +309,7 @@ Value ThreadsManager::split(Position& pos, Stack* ss, Value alpha, Value beta,
   assert(beta <= VALUE_INFINITE);
   assert(depth > DEPTH_ZERO);
 
   assert(beta <= VALUE_INFINITE);
   assert(depth > DEPTH_ZERO);
 
-  int master = pos.thread();
+  int master = pos.this_thread();
   Thread& masterThread = *threads[master];
 
   if (masterThread.splitPointsCnt >= MAX_SPLITPOINTS_PER_THREAD)
   Thread& masterThread = *threads[master];
 
   if (masterThread.splitPointsCnt >= MAX_SPLITPOINTS_PER_THREAD)
index a10920a9714ab381a4a2d4b94fbdf51140b627b8..4c3faf05c02c07999017594728c1249213dd4b2d 100644 (file)
@@ -113,7 +113,7 @@ void uci_loop(const string& args) {
           pos.print();
 
       else if (token == "flip")
           pos.print();
 
       else if (token == "flip")
-          pos.flip_me();
+          pos.flip();
 
       else if (token == "eval")
           cout << Eval::trace(pos) << endl;
 
       else if (token == "eval")
           cout << Eval::trace(pos) << endl;