No functional change.
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
#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];
////
namespace {
+
void init_masks();
void init_ray_bitboards();
void init_attacks();
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;
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;
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];
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];
/// 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.
#if !defined(COLOR_H_INCLUDED)
#define COLOR_H_INCLUDED
-////
-//// Includes
-////
-
-#include "misc.h"
-
////
//// Types
};
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
//// 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);
}
#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
//// 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);
#else
-# include <windows.h>
+#include <windows.h>
typedef CRITICAL_SECTION Lock;
# define lock_init(x, y) InitializeCriticalSection(x)
std::cin.rdbuf()->pubsetbuf(NULL, 0);
// Initialization
-
init_mersenne();
init_direction_table();
init_bitboards();
{
if (argc < 4 || argc > 7)
{
- std::cout << "Usage: glaurung bench <hash size> <threads> "
+ std::cout << "Usage: stockfish bench <hash size> <threads> "
<< "[time = 60s] [fen positions file = default] "
<< "[time, depth or node limited = time]"
<< std::endl;
/// 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);
}
//// 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)
/// a single reply to check.
inline int MovePicker::number_of_moves() const {
-
return numOfMoves;
}
#include <cstring>
#include "pawns.h"
+#include "position.h"
////
//// Includes
////
-#include "position.h"
-
+#include "bitboard.h"
+#include "value.h"
////
//// Types
/// 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 {
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();
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;
};
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);
}
+++ /dev/null
-/*
- 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 <http://www.gnu.org/licenses/>.
-*/
-
-
-#if !defined(PHASE_H_INCLUDED)
-#define PHASE_H_INCLUDED
-
-////
-//// Types
-////
-
-enum Phase {
- PHASE_ENDGAME = 0,
- PHASE_MIDGAME = 128
-};
-
-
-#endif // !defined(PHASE_H_INCLUDED)
////
#include "color.h"
-#include "misc.h"
#include "square.h"
//// 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
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) {
#include "direction.h"
#include "move.h"
#include "piece.h"
-#include "phase.h"
#include "square.h"
#include "value.h"
//// Types
////
-/// Castle rights, encoded as bit fields:
+/// Castle rights, encoded as bit fields
enum CastleRights {
NO_CASTLES = 0,
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
//// Includes
////
-#include "position.h"
#include "value.h"
(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 <windows.h>
#include <time.h>
#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);