position: do_move() 中统一执行 move = m 操作
This commit is contained in:
parent
806b97d334
commit
a45a8006e5
|
@ -388,6 +388,8 @@ bool Position::pseudo_legal(const Move m) const
|
||||||
|
|
||||||
void Position::do_move(Move m, StateInfo &newSt)
|
void Position::do_move(Move m, StateInfo &newSt)
|
||||||
{
|
{
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
++st->rule50;
|
++st->rule50;
|
||||||
|
|
||||||
MoveType mt = type_of(m);
|
MoveType mt = type_of(m);
|
||||||
|
@ -396,17 +398,23 @@ void Position::do_move(Move m, StateInfo &newSt)
|
||||||
case MOVETYPE_REMOVE:
|
case MOVETYPE_REMOVE:
|
||||||
// Reset rule 50 counter
|
// Reset rule 50 counter
|
||||||
st->rule50 = 0;
|
st->rule50 = 0;
|
||||||
remove_piece(static_cast<Square>(-m));
|
ret = remove_piece(static_cast<Square>(-m));
|
||||||
break;
|
break;
|
||||||
case MOVETYPE_MOVE:
|
case MOVETYPE_MOVE:
|
||||||
move_piece(from_sq(m), to_sq(m));
|
ret = move_piece(from_sq(m), to_sq(m));
|
||||||
break;
|
break;
|
||||||
case MOVETYPE_PLACE:
|
case MOVETYPE_PLACE:
|
||||||
put_piece(to_sq(m));
|
ret = put_piece(to_sq(m));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
move = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Position::undo_move() unmakes a move. When it returns, the position should
|
/// Position::undo_move() unmakes a move. When it returns, the position should
|
||||||
|
@ -634,8 +642,6 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
||||||
byTypeBB[ALL_PIECES] |= s;
|
byTypeBB[ALL_PIECES] |= s;
|
||||||
byTypeBB[us] |= s;
|
byTypeBB[us] |= s;
|
||||||
|
|
||||||
move = static_cast<Move>(s);
|
|
||||||
|
|
||||||
if (updateCmdlist) {
|
if (updateCmdlist) {
|
||||||
sprintf(cmdline, "(%1u,%1u)",
|
sprintf(cmdline, "(%1u,%1u)",
|
||||||
file, rank);
|
file, rank);
|
||||||
|
@ -693,8 +699,6 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
move = make_move(currentSquare, s);
|
|
||||||
|
|
||||||
if (updateCmdlist) {
|
if (updateCmdlist) {
|
||||||
sprintf(cmdline, "(%1u,%1u)->(%1u,%1u)", currentSquare / RANK_NB, currentSquare % RANK_NB + 1,
|
sprintf(cmdline, "(%1u,%1u)->(%1u,%1u)", currentSquare / RANK_NB, currentSquare % RANK_NB + 1,
|
||||||
file, rank);
|
file, rank);
|
||||||
|
@ -749,11 +753,6 @@ bool Position::remove_piece(Square s, bool updateCmdlist)
|
||||||
if (pieceCountNeedRemove <= 0)
|
if (pieceCountNeedRemove <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
File file = file_of(s);
|
|
||||||
Rank rank = rank_of(s);
|
|
||||||
|
|
||||||
int oppId = them;
|
|
||||||
|
|
||||||
// if piece is not their
|
// if piece is not their
|
||||||
if (!((them << PLAYER_SHIFT) & board[s]))
|
if (!((them << PLAYER_SHIFT) & board[s]))
|
||||||
return false;
|
return false;
|
||||||
|
@ -769,7 +768,7 @@ bool Position::remove_piece(Square s, bool updateCmdlist)
|
||||||
if (rule.hasBannedLocations && phase == PHASE_PLACING) {
|
if (rule.hasBannedLocations && phase == PHASE_PLACING) {
|
||||||
board[s]= BAN_STONE;
|
board[s]= BAN_STONE;
|
||||||
update_key(s);
|
update_key(s);
|
||||||
byTypeBB[oppId] ^= s;
|
byTypeBB[them] ^= s;
|
||||||
byTypeBB[BAN] |= s;
|
byTypeBB[BAN] |= s;
|
||||||
} else { // Remove
|
} else { // Remove
|
||||||
board[s]= NO_PIECE;
|
board[s]= NO_PIECE;
|
||||||
|
@ -779,9 +778,9 @@ bool Position::remove_piece(Square s, bool updateCmdlist)
|
||||||
|
|
||||||
pieceCountOnBoard[them]--;
|
pieceCountOnBoard[them]--;
|
||||||
|
|
||||||
move = static_cast<Move>(-s);
|
|
||||||
|
|
||||||
if (updateCmdlist) {
|
if (updateCmdlist) {
|
||||||
|
File file = file_of(s);
|
||||||
|
Rank rank = rank_of(s);
|
||||||
sprintf(cmdline, "-(%1u,%1u)", file, rank);
|
sprintf(cmdline, "-(%1u,%1u)", file, rank);
|
||||||
gamePly++;
|
gamePly++;
|
||||||
st->rule50 = 0;
|
st->rule50 = 0;
|
||||||
|
|
Loading…
Reference in New Issue