position: refactor put_piece()
This commit is contained in:
parent
106d9f9cce
commit
391e5e1a83
|
@ -608,11 +608,7 @@ bool Position::start()
|
||||||
|
|
||||||
bool Position::put_piece(Square s, bool updateCmdlist)
|
bool Position::put_piece(Square s, bool updateCmdlist)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
Piece piece = NO_PIECE;
|
Piece piece = NO_PIECE;
|
||||||
int n = 0;
|
|
||||||
|
|
||||||
int us = sideToMove;
|
int us = sideToMove;
|
||||||
|
|
||||||
Bitboard fromTo;
|
Bitboard fromTo;
|
||||||
|
@ -625,7 +621,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
||||||
|
|
||||||
if (phase == PHASE_READY) {
|
if (phase == PHASE_READY) {
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (phase == PHASE_PLACING) {
|
if (phase == PHASE_PLACING) {
|
||||||
piece = (Piece)((0x01 | make_piece(sideToMove)) + rule.nTotalPiecesEachSide - pieceCountInHand[us]);
|
piece = (Piece)((0x01 | make_piece(sideToMove)) + rule.nTotalPiecesEachSide - pieceCountInHand[us]);
|
||||||
|
@ -646,7 +642,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
||||||
|
|
||||||
currentSquare = s;
|
currentSquare = s;
|
||||||
|
|
||||||
n = add_mills(currentSquare);
|
int n = add_mills(currentSquare);
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
assert(pieceCountInHand[BLACK] >= 0 && pieceCountInHand[WHITE] >= 0);
|
assert(pieceCountInHand[BLACK] >= 0 && pieceCountInHand[WHITE] >= 0);
|
||||||
|
@ -687,13 +683,15 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
||||||
// if illegal
|
// if illegal
|
||||||
if (pieceCountOnBoard[sideToMove] > rule.nPiecesAtLeast ||
|
if (pieceCountOnBoard[sideToMove] > rule.nPiecesAtLeast ||
|
||||||
!rule.allowFlyWhenRemainThreePieces) {
|
!rule.allowFlyWhenRemainThreePieces) {
|
||||||
for (i = 0; i < 4; i++) {
|
int md;
|
||||||
if (s == MoveList::moveTable[currentSquare][i])
|
|
||||||
|
for (md = 0; md < MD_NB; md++) {
|
||||||
|
if (s == MoveList::moveTable[currentSquare][md])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// not in moveTable
|
// not in moveTable
|
||||||
if (i == 4) {
|
if (md == MD_NB) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -718,7 +716,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
||||||
board[currentSquare] = NO_PIECE;
|
board[currentSquare] = NO_PIECE;
|
||||||
|
|
||||||
currentSquare = s;
|
currentSquare = s;
|
||||||
n = add_mills(currentSquare);
|
int n = add_mills(currentSquare);
|
||||||
|
|
||||||
// midgame
|
// midgame
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
|
@ -732,6 +730,8 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
||||||
pieceCountNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
pieceCountNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
||||||
action = ACTION_REMOVE;
|
action = ACTION_REMOVE;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue