From 74160ac60266f9e6824a5a6417d8a0ac8c0b39cf Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Wed, 18 Mar 2009 15:36:03 +0100 Subject: [PATCH] Big headers cleanup No functional change. Signed-off-by: Marco Costalba --- src/bitboard.cpp | 59 +----------------------------------------------- src/bitboard.h | 59 ++++++++++++++++++++++++++++++++++++++++-------- src/color.h | 6 ----- src/direction.h | 10 ++++---- src/evaluate.h | 17 +++++++------- src/lock.h | 2 +- src/main.cpp | 3 +-- src/move.cpp | 2 +- src/movegen.h | 12 +++++----- src/movepick.h | 1 - src/pawns.cpp | 1 + src/pawns.h | 21 +++++++++-------- src/phase.h | 34 ---------------------------- src/piece.h | 36 ++--------------------------- src/position.h | 9 ++++++-- src/psqtab.h | 1 - src/timeoday.cpp | 18 +++++++-------- 17 files changed, 105 insertions(+), 186 deletions(-) delete mode 100644 src/phase.h diff --git a/src/bitboard.cpp b/src/bitboard.cpp index 89b54321..3621d6b2 100644 --- a/src/bitboard.cpp +++ b/src/bitboard.cpp @@ -38,64 +38,6 @@ #include "direction.h" -//// -//// Constants and variables -//// - -const Bitboard SquaresByColorBB[2] = {BlackSquaresBB, WhiteSquaresBB}; - -const Bitboard FileBB[8] = { - FileABB, FileBBB, FileCBB, FileDBB, FileEBB, FileFBB, FileGBB, FileHBB -}; - -const Bitboard NeighboringFilesBB[8] = { - FileBBB, FileABB|FileCBB, FileBBB|FileDBB, FileCBB|FileEBB, - FileDBB|FileFBB, FileEBB|FileGBB, FileFBB|FileHBB, FileGBB -}; - -const Bitboard ThisAndNeighboringFilesBB[8] = { - FileABB|FileBBB, FileABB|FileBBB|FileCBB, - FileBBB|FileCBB|FileDBB, FileCBB|FileDBB|FileEBB, - FileDBB|FileEBB|FileFBB, FileEBB|FileFBB|FileGBB, - FileFBB|FileGBB|FileHBB, FileGBB|FileHBB -}; - -const Bitboard RankBB[8] = { - Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB -}; - -const Bitboard RelativeRankBB[2][8] = { - { - Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB - }, - { - Rank8BB, Rank7BB, Rank6BB, Rank5BB, Rank4BB, Rank3BB, Rank2BB, Rank1BB - } -}; - -const Bitboard InFrontBB[2][8] = { - { - Rank2BB | Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB, - Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB, - Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB, - Rank5BB | Rank6BB | Rank7BB | Rank8BB, - Rank6BB | Rank7BB | Rank8BB, - Rank7BB | Rank8BB, - Rank8BB, - EmptyBoardBB - }, - { - EmptyBoardBB, - Rank1BB, - Rank2BB | Rank1BB, - Rank3BB | Rank2BB | Rank1BB, - Rank4BB | Rank3BB | Rank2BB | Rank1BB, - Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB, - Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB, - Rank7BB | Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB - } -}; - #if defined(USE_COMPACT_ROOK_ATTACKS) Bitboard RankAttacks[8][64], FileAttacks[8][64]; @@ -270,6 +212,7 @@ Bitboard QueenPseudoAttacks[64]; //// namespace { + void init_masks(); void init_ray_bitboards(); void init_attacks(); diff --git a/src/bitboard.h b/src/bitboard.h index 1aefd8ad..d1cf40f2 100644 --- a/src/bitboard.h +++ b/src/bitboard.h @@ -84,8 +84,7 @@ const Bitboard EmptyBoardBB = 0ULL; const Bitboard WhiteSquaresBB = 0x55AA55AA55AA55AAULL; const Bitboard BlackSquaresBB = 0xAA55AA55AA55AA55ULL; - -extern const Bitboard SquaresByColorBB[2]; +const Bitboard SquaresByColorBB[2] = { BlackSquaresBB, WhiteSquaresBB }; const Bitboard FileABB = 0x0101010101010101ULL; const Bitboard FileBBB = 0x0202020202020202ULL; @@ -96,9 +95,21 @@ const Bitboard FileFBB = 0x2020202020202020ULL; const Bitboard FileGBB = 0x4040404040404040ULL; const Bitboard FileHBB = 0x8080808080808080ULL; -extern const Bitboard FileBB[8]; -extern const Bitboard NeighboringFilesBB[8]; -extern const Bitboard ThisAndNeighboringFilesBB[8]; +const Bitboard FileBB[8] = { + FileABB, FileBBB, FileCBB, FileDBB, FileEBB, FileFBB, FileGBB, FileHBB +}; + +const Bitboard NeighboringFilesBB[8] = { + FileBBB, FileABB|FileCBB, FileBBB|FileDBB, FileCBB|FileEBB, + FileDBB|FileFBB, FileEBB|FileGBB, FileFBB|FileHBB, FileGBB +}; + +const Bitboard ThisAndNeighboringFilesBB[8] = { + FileABB|FileBBB, FileABB|FileBBB|FileCBB, + FileBBB|FileCBB|FileDBB, FileCBB|FileDBB|FileEBB, + FileDBB|FileEBB|FileFBB, FileEBB|FileFBB|FileGBB, + FileFBB|FileGBB|FileHBB, FileGBB|FileHBB +}; const Bitboard Rank1BB = 0xFFULL; const Bitboard Rank2BB = 0xFF00ULL; @@ -109,9 +120,35 @@ const Bitboard Rank6BB = 0xFF0000000000ULL; const Bitboard Rank7BB = 0xFF000000000000ULL; const Bitboard Rank8BB = 0xFF00000000000000ULL; -extern const Bitboard RankBB[8]; -extern const Bitboard RelativeRankBB[2][8]; -extern const Bitboard InFrontBB[2][8]; +const Bitboard RankBB[8] = { + Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB +}; + +const Bitboard RelativeRankBB[2][8] = { + { Rank1BB, Rank2BB, Rank3BB, Rank4BB, Rank5BB, Rank6BB, Rank7BB, Rank8BB }, + { Rank8BB, Rank7BB, Rank6BB, Rank5BB, Rank4BB, Rank3BB, Rank2BB, Rank1BB } +}; + +const Bitboard InFrontBB[2][8] = { + { Rank2BB | Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB, + Rank3BB | Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB, + Rank4BB | Rank5BB | Rank6BB | Rank7BB | Rank8BB, + Rank5BB | Rank6BB | Rank7BB | Rank8BB, + Rank6BB | Rank7BB | Rank8BB, + Rank7BB | Rank8BB, + Rank8BB, + EmptyBoardBB + }, + { EmptyBoardBB, + Rank1BB, + Rank2BB | Rank1BB, + Rank3BB | Rank2BB | Rank1BB, + Rank4BB | Rank3BB | Rank2BB | Rank1BB, + Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB, + Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB, + Rank7BB | Rank6BB | Rank5BB | Rank4BB | Rank3BB | Rank2BB | Rank1BB + } +}; extern Bitboard SetMaskBB[65]; extern Bitboard ClearMaskBB[65]; @@ -124,13 +161,17 @@ extern Bitboard PassedPawnMask[2][64]; extern Bitboard OutpostMask[2][64]; #if defined(USE_COMPACT_ROOK_ATTACKS) + extern Bitboard RankAttacks[8][64], FileAttacks[8][64]; + #else + extern const uint64_t RMult[64]; extern const int RShift[64]; extern Bitboard RMask[64]; extern int RAttackIndex[64]; extern Bitboard RAttacks[0x19000]; + #endif // defined(USE_COMPACT_ROOK_ATTACKS) extern const uint64_t BMult[64]; @@ -212,7 +253,7 @@ inline Bitboard this_and_neighboring_files_bb(Square s) { /// relative_rank_bb() takes a color and a rank as input, and returns a bitboard /// representing all squares on the given rank from the given color's point of -/// view. For instance, relative_rank_bb(WHITE, 7) gives all squares on the +/// view. For instance, relative_rank_bb(WHITE, 7) gives all squares on the /// 7th rank, while relative_rank_bb(BLACK, 7) gives all squares on the 2nd /// rank. diff --git a/src/color.h b/src/color.h index 81ba55c1..872c7b79 100644 --- a/src/color.h +++ b/src/color.h @@ -21,12 +21,6 @@ #if !defined(COLOR_H_INCLUDED) #define COLOR_H_INCLUDED -//// -//// Includes -//// - -#include "misc.h" - //// //// Types diff --git a/src/direction.h b/src/direction.h index 988128e3..4ca264a0 100644 --- a/src/direction.h +++ b/src/direction.h @@ -38,8 +38,8 @@ enum Direction { }; enum SignedDirection { - SIGNED_DIR_E = 0, SIGNED_DIR_W = 1, - SIGNED_DIR_N = 2, SIGNED_DIR_S = 3, + SIGNED_DIR_E = 0, SIGNED_DIR_W = 1, + SIGNED_DIR_N = 2, SIGNED_DIR_S = 3, SIGNED_DIR_NE = 4, SIGNED_DIR_SW = 5, SIGNED_DIR_NW = 6, SIGNED_DIR_SE = 7, SIGNED_DIR_NONE = 8 @@ -58,9 +58,11 @@ extern uint8_t SignedDirectionTable[64][64]; //// Inline functions //// -inline void operator++ (Direction &d, int) { d = Direction(int(d) + 1); } +inline void operator++ (Direction& d, int) { + d = Direction(int(d) + 1); +} -inline void operator++ (SignedDirection &d, int) { +inline void operator++ (SignedDirection& d, int) { d = SignedDirection(int(d) + 1); } diff --git a/src/evaluate.h b/src/evaluate.h index b95aa15d..fd0c2780 100644 --- a/src/evaluate.h +++ b/src/evaluate.h @@ -27,29 +27,30 @@ #include "material.h" #include "pawns.h" -#include "position.h" //// //// Types //// + /// The EvalInfo struct contains various information computed and collected -/// by the evaluation function. An EvalInfo object is passed as one of the +/// by the evaluation function. An EvalInfo object is passed as one of the /// arguments to the evaluation function, and the search can make use of its /// contents to make intelligent search decisions. /// /// At the moment, this is not utilized very much: The only part of the /// EvalInfo object which is used by the search is futilityMargin. +class Position; struct EvalInfo { - // Middle game and endgame evaluations: + // Middle game and endgame evaluations Value mgValue, egValue; - // Pointers to material and pawn hash table entries: - MaterialInfo *mi; - PawnInfo *pi; + // Pointers to material and pawn hash table entries + MaterialInfo* mi; + PawnInfo* pi; // attackedBy[color][piece type] is a bitboard representing all squares // attacked by a given color and piece type. attackedBy[color][0] contains @@ -100,8 +101,8 @@ struct EvalInfo { //// Prototypes //// -extern Value evaluate(const Position &pos, EvalInfo &ei, int threadID); -extern Value quick_evaluate(const Position &pos); +extern Value evaluate(const Position& pos, EvalInfo& ei, int threadID); +extern Value quick_evaluate(const Position& pos); extern void init_eval(int threads); extern void quit_eval(); extern void read_weights(Color sideToMove); diff --git a/src/lock.h b/src/lock.h index b34957df..d813397e 100644 --- a/src/lock.h +++ b/src/lock.h @@ -87,7 +87,7 @@ typedef pthread_mutex_t Lock; #else -# include +#include typedef CRITICAL_SECTION Lock; # define lock_init(x, y) InitializeCriticalSection(x) diff --git a/src/main.cpp b/src/main.cpp index e01599db..ac466597 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,7 +52,6 @@ int main(int argc, char *argv[]) { std::cin.rdbuf()->pubsetbuf(NULL, 0); // Initialization - init_mersenne(); init_direction_table(); init_bitboards(); @@ -73,7 +72,7 @@ int main(int argc, char *argv[]) { { if (argc < 4 || argc > 7) { - std::cout << "Usage: glaurung bench " + std::cout << "Usage: stockfish bench " << "[time = 60s] [fen positions file = default] " << "[time, depth or node limited = time]" << std::endl; diff --git a/src/move.cpp b/src/move.cpp index ad282dfb..3935eb34 100644 --- a/src/move.cpp +++ b/src/move.cpp @@ -139,7 +139,7 @@ const std::string move_to_string(Move move) { /// Overload the << operator, to make it easier to print moves. -std::ostream &operator << (std::ostream &os, Move m) { +std::ostream &operator << (std::ostream& os, Move m) { return os << move_to_string(m); } diff --git a/src/movegen.h b/src/movegen.h index 48e0dec0..18715683 100644 --- a/src/movegen.h +++ b/src/movegen.h @@ -32,12 +32,12 @@ //// Prototypes //// -extern int generate_captures(const Position &pos, MoveStack *mlist); -extern int generate_noncaptures(const Position &pos, MoveStack *mlist); -extern int generate_checks(const Position &pos, MoveStack *mlist, Bitboard dc); -extern int generate_evasions(const Position &pos, MoveStack *mlist, Bitboard pinned); -extern int generate_legal_moves(const Position &pos, MoveStack *mlist); -extern bool move_is_legal(const Position &pos, const Move m, Bitboard pinned); +extern int generate_captures(const Position& pos, MoveStack* mlist); +extern int generate_noncaptures(const Position& pos, MoveStack* mlist); +extern int generate_checks(const Position& pos, MoveStack* mlist, Bitboard dc); +extern int generate_evasions(const Position& pos, MoveStack* mlist, Bitboard pinned); +extern int generate_legal_moves(const Position& pos, MoveStack* mlist); +extern bool move_is_legal(const Position& pos, const Move m, Bitboard pinned); #endif // !defined(MOVEGEN_H_INCLUDED) diff --git a/src/movepick.h b/src/movepick.h index 2c861c71..135b3555 100644 --- a/src/movepick.h +++ b/src/movepick.h @@ -105,7 +105,6 @@ private: /// a single reply to check. inline int MovePicker::number_of_moves() const { - return numOfMoves; } diff --git a/src/pawns.cpp b/src/pawns.cpp index 0aacec00..8dfb75a9 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -26,6 +26,7 @@ #include #include "pawns.h" +#include "position.h" //// diff --git a/src/pawns.h b/src/pawns.h index 4b61d80e..bd6b54ab 100644 --- a/src/pawns.h +++ b/src/pawns.h @@ -25,8 +25,8 @@ //// Includes //// -#include "position.h" - +#include "bitboard.h" +#include "value.h" //// //// Types @@ -38,6 +38,7 @@ /// to add further information in the future. A lookup to the pawn hash table /// (performed by calling the get_pawn_info method in a PawnInfoTable object) /// returns a pointer to a PawnInfo object. +class Position; class PawnInfo { @@ -49,9 +50,9 @@ public: Value kingside_storm_value(Color c) const; Value queenside_storm_value(Color c) const; Bitboard passed_pawns() const; - bool file_is_half_open(Color c, File f) const; - bool has_open_file_to_left(Color c, File f) const; - bool has_open_file_to_right(Color c, File f) const; + int file_is_half_open(Color c, File f) const; + int has_open_file_to_left(Color c, File f) const; + int has_open_file_to_right(Color c, File f) const; private: void clear(); @@ -75,11 +76,11 @@ public: PawnInfoTable(unsigned numOfEntries); ~PawnInfoTable(); void clear(); - PawnInfo *get_pawn_info(const Position &pos); + PawnInfo* get_pawn_info(const Position& pos); private: unsigned size; - PawnInfo *entries; + PawnInfo* entries; }; @@ -107,15 +108,15 @@ inline Value PawnInfo::queenside_storm_value(Color c) const { return Value(qsStormValue[c]); } -inline bool PawnInfo::file_is_half_open(Color c, File f) const { +inline int PawnInfo::file_is_half_open(Color c, File f) const { return (halfOpenFiles[c] & (1 << int(f))); } -inline bool PawnInfo::has_open_file_to_left(Color c, File f) const { +inline int PawnInfo::has_open_file_to_left(Color c, File f) const { return halfOpenFiles[c] & ((1 << int(f)) - 1); } -inline bool PawnInfo::has_open_file_to_right(Color c, File f) const { +inline int PawnInfo::has_open_file_to_right(Color c, File f) const { return halfOpenFiles[c] & ~((1 << int(f+1)) - 1); } diff --git a/src/phase.h b/src/phase.h deleted file mode 100644 index 29981bee..00000000 --- a/src/phase.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Stockfish, a UCI chess playing engine derived from Glaurung 2.1 - Copyright (C) 2004-2008 Tord Romstad (Glaurung author) - Copyright (C) 2008 Marco Costalba - - Stockfish is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Stockfish is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - - -#if !defined(PHASE_H_INCLUDED) -#define PHASE_H_INCLUDED - -//// -//// Types -//// - -enum Phase { - PHASE_ENDGAME = 0, - PHASE_MIDGAME = 128 -}; - - -#endif // !defined(PHASE_H_INCLUDED) diff --git a/src/piece.h b/src/piece.h index be75a433..cf23c028 100644 --- a/src/piece.h +++ b/src/piece.h @@ -26,7 +26,6 @@ //// #include "color.h" -#include "misc.h" #include "square.h" @@ -50,41 +49,10 @@ enum Piece { //// Constants //// -const PieceType PieceTypeMin = PAWN; -const PieceType PieceTypeMax = KING; - const int SlidingArray[18] = { 0, 0, 0, 1, 2, 3, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0 }; -const SquareDelta Directions[16][16] = { - {DELTA_ZERO}, - {DELTA_NW, DELTA_NE, DELTA_ZERO}, - {DELTA_SSW, DELTA_SSE, DELTA_SWW, DELTA_SEE, - DELTA_NWW, DELTA_NEE, DELTA_NNW, DELTA_NNE, DELTA_ZERO}, - {DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO}, - {DELTA_S, DELTA_E, DELTA_W, DELTA_N, DELTA_ZERO}, - {DELTA_S, DELTA_E, DELTA_W, DELTA_N, - DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO}, - {DELTA_S, DELTA_E, DELTA_W, DELTA_N, - DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO}, - {DELTA_ZERO}, - {DELTA_ZERO}, - {DELTA_SW, DELTA_SE, DELTA_ZERO}, - {DELTA_SSW, DELTA_SSE, DELTA_SWW, DELTA_SEE, - DELTA_NWW, DELTA_NEE, DELTA_NNW, DELTA_NNE, DELTA_ZERO}, - {DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO}, - {DELTA_S, DELTA_E, DELTA_W, DELTA_N, DELTA_ZERO}, - {DELTA_S, DELTA_E, DELTA_W, DELTA_N, - DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO}, - {DELTA_S, DELTA_E, DELTA_W, DELTA_N, - DELTA_SE, DELTA_SW, DELTA_NE, DELTA_NW, DELTA_ZERO}, -}; - -const SquareDelta PawnPush[2] = { - DELTA_N, DELTA_S -}; - //// //// Inline functions @@ -115,12 +83,12 @@ inline int piece_is_slider(Piece p) { return SlidingArray[int(p)]; } -inline int piece_type_is_slider(PieceType pt) { +inline int piece_is_slider(PieceType pt) { return SlidingArray[int(pt)]; } inline SquareDelta pawn_push(Color c) { - return PawnPush[c]; + return (c == WHITE ? DELTA_N : DELTA_S); } inline bool piece_type_is_ok(PieceType pc) { diff --git a/src/position.h b/src/position.h index 510784e5..e5b5f5aa 100644 --- a/src/position.h +++ b/src/position.h @@ -38,7 +38,6 @@ #include "direction.h" #include "move.h" #include "piece.h" -#include "phase.h" #include "square.h" #include "value.h" @@ -61,7 +60,7 @@ const int MaxGameLength = 220; //// Types //// -/// Castle rights, encoded as bit fields: +/// Castle rights, encoded as bit fields enum CastleRights { NO_CASTLES = 0, @@ -72,6 +71,12 @@ enum CastleRights { ALL_CASTLES = 15 }; +/// Game phase +enum Phase { + PHASE_ENDGAME = 0, + PHASE_MIDGAME = 128 +}; + /// The StateInfo struct stores information we need to restore a Position /// object to its previous state when we retract a move. Whenever a move diff --git a/src/psqtab.h b/src/psqtab.h index 67776194..15146357 100644 --- a/src/psqtab.h +++ b/src/psqtab.h @@ -25,7 +25,6 @@ //// Includes //// -#include "position.h" #include "value.h" diff --git a/src/timeoday.cpp b/src/timeoday.cpp index 1078af30..ed1a2a90 100644 --- a/src/timeoday.cpp +++ b/src/timeoday.cpp @@ -2,21 +2,21 @@ (c) Copyright 1992 Eric Backus This software may be used freely so long as this copyright notice is - left intact. There is no warrantee on this software. - */ + left intact. There is no warrantee on this software. +*/ + #include #include #include "dos.h" - -int gettimeofday(struct timeval * tp, struct timezone * tzp) +int gettimeofday(struct timeval* tp, struct timezone* tzp) { - SYSTEMTIME systime; - - if (tp) { - struct tm tmrec; - time_t theTime = time(NULL); + SYSTEMTIME systime; + if (tp) + { + struct tm tmrec; + time_t theTime = time(NULL); tmrec = *localtime(&theTime); tp->tv_sec = mktime(&tmrec); -- 2.39.2