position: 实现 Position::set() 部分代码
This commit is contained in:
parent
79019ddb74
commit
5182518257
|
@ -183,53 +183,48 @@ Position::~Position()
|
||||||
|
|
||||||
Position &Position::set(const string &fenStr, StateInfo *si, Thread *th)
|
Position &Position::set(const string &fenStr, StateInfo *si, Thread *th)
|
||||||
{
|
{
|
||||||
// TODO
|
|
||||||
#if 0
|
|
||||||
/*
|
/*
|
||||||
A FEN string defines a particular position using only the ASCII character set.
|
A FEN string defines a particular position using only the ASCII character set.
|
||||||
|
|
||||||
A FEN string contains six fields separated by a space. The fields are:
|
A FEN string contains six fields separated by a space. The fields are:
|
||||||
|
|
||||||
1) Piece placement (from white's perspective). Each rank is described, starting
|
1) Piece placement. Each rank is described, starting
|
||||||
with rank 8 and ending with rank 1. Within each rank, the contents of each
|
with rank 1 and ending with rank 8. Within each rank, the contents of each
|
||||||
square are described from file A through file H. Following the Standard
|
square are described from file A through file C. Following the Standard
|
||||||
Algebraic Notation (SAN), each piece is identified by a single letter taken
|
Algebraic Notation (SAN), each piece is identified by a single letter taken
|
||||||
from the standard English names. White pieces are designated using upper-case
|
from the standard English names. White pieces are designated using "O"
|
||||||
letters ("PNBRQK") whilst Black uses lowercase ("pnbrqk"). Blank squares are
|
whilst Black uses "@". Blank uses "*". Banned uses "X".
|
||||||
noted using digits 1 through 8 (the number of blank squares), and "/"
|
noted using digits 1 through 8 (the number of blank squares), and "/"
|
||||||
separates ranks.
|
separates ranks.
|
||||||
|
|
||||||
2) Active color. "w" means white moves next, "b" means black.
|
2) Active color. "w" means white moves next, "b" means black.
|
||||||
|
|
||||||
4) En passant target square (in algebraic notation). If there's no en passant
|
3) Phrase.
|
||||||
target square, this is "-". If a pawn has just made a 2-square move, this
|
|
||||||
is the position "behind" the pawn. This is recorded only if there is a pawn
|
|
||||||
in position to make an en passant capture, and if there really is a pawn
|
|
||||||
that might have advanced two squares.
|
|
||||||
|
|
||||||
5) Halfmove clock. This is the number of halfmoves since the last pawn advance
|
4) Halfmove clock. This is the number of halfmoves since the last
|
||||||
or capture. This is used to determine if a draw can be claimed under the
|
capture. This is used to determine if a draw can be claimed under the
|
||||||
fifty-move rule.
|
fifty-move rule.
|
||||||
|
|
||||||
6) Fullmove number. The number of the full move. It starts at 1, and is
|
5) Fullmove number. The number of the full move. It starts at 1, and is
|
||||||
incremented after Black's move.
|
incremented after Black's move.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned char token;
|
unsigned char token;
|
||||||
size_t idx;
|
size_t idx;
|
||||||
Square sq = SQ_A8;
|
Square sq = SQ_A1;
|
||||||
std::istringstream ss(fenStr);
|
std::istringstream ss(fenStr);
|
||||||
|
|
||||||
std::memset(this, 0, sizeof(Position));
|
std::memset(this, 0, sizeof(Position));
|
||||||
std::memset(si, 0, sizeof(StateInfo));
|
std::memset(si, 0, sizeof(StateInfo));
|
||||||
std::fill_n(&pieceList[0][0], sizeof(pieceList) / sizeof(Square), SQ_NONE);
|
|
||||||
st = si;
|
st = si;
|
||||||
|
|
||||||
ss >> std::noskipws;
|
ss >> std::noskipws;
|
||||||
|
|
||||||
// 1. Piece placement
|
// 1. Piece placement
|
||||||
|
// TODO
|
||||||
|
#if 0
|
||||||
while ((ss >> token) && !isspace(token)) {
|
while ((ss >> token) && !isspace(token)) {
|
||||||
if (isdigit(token))
|
if (token == '@')
|
||||||
sq += (token - '0') * EAST; // Advance the given number of files
|
sq += (token - '0') * EAST; // Advance the given number of files
|
||||||
|
|
||||||
else if (token == '/')
|
else if (token == '/')
|
||||||
|
@ -240,28 +235,28 @@ Position &Position::set(const string &fenStr, StateInfo *si, Thread *th)
|
||||||
++sq;
|
++sq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// 2. Active color
|
// 2. Active color
|
||||||
ss >> token;
|
ss >> token;
|
||||||
sideToMove = (token == 'w' ? WHITE : BLACK);
|
sideToMove = (token == 'w' ? WHITE : BLACK);
|
||||||
ss >> token;
|
ss >> token;
|
||||||
|
|
||||||
// 5-6. Halfmove clock and fullmove number
|
// 3. Phrase
|
||||||
|
|
||||||
|
|
||||||
|
// 4-5. Halfmove clock and fullmove number
|
||||||
ss >> std::skipws >> st->rule50 >> gamePly;
|
ss >> std::skipws >> st->rule50 >> gamePly;
|
||||||
|
|
||||||
// Convert from fullmove starting from 1 to gamePly starting from 0,
|
// Convert from fullmove starting from 1 to gamePly starting from 0,
|
||||||
// handle also common incorrect FEN with fullmove = 0.
|
// handle also common incorrect FEN with fullmove = 0.
|
||||||
gamePly = std::max(2 * (gamePly - 1), 0) + (sideToMove == BLACK);
|
gamePly = std::max(2 * (gamePly - 1), 0) + (sideToMove == WHITE);
|
||||||
|
|
||||||
thisThread = th;
|
thisThread = th;
|
||||||
set_state(st);
|
set_state(st);
|
||||||
|
|
||||||
assert(pos_is_ok());
|
//assert(pos_is_ok());
|
||||||
#endif
|
|
||||||
th = th;
|
|
||||||
si = si;
|
|
||||||
string str = fenStr;
|
|
||||||
str = "";
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -867,7 +862,7 @@ bool Position::select_piece(Square s)
|
||||||
if (action != ACTION_SELECT && action != ACTION_PLACE)
|
if (action != ACTION_SELECT && action != ACTION_PLACE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (board[s]& (sideToMove << PLAYER_SHIFT)) {
|
if (board[s] & (sideToMove << PLAYER_SHIFT)) {
|
||||||
currentSquare = s;
|
currentSquare = s;
|
||||||
action = ACTION_PLACE;
|
action = ACTION_PLACE;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue