From 525088d280bdee7b8a61505ef418450ccd3eb98d Mon Sep 17 00:00:00 2001 From: Calcitem Date: Thu, 31 Dec 2020 01:22:13 +0800 Subject: [PATCH] refactor: Rename piecesXXX to nPiecesXXX --- src/evaluate.cpp | 30 ++++----- src/mills.cpp | 3 + src/movegen.cpp | 2 +- src/position.cpp | 84 +++++++++++------------ src/position.h | 32 ++++----- src/search.cpp | 2 +- src/ui/flutter/lib/mill/position.dart | 95 ++++++++++++++------------- src/ui/qt/game.cpp | 8 +-- 8 files changed, 130 insertions(+), 126 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 26a9f29b..abf5e34c 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -67,17 +67,17 @@ Value Evaluation::value() int nPiecesInHandDiff; int nPiecesOnBoardDiff; - int piecesNeedRemove; + int nPiecesNeedRemove; switch (pos.get_phase()) { case Phase::ready: break; 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; - 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; switch (pos.get_action()) { @@ -86,9 +86,9 @@ Value Evaluation::value() break; case Action::remove: - piecesNeedRemove = (pos.side_to_move() == BLACK) ? - pos.pieces_need_remove() : -(pos.pieces_need_remove()); - value += piecesNeedRemove * VALUE_EACH_PIECE_PLACING_NEEDREMOVE; + nPiecesNeedRemove = (pos.side_to_move() == BLACK) ? + pos.n_pieces_to_remove() : -(pos.n_pieces_to_remove()); + value += nPiecesNeedRemove * VALUE_EACH_PIECE_PLACING_NEEDREMOVE; break; default: break; @@ -97,11 +97,11 @@ Value Evaluation::value() break; case Phase::moving: - value = pos.pieces_on_board(BLACK) * VALUE_EACH_PIECE_ONBOARD - - pos.pieces_on_board(WHITE) * VALUE_EACH_PIECE_ONBOARD; + value = pos.n_pieces_on_board(BLACK) * VALUE_EACH_PIECE_ONBOARD - + pos.n_pieces_on_board(WHITE) * VALUE_EACH_PIECE_ONBOARD; #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 */ switch (pos.get_action()) { @@ -110,9 +110,9 @@ Value Evaluation::value() break; case Action::remove: - piecesNeedRemove = (pos.side_to_move() == BLACK) ? - pos.pieces_need_remove() : -(pos.pieces_need_remove()); - value += piecesNeedRemove * VALUE_EACH_PIECE_MOVING_NEEDREMOVE; + nPiecesNeedRemove = (pos.side_to_move() == BLACK) ? + pos.n_pieces_to_remove() : -(pos.n_pieces_to_remove()); + value += nPiecesNeedRemove * VALUE_EACH_PIECE_MOVING_NEEDREMOVE; break; default: break; @@ -121,7 +121,7 @@ Value Evaluation::value() break; 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) { value -= VALUE_MATE; } else { @@ -134,9 +134,9 @@ Value Evaluation::value() value += delta; } - else if (pos.pieces_on_board(BLACK) < rule.nPiecesAtLeast) { + else if (pos.n_pieces_on_board(BLACK) < rule.nPiecesAtLeast) { 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; } diff --git a/src/mills.cpp b/src/mills.cpp index d50ab6b3..6a4ac0c1 100644 --- a/src/mills.cpp +++ b/src/mills.cpp @@ -28,6 +28,9 @@ 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 | \ | / | diff --git a/src/movegen.cpp b/src/movegen.cpp index c53ef98c..1a8c1a26 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -60,7 +60,7 @@ ExtMove *generate(Position &pos, ExtMove *moveList) 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) { for (auto direction = MD_BEGIN; direction < MD_NB; ++direction) { to = static_cast(MoveList::adjacentSquares[from][direction]); diff --git a/src/position.cpp b/src/position.cpp index 88fb97d8..ad3f44e3 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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 ss >> std::skipws - >> piecesOnBoard[BLACK] >> piecesInHand[BLACK] - >> piecesOnBoard[WHITE] >> piecesInHand[WHITE] - >> piecesNeedRemove; + >> nPiecesOnBoard[BLACK] >> nPiecesInHand[BLACK] + >> nPiecesOnBoard[WHITE] >> nPiecesInHand[WHITE] + >> nPiecesNeedRemove; // 6-7. Halfmove clock and fullmove number @@ -360,9 +360,9 @@ const string Position::fen() const ss << " "; - ss << piecesOnBoard[BLACK] << " " << piecesInHand[BLACK] << " " - << piecesOnBoard[WHITE] << " " << piecesInHand[WHITE] << " " - << piecesNeedRemove << " "; + ss << nPiecesOnBoard[BLACK] << " " << nPiecesInHand[BLACK] << " " + << nPiecesOnBoard[WHITE] << " " << nPiecesInHand[WHITE] << " " + << nPiecesNeedRemove << " "; ss << st.rule50 << " " << 1 + (gamePly - (sideToMove == BLACK)) / 2; @@ -535,9 +535,9 @@ void Position::undo_move(Move m) } // TODO: Adjust - //int piecesInHand[COLOR_NB]{ 0 }; - //int piecesOnBoard[COLOR_NB]{ 0 }; - //int piecesNeedRemove{ 0 }; + //int nPiecesInHand[COLOR_NB]{ 0 }; + //int nPiecesOnBoard[COLOR_NB]{ 0 }; + //int nPiecesNeedRemove{ 0 }; // 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 r = 0; r < RANK_NB; r++) { Square s = static_cast(f * RANK_NB + r); if (board[s] & B_STONE) { - piecesOnBoard[BLACK]++; + nPiecesOnBoard[BLACK]++; } else if (board[s] & W_STONE) { - piecesOnBoard[WHITE]++; + nPiecesOnBoard[WHITE]++; } #if 0 else if (board[s] & BAN_STONE) { @@ -685,20 +685,20 @@ int Position::pieces_on_board_count() } } - if (piecesOnBoard[BLACK] > rule.nTotalPiecesEachSide || - piecesOnBoard[WHITE] > rule.nTotalPiecesEachSide) { + if (nPiecesOnBoard[BLACK] > rule.nTotalPiecesEachSide || + nPiecesOnBoard[WHITE] > rule.nTotalPiecesEachSide) { 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]; - piecesInHand[WHITE] = rule.nTotalPiecesEachSide - piecesOnBoard[WHITE]; + nPiecesInHand[BLACK] = rule.nTotalPiecesEachSide - nPiecesOnBoard[BLACK]; + nPiecesInHand[WHITE] = rule.nTotalPiecesEachSide - nPiecesOnBoard[WHITE]; - return piecesInHand[BLACK] + piecesInHand[WHITE]; + return nPiecesInHand[BLACK] + nPiecesInHand[WHITE]; } #ifdef THREEFOLD_REPETITION @@ -726,9 +726,9 @@ bool Position::reset() memset(byTypeBB, 0, sizeof(byTypeBB)); memset(byColorBB, 0, sizeof(byColorBB)); - piecesOnBoard[BLACK] = piecesOnBoard[WHITE] = 0; - piecesInHand[BLACK] = piecesInHand[WHITE] = rule.nTotalPiecesEachSide; - piecesNeedRemove = 0; + nPiecesOnBoard[BLACK] = nPiecesOnBoard[WHITE] = 0; + nPiecesInHand[BLACK] = nPiecesInHand[WHITE] = rule.nTotalPiecesEachSide; + nPiecesNeedRemove = 0; millListSize = 0; MoveList::create(); @@ -792,9 +792,9 @@ bool Position::put_piece(Square s, bool updateCmdlist) } if (phase == Phase::placing) { - piece = (Piece)((0x01 | make_piece(sideToMove)) + rule.nTotalPiecesEachSide - piecesInHand[us]); - piecesInHand[us]--; - piecesOnBoard[us]++; + piece = (Piece)((0x01 | make_piece(sideToMove)) + rule.nTotalPiecesEachSide - nPiecesInHand[us]); + nPiecesInHand[us]--; + nPiecesOnBoard[us]++; Piece pc = board[s] = piece; 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); 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()) { return true; } @@ -836,7 +836,7 @@ bool Position::put_piece(Square s, bool updateCmdlist) change_side_to_move(); } } else { - piecesNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1; + nPiecesNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1; update_key_misc(); action = Action::remove; } @@ -848,7 +848,7 @@ bool Position::put_piece(Square s, bool updateCmdlist) } // if illegal - if (piecesOnBoard[sideToMove] > rule.nPiecesAtLeast || + if (nPiecesOnBoard[sideToMove] > rule.nPiecesAtLeast || !rule.flyingAllowed) { if ((square_bb(s) & MoveList::adjacentSquaresBB[currentSquare]) == 0) { return false; @@ -890,7 +890,7 @@ bool Position::put_piece(Square s, bool updateCmdlist) return true; } } else { - piecesNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1; + nPiecesNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1; update_key_misc(); action = Action::remove; } @@ -909,7 +909,7 @@ bool Position::remove_piece(Square s, bool updateCmdlist) if (action != Action::remove) return false; - if (piecesNeedRemove <= 0) + if (nPiecesNeedRemove <= 0) return false; // 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? } - piecesOnBoard[them]--; + nPiecesOnBoard[them]--; - if (piecesOnBoard[them] + piecesInHand[them] < rule.nPiecesAtLeast) { + if (nPiecesOnBoard[them] + nPiecesInHand[them] < rule.nPiecesAtLeast) { set_gameover(sideToMove, GameOverReason::loseReasonlessThanThree); return true; } currentSquare = SQ_0; - piecesNeedRemove--; + nPiecesNeedRemove--; update_key_misc(); - if (piecesNeedRemove > 0) { + if (nPiecesNeedRemove > 0) { return true; } if (phase == Phase::placing) { - if (piecesInHand[BLACK] == 0 && piecesInHand[WHITE] == 0) { + if (nPiecesInHand[BLACK] == 0 && nPiecesInHand[WHITE] == 0) { phase = Phase::moving; action = Action::select; @@ -1123,7 +1123,7 @@ bool Position::check_if_game_is_over() return true; } - if (piecesOnBoard[BLACK] + piecesOnBoard[WHITE] >= EFFECTIVE_SQUARE_NB) { + if (nPiecesOnBoard[BLACK] + nPiecesOnBoard[WHITE] >= EFFECTIVE_SQUARE_NB) { if (rule.isBlackLoseButNotDrawWhenBoardFull) { set_gameover(WHITE, GameOverReason::loseReasonBoardIsFull); } else { @@ -1227,7 +1227,7 @@ Key Position::update_key_misc() { st.key = st.key << Zobrist::KEY_MISC_BIT >> Zobrist::KEY_MISC_BIT; - st.key |= static_cast(piecesNeedRemove) << (CHAR_BIT * sizeof(Key) - Zobrist::KEY_MISC_BIT); + st.key |= static_cast(nPiecesNeedRemove) << (CHAR_BIT * sizeof(Key) - Zobrist::KEY_MISC_BIT); return st.key; } @@ -1486,7 +1486,7 @@ int Position::surrounded_empty_squares_count(Square s, bool includeFobidden) int n = 0; - if (piecesOnBoard[sideToMove] > rule.nPiecesAtLeast || + if (nPiecesOnBoard[sideToMove] > rule.nPiecesAtLeast || !rule.flyingAllowed) { Square moveSquare; 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 { // Full - if (piecesOnBoard[BLACK] + piecesOnBoard[WHITE] >= EFFECTIVE_SQUARE_NB) + if (nPiecesOnBoard[BLACK] + nPiecesOnBoard[WHITE] >= EFFECTIVE_SQUARE_NB) return true; // Can fly - if (piecesOnBoard[sideToMove] <= rule.nPiecesAtLeast && + if (nPiecesOnBoard[sideToMove] <= rule.nPiecesAtLeast && rule.flyingAllowed) { return false; } diff --git a/src/position.h b/src/position.h index fd7ab386..359b5fd7 100644 --- a/src/position.h +++ b/src/position.h @@ -142,13 +142,13 @@ public: static void print_board(); - int pieces_on_board_count(); - int pieces_in_hand_count(); + int n_pieces_on_board_count(); + int n_pieces_in_hand_count(); - int pieces_on_board(Color c); - int pieces_in_hand(Color c); + int n_pieces_on_board(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); @@ -178,9 +178,9 @@ public: Bitboard byTypeBB[PIECE_TYPE_NB]; Bitboard byColorBB[COLOR_NB]; // TODO: [0] is sum of Black and White - int piecesInHand[COLOR_NB]{ 0, 12, 12 }; // TODO - int piecesOnBoard[COLOR_NB]{ 0, 0, 0 }; - int piecesNeedRemove{ 0 }; + int nPiecesInHand[COLOR_NB]{ 0, 12, 12 }; // TODO + int nPiecesOnBoard[COLOR_NB]{ 0, 0, 0 }; + int nPiecesNeedRemove{ 0 }; int gamePly { 0 }; Color sideToMove { NOCOLOR }; Thread *thisThread; @@ -261,9 +261,9 @@ inline Piece Position::moved_piece(Move m) const template inline int Position::count(Color c) const { if (Pt == ON_BOARD) { - return piecesOnBoard[c]; + return nPiecesOnBoard[c]; } else if (Pt == IN_HAND) { - return piecesInHand[c]; + return nPiecesInHand[c]; } return 0; @@ -380,19 +380,19 @@ inline const char *Position::cmd_line() const 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 diff --git a/src/search.cpp b/src/search.cpp index 8ef13e1b..7acf66f0 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -294,7 +294,7 @@ Value search(Position *pos, Sanmill::Stack &ss, Depth depth, Depth ori #endif /* TRANSPOSITION_TABLE_ENABLE */ #if 0 - if (position->phase == Phase::placing && depth == 1 && pos->piecesNeedRemove > 0) { + if (position->phase == Phase::placing && depth == 1 && pos->nPiecesNeedRemove > 0) { depth--; } #endif diff --git a/src/ui/flutter/lib/mill/position.dart b/src/ui/flutter/lib/mill/position.dart index 85c61564..017ffef3 100644 --- a/src/ui/flutter/lib/mill/position.dart +++ b/src/ui/flutter/lib/mill/position.dart @@ -46,9 +46,9 @@ class Position { GameRecorder recorder; - Map piecesInHand = {Color.black: -1, Color.white: -1}; - Map piecesOnBoard = {Color.black: 0, Color.white: 0}; - int piecesNeedRemove = 0; + Map nPiecesInHand = {Color.black: -1, Color.white: -1}; + Map nPiecesOnBoard = {Color.black: 0, Color.white: 0}; + int nPiecesNeedRemove = 0; int gamePly = 0; String _sideToMove = Color.black; @@ -102,9 +102,9 @@ class Position { recorder = other.recorder; - piecesInHand = other.piecesInHand; - piecesOnBoard = other.piecesOnBoard; - piecesNeedRemove = other.piecesNeedRemove; + nPiecesInHand = other.nPiecesInHand; + nPiecesOnBoard = other.nPiecesOnBoard; + nPiecesNeedRemove = other.nPiecesNeedRemove; gamePly = other.gamePly; @@ -242,15 +242,15 @@ class Position { 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; @@ -370,35 +370,35 @@ class Position { /////////////////////////////////////////////////////////////////////////////// - int piecesOnBoardCount() { - piecesOnBoard[Color.black] = piecesOnBoard[Color.white] = 0; + int nPiecesOnBoardCount() { + nPiecesOnBoard[Color.black] = nPiecesOnBoard[Color.white] = 0; for (int f = 1; f < fileExNumber; f++) { for (int r = 0; r < rankNumber; r++) { int s = f * rankNumber + r; if (board[s] == Piece.blackStone) { - piecesOnBoard[Color.black]++; + nPiecesOnBoard[Color.black]++; } else if (board[s] == Piece.whiteStone) { - piecesOnBoard[Color.black]++; + nPiecesOnBoard[Color.black]++; } } } - if (piecesOnBoard[Color.black] > rule.nTotalPiecesEachSide || - piecesOnBoard[Color.white] > rule.nTotalPiecesEachSide) { + if (nPiecesOnBoard[Color.black] > rule.nTotalPiecesEachSide || + nPiecesOnBoard[Color.white] > rule.nTotalPiecesEachSide) { return -1; } - return piecesOnBoard[Color.black] + piecesOnBoard[Color.white]; + return nPiecesOnBoard[Color.black] + nPiecesOnBoard[Color.white]; } - int piecesInHandCount() { - piecesInHand[Color.black] = - rule.nTotalPiecesEachSide - piecesOnBoard[Color.black]; - piecesInHand[Color.white] = - rule.nTotalPiecesEachSide - piecesOnBoard[Color.white]; + int nPiecesInHandCount() { + nPiecesInHand[Color.black] = + rule.nTotalPiecesEachSide - nPiecesOnBoard[Color.black]; + nPiecesInHand[Color.white] = + rule.nTotalPiecesEachSide - nPiecesOnBoard[Color.white]; - return piecesOnBoard[Color.black] + piecesOnBoard[Color.white]; + return nPiecesOnBoard[Color.black] + nPiecesOnBoard[Color.white]; } void clearBoard() { @@ -428,12 +428,12 @@ class Position { clearBoard(); - if (piecesOnBoardCount() == -1) { + if (nPiecesOnBoardCount() == -1) { return -1; } - piecesInHandCount(); - piecesNeedRemove = 0; + nPiecesInHandCount(); + nPiecesNeedRemove = 0; winner = Color.nobody; createMoveTable(); @@ -456,10 +456,10 @@ class Position { clearBoard(); - piecesOnBoard[Color.black] = piecesOnBoard[Color.white] = 0; - piecesInHand[Color.black] = - piecesInHand[Color.white] = rule.nTotalPiecesEachSide; - piecesNeedRemove = 0; + nPiecesOnBoard[Color.black] = nPiecesOnBoard[Color.white] = 0; + nPiecesInHand[Color.black] = + nPiecesInHand[Color.white] = rule.nTotalPiecesEachSide; + nPiecesNeedRemove = 0; currentSquare = 0; int i = 0; // TODO: rule @@ -513,8 +513,8 @@ class Position { if (phase == Phase.placing) { piece = sideToMove(); - piecesInHand[us]--; - piecesOnBoard[us]++; + nPiecesInHand[us]--; + nPiecesOnBoard[us]++; _grid[index] = piece; board[s] = piece; @@ -527,9 +527,10 @@ class Position { if (n == 0) { 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()) { return true; } @@ -552,7 +553,7 @@ class Position { changeSideToMove(); } } else { - piecesNeedRemove = + nPiecesNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1; action = Act.remove; } @@ -562,7 +563,7 @@ class Position { } // if illegal - if (piecesOnBoard[sideToMove()] > rule.nPiecesAtLeast || + if (nPiecesOnBoard[sideToMove()] > rule.nPiecesAtLeast || !rule.flyingAllowed) { int md; @@ -605,7 +606,7 @@ class Position { return true; } } else { - piecesNeedRemove = + nPiecesNeedRemove = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1; action = Act.remove; } @@ -621,7 +622,7 @@ class Position { if (action != Act.remove) return false; - if (piecesNeedRemove <= 0) return false; + if (nPiecesNeedRemove <= 0) return false; // if piece is not their if (!(Color.opponent(sideToMove()) == board[s])) return false; @@ -642,23 +643,23 @@ class Position { cmdline = "-(" + fileOf(s).toString() + "," + rankOf(s).toString() + ")"; 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); return true; } currentSquare = 0; - piecesNeedRemove--; + nPiecesNeedRemove--; - if (piecesNeedRemove > 0) { + if (nPiecesNeedRemove > 0) { return true; } 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; action = Act.select; @@ -748,7 +749,7 @@ class Position { return true; } - if (piecesOnBoard[Color.black] + piecesOnBoard[Color.white] >= + if (nPiecesOnBoard[Color.black] + nPiecesOnBoard[Color.white] >= rankNumber * fileNumber) { if (rule.isBlackLoseButNotDrawWhenBoardFull) { setGameOver(Color.white, GameOverReason.loseReasonBoardIsFull); @@ -1407,14 +1408,14 @@ class Position { bool isAllSurrounded() { // Full - if (piecesOnBoard[Color.black] + piecesOnBoard[Color.white] >= + if (nPiecesOnBoard[Color.black] + nPiecesOnBoard[Color.white] >= rankNumber * fileNumber) { //print("Board is full."); return true; } // Can fly - if (piecesOnBoard[sideToMove()] <= rule.nPiecesAtLeast && + if (nPiecesOnBoard[sideToMove()] <= rule.nPiecesAtLeast && rule.flyingAllowed) { //print("Can fly."); return false; diff --git a/src/ui/qt/game.cpp b/src/ui/qt/game.cpp index c7e7be99..4315c00b 100644 --- a/src/ui/qt/game.cpp +++ b/src/ui/qt/game.cpp @@ -1537,15 +1537,15 @@ void Game::setTips() switch (p.phase) { 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); break; case Phase::placing: 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) { - tips = "成三!轮到" + turnStr + "去子,需去" + std::to_string(p.piecesNeedRemove) + "子"; + tips = "成三!轮到" + turnStr + "去子,需去" + std::to_string(p.nPiecesNeedRemove) + "子"; } break; @@ -1553,7 +1553,7 @@ void Game::setTips() if (p.action == Action::place || p.action == Action::select) { tips = "轮到" + turnStr + "选子移动"; } else if (p.action == Action::remove) { - tips = "成三!轮到" + turnStr + "去子,需去" + std::to_string(p.piecesNeedRemove) + "子"; + tips = "成三!轮到" + turnStr + "去子,需去" + std::to_string(p.nPiecesNeedRemove) + "子"; } break;