refactor: Rename piecesXXX to nPiecesXXX
This commit is contained in:
parent
e330d5312c
commit
525088d280
|
@ -67,17 +67,17 @@ Value Evaluation<T>::value()
|
||||||
|
|
||||||
int nPiecesInHandDiff;
|
int nPiecesInHandDiff;
|
||||||
int nPiecesOnBoardDiff;
|
int nPiecesOnBoardDiff;
|
||||||
int piecesNeedRemove;
|
int nPiecesNeedRemove;
|
||||||
|
|
||||||
switch (pos.get_phase()) {
|
switch (pos.get_phase()) {
|
||||||
case Phase::ready:
|
case Phase::ready:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Phase::placing:
|
case Phase::placing:
|
||||||
nPiecesInHandDiff = pos.pieces_in_hand(BLACK) - pos.pieces_in_hand(WHITE);
|
nPiecesInHandDiff = pos.n_pieces_in_hand(BLACK) - pos.n_pieces_in_hand(WHITE);
|
||||||
value += nPiecesInHandDiff * VALUE_EACH_PIECE_INHAND;
|
value += nPiecesInHandDiff * VALUE_EACH_PIECE_INHAND;
|
||||||
|
|
||||||
nPiecesOnBoardDiff = pos.pieces_on_board(BLACK) - pos.pieces_on_board(WHITE);
|
nPiecesOnBoardDiff = pos.n_pieces_on_board(BLACK) - pos.n_pieces_on_board(WHITE);
|
||||||
value += nPiecesOnBoardDiff * VALUE_EACH_PIECE_ONBOARD;
|
value += nPiecesOnBoardDiff * VALUE_EACH_PIECE_ONBOARD;
|
||||||
|
|
||||||
switch (pos.get_action()) {
|
switch (pos.get_action()) {
|
||||||
|
@ -86,9 +86,9 @@ Value Evaluation<T>::value()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Action::remove:
|
case Action::remove:
|
||||||
piecesNeedRemove = (pos.side_to_move() == BLACK) ?
|
nPiecesNeedRemove = (pos.side_to_move() == BLACK) ?
|
||||||
pos.pieces_need_remove() : -(pos.pieces_need_remove());
|
pos.n_pieces_to_remove() : -(pos.n_pieces_to_remove());
|
||||||
value += piecesNeedRemove * VALUE_EACH_PIECE_PLACING_NEEDREMOVE;
|
value += nPiecesNeedRemove * VALUE_EACH_PIECE_PLACING_NEEDREMOVE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -97,11 +97,11 @@ Value Evaluation<T>::value()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Phase::moving:
|
case Phase::moving:
|
||||||
value = pos.pieces_on_board(BLACK) * VALUE_EACH_PIECE_ONBOARD -
|
value = pos.n_pieces_on_board(BLACK) * VALUE_EACH_PIECE_ONBOARD -
|
||||||
pos.pieces_on_board(WHITE) * VALUE_EACH_PIECE_ONBOARD;
|
pos.n_pieces_on_board(WHITE) * VALUE_EACH_PIECE_ONBOARD;
|
||||||
|
|
||||||
#ifdef EVALUATE_MOBILITY
|
#ifdef EVALUATE_MOBILITY
|
||||||
value += pos.get_mobility_diff(position->turn, position->piecesInHand[BLACK], position->piecesInHand[WHITE], false) * 10;
|
value += pos.get_mobility_diff(position->turn, position->nPiecesInHand[BLACK], position->nPiecesInHand[WHITE], false) * 10;
|
||||||
#endif /* EVALUATE_MOBILITY */
|
#endif /* EVALUATE_MOBILITY */
|
||||||
|
|
||||||
switch (pos.get_action()) {
|
switch (pos.get_action()) {
|
||||||
|
@ -110,9 +110,9 @@ Value Evaluation<T>::value()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Action::remove:
|
case Action::remove:
|
||||||
piecesNeedRemove = (pos.side_to_move() == BLACK) ?
|
nPiecesNeedRemove = (pos.side_to_move() == BLACK) ?
|
||||||
pos.pieces_need_remove() : -(pos.pieces_need_remove());
|
pos.n_pieces_to_remove() : -(pos.n_pieces_to_remove());
|
||||||
value += piecesNeedRemove * VALUE_EACH_PIECE_MOVING_NEEDREMOVE;
|
value += nPiecesNeedRemove * VALUE_EACH_PIECE_MOVING_NEEDREMOVE;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -121,7 +121,7 @@ Value Evaluation<T>::value()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Phase::gameOver:
|
case Phase::gameOver:
|
||||||
if (pos.pieces_on_board(BLACK) + pos.pieces_on_board(WHITE) >= EFFECTIVE_SQUARE_NB) {
|
if (pos.n_pieces_on_board(BLACK) + pos.n_pieces_on_board(WHITE) >= EFFECTIVE_SQUARE_NB) {
|
||||||
if (rule.isBlackLoseButNotDrawWhenBoardFull) {
|
if (rule.isBlackLoseButNotDrawWhenBoardFull) {
|
||||||
value -= VALUE_MATE;
|
value -= VALUE_MATE;
|
||||||
} else {
|
} else {
|
||||||
|
@ -134,9 +134,9 @@ Value Evaluation<T>::value()
|
||||||
value += delta;
|
value += delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (pos.pieces_on_board(BLACK) < rule.nPiecesAtLeast) {
|
else if (pos.n_pieces_on_board(BLACK) < rule.nPiecesAtLeast) {
|
||||||
value -= VALUE_MATE;
|
value -= VALUE_MATE;
|
||||||
} else if (pos.pieces_on_board(WHITE) < rule.nPiecesAtLeast) {
|
} else if (pos.n_pieces_on_board(WHITE) < rule.nPiecesAtLeast) {
|
||||||
value += VALUE_MATE;
|
value += VALUE_MATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
namespace Mills
|
namespace Mills
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Morris boards have concentric square rings joined by edges and an empty middle.
|
||||||
|
// Morris games are typically played on the vertices not the cells.
|
||||||
|
|
||||||
/*
|
/*
|
||||||
31 ----- 24 ----- 25
|
31 ----- 24 ----- 25
|
||||||
| \ | / |
|
| \ | / |
|
||||||
|
|
|
@ -60,7 +60,7 @@ ExtMove *generate<MOVE>(Position &pos, ExtMove *moveList)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos.pieces_on_board(pos.side_to_move()) > rule.nPiecesAtLeast ||
|
if (pos.n_pieces_on_board(pos.side_to_move()) > rule.nPiecesAtLeast ||
|
||||||
!rule.flyingAllowed) {
|
!rule.flyingAllowed) {
|
||||||
for (auto direction = MD_BEGIN; direction < MD_NB; ++direction) {
|
for (auto direction = MD_BEGIN; direction < MD_NB; ++direction) {
|
||||||
to = static_cast<Square>(MoveList<LEGAL>::adjacentSquares[from][direction]);
|
to = static_cast<Square>(MoveList<LEGAL>::adjacentSquares[from][direction]);
|
||||||
|
|
|
@ -273,9 +273,9 @@ Position &Position::set(const string &fenStr, Thread *th)
|
||||||
|
|
||||||
// 5. Black on board / Black in hand / White on board / White in hand / need to remove
|
// 5. Black on board / Black in hand / White on board / White in hand / need to remove
|
||||||
ss >> std::skipws
|
ss >> std::skipws
|
||||||
>> piecesOnBoard[BLACK] >> piecesInHand[BLACK]
|
>> nPiecesOnBoard[BLACK] >> nPiecesInHand[BLACK]
|
||||||
>> piecesOnBoard[WHITE] >> piecesInHand[WHITE]
|
>> nPiecesOnBoard[WHITE] >> nPiecesInHand[WHITE]
|
||||||
>> piecesNeedRemove;
|
>> nPiecesNeedRemove;
|
||||||
|
|
||||||
|
|
||||||
// 6-7. Halfmove clock and fullmove number
|
// 6-7. Halfmove clock and fullmove number
|
||||||
|
@ -360,9 +360,9 @@ const string Position::fen() const
|
||||||
|
|
||||||
ss << " ";
|
ss << " ";
|
||||||
|
|
||||||
ss << piecesOnBoard[BLACK] << " " << piecesInHand[BLACK] << " "
|
ss << nPiecesOnBoard[BLACK] << " " << nPiecesInHand[BLACK] << " "
|
||||||
<< piecesOnBoard[WHITE] << " " << piecesInHand[WHITE] << " "
|
<< nPiecesOnBoard[WHITE] << " " << nPiecesInHand[WHITE] << " "
|
||||||
<< piecesNeedRemove << " ";
|
<< nPiecesNeedRemove << " ";
|
||||||
|
|
||||||
ss << st.rule50 << " " << 1 + (gamePly - (sideToMove == BLACK)) / 2;
|
ss << st.rule50 << " " << 1 + (gamePly - (sideToMove == BLACK)) / 2;
|
||||||
|
|
||||||
|
@ -535,9 +535,9 @@ void Position::undo_move(Move m)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Adjust
|
// TODO: Adjust
|
||||||
//int piecesInHand[COLOR_NB]{ 0 };
|
//int nPiecesInHand[COLOR_NB]{ 0 };
|
||||||
//int piecesOnBoard[COLOR_NB]{ 0 };
|
//int nPiecesOnBoard[COLOR_NB]{ 0 };
|
||||||
//int piecesNeedRemove{ 0 };
|
//int nPiecesNeedRemove{ 0 };
|
||||||
|
|
||||||
// TODO End
|
// TODO End
|
||||||
|
|
||||||
|
@ -666,17 +666,17 @@ bool Position::pos_is_ok() const
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int Position::pieces_on_board_count()
|
int Position::n_pieces_on_board_count()
|
||||||
{
|
{
|
||||||
piecesOnBoard[BLACK] = piecesOnBoard[WHITE] = 0;
|
nPiecesOnBoard[BLACK] = nPiecesOnBoard[WHITE] = 0;
|
||||||
|
|
||||||
for (int f = 1; f < FILE_NB + 2; f++) {
|
for (int f = 1; f < FILE_NB + 2; f++) {
|
||||||
for (int r = 0; r < RANK_NB; r++) {
|
for (int r = 0; r < RANK_NB; r++) {
|
||||||
Square s = static_cast<Square>(f * RANK_NB + r);
|
Square s = static_cast<Square>(f * RANK_NB + r);
|
||||||
if (board[s] & B_STONE) {
|
if (board[s] & B_STONE) {
|
||||||
piecesOnBoard[BLACK]++;
|
nPiecesOnBoard[BLACK]++;
|
||||||
} else if (board[s] & W_STONE) {
|
} else if (board[s] & W_STONE) {
|
||||||
piecesOnBoard[WHITE]++;
|
nPiecesOnBoard[WHITE]++;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
else if (board[s] & BAN_STONE) {
|
else if (board[s] & BAN_STONE) {
|
||||||
|
@ -685,20 +685,20 @@ int Position::pieces_on_board_count()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (piecesOnBoard[BLACK] > rule.nTotalPiecesEachSide ||
|
if (nPiecesOnBoard[BLACK] > rule.nTotalPiecesEachSide ||
|
||||||
piecesOnBoard[WHITE] > rule.nTotalPiecesEachSide) {
|
nPiecesOnBoard[WHITE] > rule.nTotalPiecesEachSide) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return piecesOnBoard[BLACK] + piecesOnBoard[WHITE];
|
return nPiecesOnBoard[BLACK] + nPiecesOnBoard[WHITE];
|
||||||
}
|
}
|
||||||
|
|
||||||
int Position::pieces_in_hand_count()
|
int Position::n_pieces_in_hand_count()
|
||||||
{
|
{
|
||||||
piecesInHand[BLACK] = rule.nTotalPiecesEachSide - piecesOnBoard[BLACK];
|
nPiecesInHand[BLACK] = rule.nTotalPiecesEachSide - nPiecesOnBoard[BLACK];
|
||||||
piecesInHand[WHITE] = rule.nTotalPiecesEachSide - piecesOnBoard[WHITE];
|
nPiecesInHand[WHITE] = rule.nTotalPiecesEachSide - nPiecesOnBoard[WHITE];
|
||||||
|
|
||||||
return piecesInHand[BLACK] + piecesInHand[WHITE];
|
return nPiecesInHand[BLACK] + nPiecesInHand[WHITE];
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef THREEFOLD_REPETITION
|
#ifdef THREEFOLD_REPETITION
|
||||||
|
@ -726,9 +726,9 @@ bool Position::reset()
|
||||||
memset(byTypeBB, 0, sizeof(byTypeBB));
|
memset(byTypeBB, 0, sizeof(byTypeBB));
|
||||||
memset(byColorBB, 0, sizeof(byColorBB));
|
memset(byColorBB, 0, sizeof(byColorBB));
|
||||||
|
|
||||||
piecesOnBoard[BLACK] = piecesOnBoard[WHITE] = 0;
|
nPiecesOnBoard[BLACK] = nPiecesOnBoard[WHITE] = 0;
|
||||||
piecesInHand[BLACK] = piecesInHand[WHITE] = rule.nTotalPiecesEachSide;
|
nPiecesInHand[BLACK] = nPiecesInHand[WHITE] = rule.nTotalPiecesEachSide;
|
||||||
piecesNeedRemove = 0;
|
nPiecesNeedRemove = 0;
|
||||||
millListSize = 0;
|
millListSize = 0;
|
||||||
|
|
||||||
MoveList<LEGAL>::create();
|
MoveList<LEGAL>::create();
|
||||||
|
@ -792,9 +792,9 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (phase == Phase::placing) {
|
if (phase == Phase::placing) {
|
||||||
piece = (Piece)((0x01 | make_piece(sideToMove)) + rule.nTotalPiecesEachSide - piecesInHand[us]);
|
piece = (Piece)((0x01 | make_piece(sideToMove)) + rule.nTotalPiecesEachSide - nPiecesInHand[us]);
|
||||||
piecesInHand[us]--;
|
nPiecesInHand[us]--;
|
||||||
piecesOnBoard[us]++;
|
nPiecesOnBoard[us]++;
|
||||||
|
|
||||||
Piece pc = board[s] = piece;
|
Piece pc = board[s] = piece;
|
||||||
byTypeBB[ALL_PIECES] |= byTypeBB[type_of(pc)] |= s;
|
byTypeBB[ALL_PIECES] |= byTypeBB[type_of(pc)] |= s;
|
||||||
|
@ -811,9 +811,9 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
||||||
int n = add_mills(currentSquare);
|
int n = add_mills(currentSquare);
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
assert(piecesInHand[BLACK] >= 0 && piecesInHand[WHITE] >= 0);
|
assert(nPiecesInHand[BLACK] >= 0 && nPiecesInHand[WHITE] >= 0);
|
||||||
|
|
||||||
if (piecesInHand[BLACK] == 0 && piecesInHand[WHITE] == 0) {
|
if (nPiecesInHand[BLACK] == 0 && nPiecesInHand[WHITE] == 0) {
|
||||||
if (check_if_game_is_over()) {
|
if (check_if_game_is_over()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -836,7 +836,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
||||||
change_side_to_move();
|
change_side_to_move();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
piecesNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
nPiecesNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
||||||
update_key_misc();
|
update_key_misc();
|
||||||
action = Action::remove;
|
action = Action::remove;
|
||||||
}
|
}
|
||||||
|
@ -848,7 +848,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if illegal
|
// if illegal
|
||||||
if (piecesOnBoard[sideToMove] > rule.nPiecesAtLeast ||
|
if (nPiecesOnBoard[sideToMove] > rule.nPiecesAtLeast ||
|
||||||
!rule.flyingAllowed) {
|
!rule.flyingAllowed) {
|
||||||
if ((square_bb(s) & MoveList<LEGAL>::adjacentSquaresBB[currentSquare]) == 0) {
|
if ((square_bb(s) & MoveList<LEGAL>::adjacentSquaresBB[currentSquare]) == 0) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -890,7 +890,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
piecesNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
nPiecesNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
||||||
update_key_misc();
|
update_key_misc();
|
||||||
action = Action::remove;
|
action = Action::remove;
|
||||||
}
|
}
|
||||||
|
@ -909,7 +909,7 @@ bool Position::remove_piece(Square s, bool updateCmdlist)
|
||||||
if (action != Action::remove)
|
if (action != Action::remove)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (piecesNeedRemove <= 0)
|
if (nPiecesNeedRemove <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// if piece is not their
|
// if piece is not their
|
||||||
|
@ -951,24 +951,24 @@ bool Position::remove_piece(Square s, bool updateCmdlist)
|
||||||
st.rule50 = 0; // TODO: Need to move out?
|
st.rule50 = 0; // TODO: Need to move out?
|
||||||
}
|
}
|
||||||
|
|
||||||
piecesOnBoard[them]--;
|
nPiecesOnBoard[them]--;
|
||||||
|
|
||||||
if (piecesOnBoard[them] + piecesInHand[them] < rule.nPiecesAtLeast) {
|
if (nPiecesOnBoard[them] + nPiecesInHand[them] < rule.nPiecesAtLeast) {
|
||||||
set_gameover(sideToMove, GameOverReason::loseReasonlessThanThree);
|
set_gameover(sideToMove, GameOverReason::loseReasonlessThanThree);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentSquare = SQ_0;
|
currentSquare = SQ_0;
|
||||||
|
|
||||||
piecesNeedRemove--;
|
nPiecesNeedRemove--;
|
||||||
update_key_misc();
|
update_key_misc();
|
||||||
|
|
||||||
if (piecesNeedRemove > 0) {
|
if (nPiecesNeedRemove > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (phase == Phase::placing) {
|
if (phase == Phase::placing) {
|
||||||
if (piecesInHand[BLACK] == 0 && piecesInHand[WHITE] == 0) {
|
if (nPiecesInHand[BLACK] == 0 && nPiecesInHand[WHITE] == 0) {
|
||||||
phase = Phase::moving;
|
phase = Phase::moving;
|
||||||
action = Action::select;
|
action = Action::select;
|
||||||
|
|
||||||
|
@ -1123,7 +1123,7 @@ bool Position::check_if_game_is_over()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (piecesOnBoard[BLACK] + piecesOnBoard[WHITE] >= EFFECTIVE_SQUARE_NB) {
|
if (nPiecesOnBoard[BLACK] + nPiecesOnBoard[WHITE] >= EFFECTIVE_SQUARE_NB) {
|
||||||
if (rule.isBlackLoseButNotDrawWhenBoardFull) {
|
if (rule.isBlackLoseButNotDrawWhenBoardFull) {
|
||||||
set_gameover(WHITE, GameOverReason::loseReasonBoardIsFull);
|
set_gameover(WHITE, GameOverReason::loseReasonBoardIsFull);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1227,7 +1227,7 @@ Key Position::update_key_misc()
|
||||||
{
|
{
|
||||||
st.key = st.key << Zobrist::KEY_MISC_BIT >> Zobrist::KEY_MISC_BIT;
|
st.key = st.key << Zobrist::KEY_MISC_BIT >> Zobrist::KEY_MISC_BIT;
|
||||||
|
|
||||||
st.key |= static_cast<Key>(piecesNeedRemove) << (CHAR_BIT * sizeof(Key) - Zobrist::KEY_MISC_BIT);
|
st.key |= static_cast<Key>(nPiecesNeedRemove) << (CHAR_BIT * sizeof(Key) - Zobrist::KEY_MISC_BIT);
|
||||||
|
|
||||||
return st.key;
|
return st.key;
|
||||||
}
|
}
|
||||||
|
@ -1486,7 +1486,7 @@ int Position::surrounded_empty_squares_count(Square s, bool includeFobidden)
|
||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
if (piecesOnBoard[sideToMove] > rule.nPiecesAtLeast ||
|
if (nPiecesOnBoard[sideToMove] > rule.nPiecesAtLeast ||
|
||||||
!rule.flyingAllowed) {
|
!rule.flyingAllowed) {
|
||||||
Square moveSquare;
|
Square moveSquare;
|
||||||
for (MoveDirection d = MD_BEGIN; d < MD_NB; ++d) {
|
for (MoveDirection d = MD_BEGIN; d < MD_NB; ++d) {
|
||||||
|
@ -1537,11 +1537,11 @@ void Position::surrounded_pieces_count(Square s, int &nOurPieces, int &nTheirPie
|
||||||
bool Position::is_all_surrounded() const
|
bool Position::is_all_surrounded() const
|
||||||
{
|
{
|
||||||
// Full
|
// Full
|
||||||
if (piecesOnBoard[BLACK] + piecesOnBoard[WHITE] >= EFFECTIVE_SQUARE_NB)
|
if (nPiecesOnBoard[BLACK] + nPiecesOnBoard[WHITE] >= EFFECTIVE_SQUARE_NB)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Can fly
|
// Can fly
|
||||||
if (piecesOnBoard[sideToMove] <= rule.nPiecesAtLeast &&
|
if (nPiecesOnBoard[sideToMove] <= rule.nPiecesAtLeast &&
|
||||||
rule.flyingAllowed) {
|
rule.flyingAllowed) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,13 +142,13 @@ public:
|
||||||
|
|
||||||
static void print_board();
|
static void print_board();
|
||||||
|
|
||||||
int pieces_on_board_count();
|
int n_pieces_on_board_count();
|
||||||
int pieces_in_hand_count();
|
int n_pieces_in_hand_count();
|
||||||
|
|
||||||
int pieces_on_board(Color c);
|
int n_pieces_on_board(Color c);
|
||||||
int pieces_in_hand(Color c);
|
int n_pieces_in_hand(Color c);
|
||||||
|
|
||||||
int pieces_need_remove();
|
int n_pieces_to_remove();
|
||||||
|
|
||||||
static bool is_star_square(Square s);
|
static bool is_star_square(Square s);
|
||||||
|
|
||||||
|
@ -178,9 +178,9 @@ public:
|
||||||
Bitboard byTypeBB[PIECE_TYPE_NB];
|
Bitboard byTypeBB[PIECE_TYPE_NB];
|
||||||
Bitboard byColorBB[COLOR_NB];
|
Bitboard byColorBB[COLOR_NB];
|
||||||
// TODO: [0] is sum of Black and White
|
// TODO: [0] is sum of Black and White
|
||||||
int piecesInHand[COLOR_NB]{ 0, 12, 12 }; // TODO
|
int nPiecesInHand[COLOR_NB]{ 0, 12, 12 }; // TODO
|
||||||
int piecesOnBoard[COLOR_NB]{ 0, 0, 0 };
|
int nPiecesOnBoard[COLOR_NB]{ 0, 0, 0 };
|
||||||
int piecesNeedRemove{ 0 };
|
int nPiecesNeedRemove{ 0 };
|
||||||
int gamePly { 0 };
|
int gamePly { 0 };
|
||||||
Color sideToMove { NOCOLOR };
|
Color sideToMove { NOCOLOR };
|
||||||
Thread *thisThread;
|
Thread *thisThread;
|
||||||
|
@ -261,9 +261,9 @@ inline Piece Position::moved_piece(Move m) const
|
||||||
template<PieceType Pt> inline int Position::count(Color c) const
|
template<PieceType Pt> inline int Position::count(Color c) const
|
||||||
{
|
{
|
||||||
if (Pt == ON_BOARD) {
|
if (Pt == ON_BOARD) {
|
||||||
return piecesOnBoard[c];
|
return nPiecesOnBoard[c];
|
||||||
} else if (Pt == IN_HAND) {
|
} else if (Pt == IN_HAND) {
|
||||||
return piecesInHand[c];
|
return nPiecesInHand[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -380,19 +380,19 @@ inline const char *Position::cmd_line() const
|
||||||
return cmdline;
|
return cmdline;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::pieces_on_board(Color c)
|
inline int Position::n_pieces_on_board(Color c)
|
||||||
{
|
{
|
||||||
return piecesOnBoard[c];
|
return nPiecesOnBoard[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::pieces_in_hand(Color c)
|
inline int Position::n_pieces_in_hand(Color c)
|
||||||
{
|
{
|
||||||
return piecesInHand[c];
|
return nPiecesInHand[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int Position::pieces_need_remove()
|
inline int Position::n_pieces_to_remove()
|
||||||
{
|
{
|
||||||
return piecesNeedRemove;
|
return nPiecesNeedRemove;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // #ifndef POSITION_H_INCLUDED
|
#endif // #ifndef POSITION_H_INCLUDED
|
||||||
|
|
|
@ -294,7 +294,7 @@ Value search(Position *pos, Sanmill::Stack<Position> &ss, Depth depth, Depth ori
|
||||||
#endif /* TRANSPOSITION_TABLE_ENABLE */
|
#endif /* TRANSPOSITION_TABLE_ENABLE */
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (position->phase == Phase::placing && depth == 1 && pos->piecesNeedRemove > 0) {
|
if (position->phase == Phase::placing && depth == 1 && pos->nPiecesNeedRemove > 0) {
|
||||||
depth--;
|
depth--;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -46,9 +46,9 @@ class Position {
|
||||||
|
|
||||||
GameRecorder recorder;
|
GameRecorder recorder;
|
||||||
|
|
||||||
Map<String, int> piecesInHand = {Color.black: -1, Color.white: -1};
|
Map<String, int> nPiecesInHand = {Color.black: -1, Color.white: -1};
|
||||||
Map<String, int> piecesOnBoard = {Color.black: 0, Color.white: 0};
|
Map<String, int> nPiecesOnBoard = {Color.black: 0, Color.white: 0};
|
||||||
int piecesNeedRemove = 0;
|
int nPiecesNeedRemove = 0;
|
||||||
|
|
||||||
int gamePly = 0;
|
int gamePly = 0;
|
||||||
String _sideToMove = Color.black;
|
String _sideToMove = Color.black;
|
||||||
|
@ -102,9 +102,9 @@ class Position {
|
||||||
|
|
||||||
recorder = other.recorder;
|
recorder = other.recorder;
|
||||||
|
|
||||||
piecesInHand = other.piecesInHand;
|
nPiecesInHand = other.nPiecesInHand;
|
||||||
piecesOnBoard = other.piecesOnBoard;
|
nPiecesOnBoard = other.nPiecesOnBoard;
|
||||||
piecesNeedRemove = other.piecesNeedRemove;
|
nPiecesNeedRemove = other.nPiecesNeedRemove;
|
||||||
|
|
||||||
gamePly = other.gamePly;
|
gamePly = other.gamePly;
|
||||||
|
|
||||||
|
@ -242,15 +242,15 @@ class Position {
|
||||||
|
|
||||||
ss += " ";
|
ss += " ";
|
||||||
|
|
||||||
ss += piecesOnBoard[Color.black].toString() +
|
ss += nPiecesOnBoard[Color.black].toString() +
|
||||||
" " +
|
" " +
|
||||||
piecesInHand[Color.black].toString() +
|
nPiecesInHand[Color.black].toString() +
|
||||||
" " +
|
" " +
|
||||||
piecesOnBoard[Color.white].toString() +
|
nPiecesOnBoard[Color.white].toString() +
|
||||||
" " +
|
" " +
|
||||||
piecesInHand[Color.white].toString() +
|
nPiecesInHand[Color.white].toString() +
|
||||||
" " +
|
" " +
|
||||||
piecesNeedRemove.toString() +
|
nPiecesNeedRemove.toString() +
|
||||||
" ";
|
" ";
|
||||||
|
|
||||||
int sideIsBlack = _sideToMove == Color.black ? 1 : 0;
|
int sideIsBlack = _sideToMove == Color.black ? 1 : 0;
|
||||||
|
@ -370,35 +370,35 @@ class Position {
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int piecesOnBoardCount() {
|
int nPiecesOnBoardCount() {
|
||||||
piecesOnBoard[Color.black] = piecesOnBoard[Color.white] = 0;
|
nPiecesOnBoard[Color.black] = nPiecesOnBoard[Color.white] = 0;
|
||||||
|
|
||||||
for (int f = 1; f < fileExNumber; f++) {
|
for (int f = 1; f < fileExNumber; f++) {
|
||||||
for (int r = 0; r < rankNumber; r++) {
|
for (int r = 0; r < rankNumber; r++) {
|
||||||
int s = f * rankNumber + r;
|
int s = f * rankNumber + r;
|
||||||
if (board[s] == Piece.blackStone) {
|
if (board[s] == Piece.blackStone) {
|
||||||
piecesOnBoard[Color.black]++;
|
nPiecesOnBoard[Color.black]++;
|
||||||
} else if (board[s] == Piece.whiteStone) {
|
} else if (board[s] == Piece.whiteStone) {
|
||||||
piecesOnBoard[Color.black]++;
|
nPiecesOnBoard[Color.black]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (piecesOnBoard[Color.black] > rule.nTotalPiecesEachSide ||
|
if (nPiecesOnBoard[Color.black] > rule.nTotalPiecesEachSide ||
|
||||||
piecesOnBoard[Color.white] > rule.nTotalPiecesEachSide) {
|
nPiecesOnBoard[Color.white] > rule.nTotalPiecesEachSide) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return piecesOnBoard[Color.black] + piecesOnBoard[Color.white];
|
return nPiecesOnBoard[Color.black] + nPiecesOnBoard[Color.white];
|
||||||
}
|
}
|
||||||
|
|
||||||
int piecesInHandCount() {
|
int nPiecesInHandCount() {
|
||||||
piecesInHand[Color.black] =
|
nPiecesInHand[Color.black] =
|
||||||
rule.nTotalPiecesEachSide - piecesOnBoard[Color.black];
|
rule.nTotalPiecesEachSide - nPiecesOnBoard[Color.black];
|
||||||
piecesInHand[Color.white] =
|
nPiecesInHand[Color.white] =
|
||||||
rule.nTotalPiecesEachSide - piecesOnBoard[Color.white];
|
rule.nTotalPiecesEachSide - nPiecesOnBoard[Color.white];
|
||||||
|
|
||||||
return piecesOnBoard[Color.black] + piecesOnBoard[Color.white];
|
return nPiecesOnBoard[Color.black] + nPiecesOnBoard[Color.white];
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearBoard() {
|
void clearBoard() {
|
||||||
|
@ -428,12 +428,12 @@ class Position {
|
||||||
|
|
||||||
clearBoard();
|
clearBoard();
|
||||||
|
|
||||||
if (piecesOnBoardCount() == -1) {
|
if (nPiecesOnBoardCount() == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
piecesInHandCount();
|
nPiecesInHandCount();
|
||||||
piecesNeedRemove = 0;
|
nPiecesNeedRemove = 0;
|
||||||
|
|
||||||
winner = Color.nobody;
|
winner = Color.nobody;
|
||||||
createMoveTable();
|
createMoveTable();
|
||||||
|
@ -456,10 +456,10 @@ class Position {
|
||||||
|
|
||||||
clearBoard();
|
clearBoard();
|
||||||
|
|
||||||
piecesOnBoard[Color.black] = piecesOnBoard[Color.white] = 0;
|
nPiecesOnBoard[Color.black] = nPiecesOnBoard[Color.white] = 0;
|
||||||
piecesInHand[Color.black] =
|
nPiecesInHand[Color.black] =
|
||||||
piecesInHand[Color.white] = rule.nTotalPiecesEachSide;
|
nPiecesInHand[Color.white] = rule.nTotalPiecesEachSide;
|
||||||
piecesNeedRemove = 0;
|
nPiecesNeedRemove = 0;
|
||||||
|
|
||||||
currentSquare = 0;
|
currentSquare = 0;
|
||||||
int i = 0; // TODO: rule
|
int i = 0; // TODO: rule
|
||||||
|
@ -513,8 +513,8 @@ class Position {
|
||||||
|
|
||||||
if (phase == Phase.placing) {
|
if (phase == Phase.placing) {
|
||||||
piece = sideToMove();
|
piece = sideToMove();
|
||||||
piecesInHand[us]--;
|
nPiecesInHand[us]--;
|
||||||
piecesOnBoard[us]++;
|
nPiecesOnBoard[us]++;
|
||||||
|
|
||||||
_grid[index] = piece;
|
_grid[index] = piece;
|
||||||
board[s] = piece;
|
board[s] = piece;
|
||||||
|
@ -527,9 +527,10 @@ class Position {
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
assert(
|
assert(
|
||||||
piecesInHand[Color.black] >= 0 && piecesInHand[Color.white] >= 0);
|
nPiecesInHand[Color.black] >= 0 && nPiecesInHand[Color.white] >= 0);
|
||||||
|
|
||||||
if (piecesInHand[Color.black] == 0 && piecesInHand[Color.white] == 0) {
|
if (nPiecesInHand[Color.black] == 0 &&
|
||||||
|
nPiecesInHand[Color.white] == 0) {
|
||||||
if (checkIfGameIsOver()) {
|
if (checkIfGameIsOver()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -552,7 +553,7 @@ class Position {
|
||||||
changeSideToMove();
|
changeSideToMove();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
piecesNeedRemove =
|
nPiecesNeedRemove =
|
||||||
rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
||||||
action = Act.remove;
|
action = Act.remove;
|
||||||
}
|
}
|
||||||
|
@ -562,7 +563,7 @@ class Position {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if illegal
|
// if illegal
|
||||||
if (piecesOnBoard[sideToMove()] > rule.nPiecesAtLeast ||
|
if (nPiecesOnBoard[sideToMove()] > rule.nPiecesAtLeast ||
|
||||||
!rule.flyingAllowed) {
|
!rule.flyingAllowed) {
|
||||||
int md;
|
int md;
|
||||||
|
|
||||||
|
@ -605,7 +606,7 @@ class Position {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
piecesNeedRemove =
|
nPiecesNeedRemove =
|
||||||
rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
|
||||||
action = Act.remove;
|
action = Act.remove;
|
||||||
}
|
}
|
||||||
|
@ -621,7 +622,7 @@ class Position {
|
||||||
|
|
||||||
if (action != Act.remove) return false;
|
if (action != Act.remove) return false;
|
||||||
|
|
||||||
if (piecesNeedRemove <= 0) return false;
|
if (nPiecesNeedRemove <= 0) return false;
|
||||||
|
|
||||||
// if piece is not their
|
// if piece is not their
|
||||||
if (!(Color.opponent(sideToMove()) == board[s])) return false;
|
if (!(Color.opponent(sideToMove()) == board[s])) return false;
|
||||||
|
@ -642,23 +643,23 @@ class Position {
|
||||||
cmdline = "-(" + fileOf(s).toString() + "," + rankOf(s).toString() + ")";
|
cmdline = "-(" + fileOf(s).toString() + "," + rankOf(s).toString() + ")";
|
||||||
rule50 = 0; // TODO: Need to move out?
|
rule50 = 0; // TODO: Need to move out?
|
||||||
|
|
||||||
piecesOnBoard[them]--;
|
nPiecesOnBoard[them]--;
|
||||||
|
|
||||||
if (piecesOnBoard[them] + piecesInHand[them] < rule.nPiecesAtLeast) {
|
if (nPiecesOnBoard[them] + nPiecesInHand[them] < rule.nPiecesAtLeast) {
|
||||||
setGameOver(sideToMove(), GameOverReason.loseReasonlessThanThree);
|
setGameOver(sideToMove(), GameOverReason.loseReasonlessThanThree);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentSquare = 0;
|
currentSquare = 0;
|
||||||
|
|
||||||
piecesNeedRemove--;
|
nPiecesNeedRemove--;
|
||||||
|
|
||||||
if (piecesNeedRemove > 0) {
|
if (nPiecesNeedRemove > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (phase == Phase.placing) {
|
if (phase == Phase.placing) {
|
||||||
if (piecesInHand[Color.black] == 0 && piecesInHand[Color.white] == 0) {
|
if (nPiecesInHand[Color.black] == 0 && nPiecesInHand[Color.white] == 0) {
|
||||||
phase = Phase.moving;
|
phase = Phase.moving;
|
||||||
action = Act.select;
|
action = Act.select;
|
||||||
|
|
||||||
|
@ -748,7 +749,7 @@ class Position {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (piecesOnBoard[Color.black] + piecesOnBoard[Color.white] >=
|
if (nPiecesOnBoard[Color.black] + nPiecesOnBoard[Color.white] >=
|
||||||
rankNumber * fileNumber) {
|
rankNumber * fileNumber) {
|
||||||
if (rule.isBlackLoseButNotDrawWhenBoardFull) {
|
if (rule.isBlackLoseButNotDrawWhenBoardFull) {
|
||||||
setGameOver(Color.white, GameOverReason.loseReasonBoardIsFull);
|
setGameOver(Color.white, GameOverReason.loseReasonBoardIsFull);
|
||||||
|
@ -1407,14 +1408,14 @@ class Position {
|
||||||
|
|
||||||
bool isAllSurrounded() {
|
bool isAllSurrounded() {
|
||||||
// Full
|
// Full
|
||||||
if (piecesOnBoard[Color.black] + piecesOnBoard[Color.white] >=
|
if (nPiecesOnBoard[Color.black] + nPiecesOnBoard[Color.white] >=
|
||||||
rankNumber * fileNumber) {
|
rankNumber * fileNumber) {
|
||||||
//print("Board is full.");
|
//print("Board is full.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can fly
|
// Can fly
|
||||||
if (piecesOnBoard[sideToMove()] <= rule.nPiecesAtLeast &&
|
if (nPiecesOnBoard[sideToMove()] <= rule.nPiecesAtLeast &&
|
||||||
rule.flyingAllowed) {
|
rule.flyingAllowed) {
|
||||||
//print("Can fly.");
|
//print("Can fly.");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1537,15 +1537,15 @@ void Game::setTips()
|
||||||
|
|
||||||
switch (p.phase) {
|
switch (p.phase) {
|
||||||
case Phase::ready:
|
case Phase::ready:
|
||||||
tips = "轮到" + turnStr + "落子,剩余" + std::to_string(p.piecesInHand[BLACK]) + "子" +
|
tips = "轮到" + turnStr + "落子,剩余" + std::to_string(p.nPiecesInHand[BLACK]) + "子" +
|
||||||
" 比分 " + to_string(p.score[BLACK]) + ":" + to_string(p.score[WHITE]) + ", 和棋 " + to_string(p.score_draw);
|
" 比分 " + to_string(p.score[BLACK]) + ":" + to_string(p.score[WHITE]) + ", 和棋 " + to_string(p.score_draw);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Phase::placing:
|
case Phase::placing:
|
||||||
if (p.action == Action::place) {
|
if (p.action == Action::place) {
|
||||||
tips = "轮到" + turnStr + "落子,剩余" + std::to_string(p.piecesInHand[p.sideToMove]) + "子";
|
tips = "轮到" + turnStr + "落子,剩余" + std::to_string(p.nPiecesInHand[p.sideToMove]) + "子";
|
||||||
} else if (p.action == Action::remove) {
|
} else if (p.action == Action::remove) {
|
||||||
tips = "成三!轮到" + turnStr + "去子,需去" + std::to_string(p.piecesNeedRemove) + "子";
|
tips = "成三!轮到" + turnStr + "去子,需去" + std::to_string(p.nPiecesNeedRemove) + "子";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1553,7 +1553,7 @@ void Game::setTips()
|
||||||
if (p.action == Action::place || p.action == Action::select) {
|
if (p.action == Action::place || p.action == Action::select) {
|
||||||
tips = "轮到" + turnStr + "选子移动";
|
tips = "轮到" + turnStr + "选子移动";
|
||||||
} else if (p.action == Action::remove) {
|
} else if (p.action == Action::remove) {
|
||||||
tips = "成三!轮到" + turnStr + "去子,需去" + std::to_string(p.piecesNeedRemove) + "子";
|
tips = "成三!轮到" + turnStr + "去子,需去" + std::to_string(p.nPiecesNeedRemove) + "子";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue