position: 基本完成 set 函数

put_piece() 因接口还未适配完成故暂不调用。
This commit is contained in:
Calcitem 2020-09-19 23:05:41 +08:00
parent 1e29418e2c
commit e1f066bbfc
1 changed files with 36 additions and 15 deletions

View File

@ -138,6 +138,9 @@ inline int H2(Key h)
Key cuckoo[8192];
Move cuckooMove[8192];
/// Position::init() initializes at startup the various arrays used to compute
/// hash keys.
void Position::init()
{
PRNG rng(1070372);
@ -220,29 +223,37 @@ Position &Position::set(const string &fenStr, StateInfo *si, Thread *th)
ss >> std::noskipws;
// 1. Piece placement
// TODO
#if 0
while ((ss >> token) && !isspace(token)) {
if (token == '@')
sq += (token - '0') * EAST; // Advance the given number of files
else if (token == '/')
sq += 2 * SOUTH;
else if ((idx = PieceToChar.find(token)) != string::npos) {
put_piece(Piece(idx), sq);
++sq;
if (token == '@' || token == 'O' || token == 'X') {
// put_piece(Piece(idx), sq); // TODO
}
++sq;
}
#endif
// 2. Active color
ss >> token;
sideToMove = (token == 'w' ? WHITE : BLACK);
ss >> token;
sideToMove = (token == 'b' ? BLACK : WHITE);
// 3. Phrase
ss >> token;
switch (token) {
case 'r':
phase = PHASE_READY;
break;
case 'p':
phase = PHASE_PLACING;
break;
case 'm':
phase = PHASE_MOVING;
break;
case 'o':
phase = PHASE_GAMEOVER;
break;
default:
phase = PHASE_NONE;
}
// 4-5. Halfmove clock and fullmove number
ss >> std::skipws >> st->rule50 >> gamePly;
@ -254,7 +265,7 @@ Position &Position::set(const string &fenStr, StateInfo *si, Thread *th)
thisThread = th;
set_state(st);
//assert(pos_is_ok());
assert(pos_is_ok());
return *this;
}
@ -2033,3 +2044,13 @@ void Position::print_board()
"\n");
}
}
/// Position::pos_is_ok() performs some consistency checks for the
/// position object and raises an asserts if something wrong is detected.
/// This is meant to be helpful when debugging.
bool Position::pos_is_ok() const
{
// TODO
return true;
}