From 057d710fc2f23b63b574122f2609e03f58d2e494 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sat, 17 Sep 2016 08:19:06 +0200 Subject: [PATCH] Fix indentation in struct FromToStats And other little trivial stuff. No functional change. --- src/evaluate.cpp | 10 +++++----- src/main.cpp | 4 ++++ src/movepick.cpp | 2 +- src/movepick.h | 30 ++++++++++++++---------------- src/position.cpp | 7 ++++++- src/position.h | 26 ++++++-------------------- src/search.cpp | 1 + src/search.h | 12 +++++++----- src/thread.h | 2 +- src/types.h | 9 ++++----- 10 files changed, 49 insertions(+), 54 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index dd86f35a..30958388 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -419,11 +419,11 @@ namespace { // attacked and undefended squares around our king and the quality of // the pawn shelter (current 'score' value). kingDanger = std::min(807, ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them]) - + 101 * ei.kingAdjacentZoneAttacksCount[Them] - + 235 * popcount(undefended) - + 134 * (popcount(b) + !!ei.pinnedPieces[Us]) - - 717 * !pos.count(Them) - - 7 * mg_value(score) / 5 - 5; + + 101 * ei.kingAdjacentZoneAttacksCount[Them] + + 235 * popcount(undefended) + + 134 * (popcount(b) + !!ei.pinnedPieces[Us]) + - 717 * !pos.count(Them) + - 7 * mg_value(score) / 5 - 5; // Analyse the enemy's safe queen contact checks. Firstly, find the // undefended squares around the king reachable by the enemy queen... diff --git a/src/main.cpp b/src/main.cpp index 736a3f7a..7187d30a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,6 +28,10 @@ #include "uci.h" #include "syzygy/tbprobe.h" +namespace PSQT { + void init(); +} + int main(int argc, char* argv[]) { std::cout << engine_info() << std::endl; diff --git a/src/movepick.cpp b/src/movepick.cpp index bbe1897e..ea587389 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -277,7 +277,7 @@ Move MovePicker::next_move() { case EVASIONS_INIT: cur = moves; endMoves = generate(pos, cur); - if (endMoves - cur > 1) + if (endMoves - cur - (ttMove != MOVE_NONE) > 1) score(); ++stage; diff --git a/src/movepick.h b/src/movepick.h index 36bf58f6..6fbd8be1 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -26,7 +26,6 @@ #include "movegen.h" #include "position.h" -#include "search.h" #include "types.h" @@ -45,9 +44,7 @@ struct Stats { const T* operator[](Piece pc) const { return table[pc]; } T* operator[](Piece pc) { return table[pc]; } void clear() { std::memset(table, 0, sizeof(table)); } - void update(Piece pc, Square to, Move m) { table[pc][to] = m; } - void update(Piece pc, Square to, Value v) { if (abs(int(v)) >= 324) @@ -68,31 +65,32 @@ typedef Stats CounterMoveHistoryStats; struct FromToStats { - Value get(Color c, Move m) const { return table[c][from_sq(m)][to_sq(m)]; } - void clear() { std::memset(table, 0, sizeof(table)); } + Value get(Color c, Move m) const { return table[c][from_sq(m)][to_sq(m)]; } + void clear() { std::memset(table, 0, sizeof(table)); } + void update(Color c, Move m, Value v) { - void update(Color c, Move m, Value v) - { - if (abs(int(v)) >= 324) - return; + if (abs(int(v)) >= 324) + return; - Square f = from_sq(m); - Square t = to_sq(m); + Square from = from_sq(m); + Square to = to_sq(m); - table[c][f][t] -= table[c][f][t] * abs(int(v)) / 324; - table[c][f][t] += int(v) * 32; - } + table[c][from][to] -= table[c][from][to] * abs(int(v)) / 324; + table[c][from][to] += int(v) * 32; + } private: - Value table[COLOR_NB][SQUARE_NB][SQUARE_NB]; + Value table[COLOR_NB][SQUARE_NB][SQUARE_NB]; }; + /// MovePicker class is used to pick one pseudo legal move at a time from the /// current position. The most important method is next_move(), which returns a /// new pseudo legal move each time it is called, until there are no moves left, /// when MOVE_NONE is returned. In order to improve the efficiency of the alpha /// beta algorithm, MovePicker attempts to return the moves which are most likely /// to get a cut-off first. +namespace Search { struct Stack; } class MovePicker { public: @@ -118,7 +116,7 @@ private: Square recaptureSquare; Value threshold; int stage; - ExtMove* cur, *endMoves, *endBadCaptures; + ExtMove *cur, *endMoves, *endBadCaptures; ExtMove moves[MAX_MOVES]; }; diff --git a/src/position.cpp b/src/position.cpp index 779c2640..c193f266 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -20,7 +20,8 @@ #include #include -#include // For std::memset, std::memcmp +#include // For offsetof() +#include // For std::memset, std::memcmp #include #include @@ -34,6 +35,10 @@ using std::string; +namespace PSQT { + extern Score psq[PIECE_NB][SQUARE_NB]; +} + namespace Zobrist { Key psq[PIECE_NB][SQUARE_NB]; diff --git a/src/position.h b/src/position.h index c322ab99..9830619e 100644 --- a/src/position.h +++ b/src/position.h @@ -22,25 +22,13 @@ #define POSITION_H_INCLUDED #include -#include // For offsetof() #include -#include // For std::unique_ptr +#include // For std::unique_ptr #include -#include #include "bitboard.h" #include "types.h" -class Position; -class Thread; - -namespace PSQT { - - extern Score psq[PIECE_NB][SQUARE_NB]; - - void init(); -} - /// StateInfo struct stores information needed to restore a Position object to /// its previous state when we retract a move. Whenever a move is made on the @@ -58,7 +46,7 @@ struct StateInfo { Score psq; Square epSquare; - // Not copied when making a move + // Not copied when making a move (will be recomputed anyhow) Key key; Bitboard checkersBB; Piece capturedPiece; @@ -76,9 +64,9 @@ typedef std::unique_ptr> StateListPtr; /// pieces, side to move, hash keys, castling info, etc. Important methods are /// do_move() and undo_move(), used by the search to update node info when /// traversing the search tree. +class Thread; class Position { - public: static void init(); @@ -144,7 +132,7 @@ public: void do_null_move(StateInfo& st); void undo_null_move(); - // Static exchange evaluation + // Static Exchange Evaluation Value see(Move m) const; Value see_sign(Move m) const; @@ -369,15 +357,13 @@ inline bool Position::is_chess960() const { } inline bool Position::capture_or_promotion(Move m) const { - assert(is_ok(m)); return type_of(m) != NORMAL ? type_of(m) != CASTLING : !empty(to_sq(m)); } inline bool Position::capture(Move m) const { - - // Castling is encoded as "king captures the rook" assert(is_ok(m)); + // Castling is encoded as "king captures rook" return (!empty(to_sq(m)) && type_of(m) != CASTLING) || type_of(m) == ENPASSANT; } @@ -405,7 +391,7 @@ inline void Position::remove_piece(Piece pc, Square s) { // WARNING: This is not a reversible operation. If we remove a piece in // do_move() and then replace it in undo_move() we will put it at the end of // the list and not in its original place, it means index[] and pieceList[] - // are not guaranteed to be invariant to a do_move() + undo_move() sequence. + // are not invariant to a do_move() + undo_move() sequence. byTypeBB[ALL_PIECES] ^= s; byTypeBB[type_of(pc)] ^= s; byColorBB[color_of(pc)] ^= s; diff --git a/src/search.cpp b/src/search.cpp index 9eac6d5f..695cd7c1 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -29,6 +29,7 @@ #include "misc.h" #include "movegen.h" #include "movepick.h" +#include "position.h" #include "search.h" #include "timeman.h" #include "thread.h" diff --git a/src/search.h b/src/search.h index 599d058f..121ab8d1 100644 --- a/src/search.h +++ b/src/search.h @@ -25,11 +25,10 @@ #include #include "misc.h" -#include "position.h" +#include "movepick.h" #include "types.h" -template struct Stats; -typedef Stats CounterMoveStats; +class Position; namespace Search { @@ -49,6 +48,7 @@ struct Stack { CounterMoveStats* counterMoves; }; + /// RootMove struct is used for moves at the root of the tree. For each root move /// we store a score and a PV (really a refutation in the case of moves which /// fail low). Score is normally set at -VALUE_INFINITE for all non-pv moves. @@ -68,6 +68,7 @@ struct RootMove { typedef std::vector RootMoves; + /// LimitsType struct stores information sent by GUI about available time to /// search the current move, maximum depth/time, if we are in analysis mode or /// if we have to ponder while it's our opponent's turn to move. @@ -89,8 +90,9 @@ struct LimitsType { TimePoint startTime; }; -/// The SignalsType struct stores atomic flags updated during the search -/// typically in an async fashion e.g. to stop the search by the GUI. + +/// SignalsType struct stores atomic flags updated during the search, typically +/// in an async fashion e.g. to stop the search by the GUI. struct SignalsType { std::atomic_bool stop, stopOnPonderhit; diff --git a/src/thread.h b/src/thread.h index 969fe635..195c3b3b 100644 --- a/src/thread.h +++ b/src/thread.h @@ -66,11 +66,11 @@ public: Position rootPos; Search::RootMoves rootMoves; Depth rootDepth; - FromToStats fromTo; Depth completedDepth; std::atomic_bool resetCalls; HistoryStats history; MoveStats counterMoves; + FromToStats fromTo; CounterMoveHistoryStats counterMoveHistory; }; diff --git a/src/types.h b/src/types.h index b1810fad..3aafb5c3 100644 --- a/src/types.h +++ b/src/types.h @@ -207,6 +207,7 @@ enum Piece { const Piece Pieces[] = { W_PAWN, W_KNIGHT, W_BISHOP, W_ROOK, W_QUEEN, W_KING, B_PAWN, B_KNIGHT, B_BISHOP, B_ROOK, B_QUEEN, B_KING }; +extern Value PieceValue[PHASE_NB][PIECE_NB]; enum Depth { @@ -329,8 +330,6 @@ inline Score operator/(Score s, int i) { return make_score(mg_value(s) / i, eg_value(s) / i); } -extern Value PieceValue[PHASE_NB][PIECE_NB]; - inline Color operator~(Color c) { return Color(c ^ BLACK); // Toggle color } @@ -356,7 +355,7 @@ inline Value mated_in(int ply) { } inline Square make_square(File f, Rank r) { - return Square((r << 3) | f); + return Square((r << 3) + f); } inline Piece make_piece(Color c, PieceType pt) { @@ -422,12 +421,12 @@ inline PieceType promotion_type(Move m) { } inline Move make_move(Square from, Square to) { - return Move(to | (from << 6)); + return Move((from << 6) + to); } template inline Move make(Square from, Square to, PieceType pt = KNIGHT) { - return Move(to | (from << 6) | T | ((pt - KNIGHT) << 12)); + return Move(T + ((pt - KNIGHT) << 12) + (from << 6) + to); } inline bool is_ok(Move m) { -- 2.39.2