mirror of
https://github.com/sockspls/badfish
synced 2025-07-11 11:39:15 +00:00
Use st->gamePly to store fullMoves
This allow to retire do_setup_move() and also to simplify draw detection logic becuase now we always have: Min(st->rule50, st->gamePly) = st->rule50 This was already true when starting from starting position, but now is true even when starting from a FEN string because now we take in account fullmove number in counting gamePly so that it is always. st->rule50 <= st->gamePly No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
3d8140a541
commit
3185c36a65
4 changed files with 13 additions and 29 deletions
|
@ -190,7 +190,11 @@ void Position::from_fen(const string& fenStr, bool isChess960) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5-6. Halfmove clock and fullmove number
|
// 5-6. Halfmove clock and fullmove number
|
||||||
fen >> std::skipws >> st->rule50 >> fullMoves;
|
fen >> std::skipws >> st->rule50 >> st->gamePly;
|
||||||
|
|
||||||
|
// Convert from fullmove starting from 1 to ply starting from 0,
|
||||||
|
// handle also common incorrect FEN with fullmove = 0.
|
||||||
|
st->gamePly = Max(2 * (st->gamePly - 1), 0) + int(sideToMove == BLACK);
|
||||||
|
|
||||||
// Various initialisations
|
// Various initialisations
|
||||||
chess960 = isChess960;
|
chess960 = isChess960;
|
||||||
|
@ -310,7 +314,7 @@ const string Position::to_fen() const {
|
||||||
fen << '-';
|
fen << '-';
|
||||||
|
|
||||||
fen << (ep_square() == SQ_NONE ? " -" : " " + square_to_string(ep_square()))
|
fen << (ep_square() == SQ_NONE ? " -" : " " + square_to_string(ep_square()))
|
||||||
<< " " << st->rule50 << " " << fullMoves;
|
<< " " << st->rule50 << " " << 1 + (st->gamePly - int(sideToMove == BLACK)) / 2;
|
||||||
|
|
||||||
return fen.str();
|
return fen.str();
|
||||||
}
|
}
|
||||||
|
@ -759,23 +763,6 @@ bool Position::move_gives_check(Move m, const CheckInfo& ci) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Position::do_setup_move() makes a permanent move on the board. It should
|
|
||||||
/// be used when setting up a position on board. You can't undo the move.
|
|
||||||
|
|
||||||
void Position::do_setup_move(Move m, StateInfo& newSt) {
|
|
||||||
|
|
||||||
assert(move_is_ok(m));
|
|
||||||
|
|
||||||
// Update the number of full moves after black's move
|
|
||||||
if (sideToMove == BLACK)
|
|
||||||
fullMoves++;
|
|
||||||
|
|
||||||
do_move(m, newSt);
|
|
||||||
|
|
||||||
assert(is_ok());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Position::do_move() makes a move, and saves all information necessary
|
/// Position::do_move() makes a move, and saves all information necessary
|
||||||
/// to a StateInfo object. The move is assumed to be legal. Pseudo-legal
|
/// to a StateInfo object. The move is assumed to be legal. Pseudo-legal
|
||||||
/// moves should be filtered out before this function is called.
|
/// moves should be filtered out before this function is called.
|
||||||
|
@ -1528,7 +1515,6 @@ void Position::clear() {
|
||||||
castleRightsMask[sq] = ALL_CASTLES;
|
castleRightsMask[sq] = ALL_CASTLES;
|
||||||
}
|
}
|
||||||
sideToMove = WHITE;
|
sideToMove = WHITE;
|
||||||
fullMoves = 1;
|
|
||||||
nodes = 0;
|
nodes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1670,7 +1656,7 @@ bool Position::is_draw() const {
|
||||||
// Draw by repetition?
|
// Draw by repetition?
|
||||||
if (!SkipRepetition)
|
if (!SkipRepetition)
|
||||||
{
|
{
|
||||||
int i = 4, e = Min(Min(st->gamePly, st->rule50), st->pliesFromNull);
|
int i = 4, e = Min(st->rule50, st->pliesFromNull);
|
||||||
|
|
||||||
if (i <= e)
|
if (i <= e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -163,7 +163,6 @@ public:
|
||||||
bool pawn_is_passed(Color c, Square s) const;
|
bool pawn_is_passed(Color c, Square s) const;
|
||||||
|
|
||||||
// Doing and undoing moves
|
// Doing and undoing moves
|
||||||
void do_setup_move(Move m, StateInfo& st);
|
|
||||||
void do_move(Move m, StateInfo& st);
|
void do_move(Move m, StateInfo& st);
|
||||||
void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
|
void do_move(Move m, StateInfo& st, const CheckInfo& ci, bool moveIsCheck);
|
||||||
void undo_move(Move m);
|
void undo_move(Move m);
|
||||||
|
@ -190,7 +189,7 @@ public:
|
||||||
template<bool SkipRepetition> bool is_draw() const;
|
template<bool SkipRepetition> bool is_draw() const;
|
||||||
|
|
||||||
// Number of plies from starting position
|
// Number of plies from starting position
|
||||||
int startpos_ply_counter() const;
|
int game_ply() const;
|
||||||
|
|
||||||
// Other properties of the position
|
// Other properties of the position
|
||||||
bool opposite_colored_bishops() const;
|
bool opposite_colored_bishops() const;
|
||||||
|
@ -257,7 +256,6 @@ private:
|
||||||
StateInfo startState;
|
StateInfo startState;
|
||||||
int64_t nodes;
|
int64_t nodes;
|
||||||
Color sideToMove;
|
Color sideToMove;
|
||||||
int fullMoves;
|
|
||||||
int threadID;
|
int threadID;
|
||||||
StateInfo* st;
|
StateInfo* st;
|
||||||
int chess960;
|
int chess960;
|
||||||
|
@ -423,8 +421,8 @@ inline bool Position::move_is_passed_pawn_push(Move m) const {
|
||||||
&& pawn_is_passed(c, move_to(m));
|
&& pawn_is_passed(c, move_to(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::startpos_ply_counter() const {
|
inline int Position::game_ply() const {
|
||||||
return Max(2 * (fullMoves - 1), 0) + int(sideToMove == BLACK);
|
return st->gamePly;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool Position::opposite_colored_bishops() const {
|
inline bool Position::opposite_colored_bishops() const {
|
||||||
|
|
|
@ -393,7 +393,7 @@ bool think(Position& pos, const SearchLimits& limits, Move searchMoves[]) {
|
||||||
NodesSincePoll = 0;
|
NodesSincePoll = 0;
|
||||||
current_search_time(get_system_time());
|
current_search_time(get_system_time());
|
||||||
Limits = limits;
|
Limits = limits;
|
||||||
TimeMgr.init(Limits, pos.startpos_ply_counter());
|
TimeMgr.init(Limits, pos.game_ply());
|
||||||
|
|
||||||
// Set output steram in normal or chess960 mode
|
// Set output steram in normal or chess960 mode
|
||||||
cout << set960(pos.is_chess960());
|
cout << set960(pos.is_chess960());
|
||||||
|
|
|
@ -144,13 +144,13 @@ namespace {
|
||||||
}
|
}
|
||||||
else return;
|
else return;
|
||||||
|
|
||||||
// Parse move list (if any)
|
|
||||||
SetupState.clear();
|
SetupState.clear();
|
||||||
|
|
||||||
|
// Parse move list (if any)
|
||||||
while (up >> token && (m = move_from_uci(pos, token)) != MOVE_NONE)
|
while (up >> token && (m = move_from_uci(pos, token)) != MOVE_NONE)
|
||||||
{
|
{
|
||||||
SetupState.push_back(StateInfo());
|
SetupState.push_back(StateInfo());
|
||||||
pos.do_setup_move(m, SetupState.back());
|
pos.do_move(m, SetupState.back());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue