startState.epSquare = SQ_NONE;
st = &startState;
- for (int i = 0; i < 8; i++)
+ for (int i = 0; i < PIECE_TYPE_NB; i++)
for (int j = 0; j < 16; j++)
- pieceList[0][i][j] = pieceList[1][i][j] = SQ_NONE;
+ pieceList[WHITE][i][j] = pieceList[BLACK][i][j] = SQ_NONE;
}
/// 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_psq_score() const {
Score score = SCORE_ZERO;
if (st->rule50 > 99 && (!checkers() || MoveList<LEGAL>(*this).size()))
return true;
- // Draw by repetition?
int i = 4, e = std::min(st->rule50, st->pliesFromNull);
if (i <= e)
stp = stp->previous->previous;
if (stp->key == st->key)
- return true;
+ return true; // Draw after first repetition
i += 2;
/// is only useful for debugging especially for finding evaluation symmetry bugs.
static char toggle_case(char c) {
- return isupper(c) ? tolower(c) : toupper(c);
+ return char(islower(c) ? toupper(c) : tolower(c));
}
void Position::flip() {
string f, token;
std::stringstream ss(fen());
- for (int i = 0; i < 8; i++)
+ for (Rank rank = RANK_8; rank >= RANK_1; rank--) // Piece placement
{
- std::getline(ss, token, i < 7 ? '/' : ' ');
- std::transform(token.begin(), token.end(), token.begin(), toggle_case);
- f.insert(0, token + (i ? "/" : " "));
+ std::getline(ss, token, rank > RANK_1 ? '/' : ' ');
+ f.insert(0, token + (f.empty() ? " " : "/"));
}
- ss >> token; // Side to move
- f += (token == "w" ? "b " : "w ");
+ ss >> token; // Active color
+ f += (token == "w" ? "B " : "W "); // Will be lowercased later
- ss >> token; // Castling flags
- std::transform(token.begin(), token.end(), token.begin(), toggle_case);
+ ss >> token; // Castling availability
f += token + " ";
- ss >> token; // En-passant square
+ std::transform(f.begin(), f.end(), f.begin(), toggle_case);
+
+ ss >> token; // En passant square
f += (token == "-" ? token : token.replace(1, 1, token[1] == '3' ? "6" : "3"));
- std::getline(ss, token); // Full and half moves
+ std::getline(ss, token); // Half and full moves
f += token;
set(f, is_chess960(), this_thread());