From 90ca5f0e492a9d8c1c71649ba93927ff68687bd1 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Thu, 31 Dec 2020 02:33:46 +0800 Subject: [PATCH] refactor: rules: Rename some val Reference: Morris (Author: Dirk Farin) --- src/mills.cpp | 4 +- src/movegen.cpp | 4 +- src/movepick.cpp | 6 +-- src/position.cpp | 26 ++++++------ src/rule.h | 14 ++++--- src/thread.cpp | 6 +-- src/types.h | 2 +- src/ucioption.cpp | 24 +++++------ src/ui/flutter/lib/common/config.dart | 32 +++++++-------- src/ui/flutter/lib/engine/native_engine.dart | 9 ++--- src/ui/flutter/lib/l10n/intl_en.arb | 16 ++++---- src/ui/flutter/lib/l10n/intl_zh.arb | 8 ++-- src/ui/flutter/lib/mill/position.dart | 22 +++++----- src/ui/flutter/lib/mill/rule.dart | 8 ++-- src/ui/flutter/lib/widgets/settings_page.dart | 40 +++++++++---------- src/ui/qt/game.cpp | 4 +- 16 files changed, 109 insertions(+), 116 deletions(-) diff --git a/src/mills.cpp b/src/mills.cpp index 6a4ac0c1..155fd758 100644 --- a/src/mills.cpp +++ b/src/mills.cpp @@ -277,12 +277,12 @@ void move_priority_list_shuffle() std::array movePriorityList2; std::array movePriorityList3; - if (rule.nTotalPiecesEachSide == 9) { + if (rule.piecesCount == 9) { movePriorityList0 = { SQ_16, SQ_18, SQ_20, SQ_22 }; movePriorityList1 = { SQ_24, SQ_26, SQ_28, SQ_30, SQ_8, SQ_10, SQ_12, SQ_14 }; movePriorityList2 = { SQ_17, SQ_19, SQ_21, SQ_23 }; movePriorityList3 = { SQ_25, SQ_27, SQ_29, SQ_31, SQ_9, SQ_11, SQ_13, SQ_15 }; - } else if (rule.nTotalPiecesEachSide == 12) { + } else if (rule.piecesCount == 12) { movePriorityList0 = { SQ_17, SQ_19, SQ_21, SQ_23 }; movePriorityList1 = { SQ_25, SQ_27, SQ_29, SQ_31, SQ_9, SQ_11, SQ_13, SQ_15 }; movePriorityList2 = { SQ_16, SQ_18, SQ_20, SQ_22 }; diff --git a/src/movegen.cpp b/src/movegen.cpp index 370476a9..bf21a231 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -61,7 +61,7 @@ ExtMove *generate(Position &pos, ExtMove *moveList) } if (pos.piece_on_board_count(pos.side_to_move()) > rule.piecesAtLeastCount || - !rule.flyingAllowed) { + !rule.mayFly) { for (auto direction = MD_BEGIN; direction < MD_NB; ++direction) { to = static_cast(MoveList::adjacentSquares[from][direction]); if (to && !pos.get_board()[to]) { @@ -107,7 +107,7 @@ ExtMove *generate(Position &pos, ExtMove *moveList) for (auto i = EFFECTIVE_SQUARE_NB - 1; i >= 0; i--) { s = MoveList::movePriorityList[i]; if (pos.get_board()[s] & make_piece(them)) { - if (rule.allowRemovePieceInMill || !pos.in_how_many_mills(s, NOBODY)) { + if (rule.mayTakeFromMillsAlways || !pos.in_how_many_mills(s, NOBODY)) { *cur++ = (Move)-s; } } diff --git a/src/movepick.cpp b/src/movepick.cpp index a67301c2..28bb77d7 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -65,7 +65,7 @@ void MovePicker::score() int nTheirMills = 0; #ifndef SORT_MOVE_WITHOUT_HUMAN_KNOWLEDGES - // TODO: rule.allowRemoveMultiPiecesWhenCloseMultiMill adapt other rules + // TODO: rule.mayTakeMultiple adapt other rules if (type_of(m) != MOVETYPE_REMOVE) { // all phrase, check if place sq can close mill if (nOurMills > 0) { @@ -90,7 +90,7 @@ void MovePicker::score() if (sq % 2 == 0 && nTheirPieces == 3) { cur->value += RATING_BLOCK_ONE_MILL * nTheirMills; - } else if (sq % 2 == 1 && nTheirPieces == 2 && rule.nTotalPiecesEachSide == 12) { + } else if (sq % 2 == 1 && nTheirPieces == 2 && rule.piecesCount == 12) { cur->value += RATING_BLOCK_ONE_MILL * nTheirMills; } } @@ -100,7 +100,7 @@ void MovePicker::score() //cur->value += nBanned; // placing phrase, place nearby ban point // for 12 men, white 's 2nd move place star point is as important as close mill (TODO) - if (rule.nTotalPiecesEachSide == 12 && + if (rule.piecesCount == 12 && pos.count(WHITE) < 2 && // patch: only when white's 2nd move Position::is_star_square(static_cast(m))) { cur->value += RATING_STAR_SQUARE; diff --git a/src/position.cpp b/src/position.cpp index 2ecb8da4..c660b77d 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -685,8 +685,8 @@ int Position::piece_on_board_count_count() } } - if (pieceOnBoardCount[BLACK] > rule.nTotalPiecesEachSide || - pieceOnBoardCount[WHITE] > rule.nTotalPiecesEachSide) { + if (pieceOnBoardCount[BLACK] > rule.piecesCount || + pieceOnBoardCount[WHITE] > rule.piecesCount) { return -1; } @@ -695,8 +695,8 @@ int Position::piece_on_board_count_count() int Position::get_piece_in_hand_count() { - pieceInHandCount[BLACK] = rule.nTotalPiecesEachSide - pieceOnBoardCount[BLACK]; - pieceInHandCount[WHITE] = rule.nTotalPiecesEachSide - pieceOnBoardCount[WHITE]; + pieceInHandCount[BLACK] = rule.piecesCount - pieceOnBoardCount[BLACK]; + pieceInHandCount[WHITE] = rule.piecesCount - pieceOnBoardCount[WHITE]; return pieceInHandCount[BLACK] + pieceInHandCount[WHITE]; } @@ -727,7 +727,7 @@ bool Position::reset() memset(byColorBB, 0, sizeof(byColorBB)); pieceOnBoardCount[BLACK] = pieceOnBoardCount[WHITE] = 0; - pieceInHandCount[BLACK] = pieceInHandCount[WHITE] = rule.nTotalPiecesEachSide; + pieceInHandCount[BLACK] = pieceInHandCount[WHITE] = rule.piecesCount; pieceToRemoveCount = 0; millListSize = 0; @@ -792,7 +792,7 @@ bool Position::put_piece(Square s, bool updateCmdlist) } if (phase == Phase::placing) { - piece = (Piece)((0x01 | make_piece(sideToMove)) + rule.nTotalPiecesEachSide - pieceInHandCount[us]); + piece = (Piece)((0x01 | make_piece(sideToMove)) + rule.piecesCount - pieceInHandCount[us]); pieceInHandCount[us]--; pieceOnBoardCount[us]++; @@ -836,7 +836,7 @@ bool Position::put_piece(Square s, bool updateCmdlist) change_side_to_move(); } } else { - pieceToRemoveCount = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1; + pieceToRemoveCount = rule.mayTakeMultiple ? n : 1; update_key_misc(); action = Action::remove; } @@ -849,7 +849,7 @@ bool Position::put_piece(Square s, bool updateCmdlist) // if illegal if (pieceOnBoardCount[sideToMove] > rule.piecesAtLeastCount || - !rule.flyingAllowed) { + !rule.mayFly) { 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 { - pieceToRemoveCount = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1; + pieceToRemoveCount = rule.mayTakeMultiple ? n : 1; update_key_misc(); action = Action::remove; } @@ -916,7 +916,7 @@ bool Position::remove_piece(Square s, bool updateCmdlist) if (!(make_piece(~side_to_move()) & board[s])) return false; - if (!rule.allowRemovePieceInMill && + if (!rule.mayTakeFromMillsAlways && in_how_many_mills(s, NOBODY) && !is_all_in_mills(~sideToMove)) { return false; @@ -1487,7 +1487,7 @@ int Position::surrounded_empty_squares_count(Square s, bool includeFobidden) int n = 0; if (pieceOnBoardCount[sideToMove] > rule.piecesAtLeastCount || - !rule.flyingAllowed) { + !rule.mayFly) { Square moveSquare; for (MoveDirection d = MD_BEGIN; d < MD_NB; ++d) { moveSquare = static_cast(MoveList::adjacentSquares[s][d]); @@ -1542,7 +1542,7 @@ bool Position::is_all_surrounded() const // Can fly if (pieceOnBoardCount[sideToMove] <= rule.piecesAtLeastCount && - rule.flyingAllowed) { + rule.mayFly) { return false; } @@ -1573,7 +1573,7 @@ bool Position::is_star_square(Square s) void Position::print_board() { - if (rule.nTotalPiecesEachSide == 12) { + if (rule.piecesCount == 12) { printf("\n" "31 ----- 24 ----- 25\n" "| \\ | / |\n" diff --git a/src/rule.h b/src/rule.h index 98dbfa96..651b5e63 100644 --- a/src/rule.h +++ b/src/rule.h @@ -21,13 +21,15 @@ #include "types.h" +// The rule struct manages the various variants of the rules. struct Rule { const char name[32]; const char description[512]; - int nTotalPiecesEachSide; // 9 or 12 + // Number of pieces each player has at the beginning. + int piecesCount; int piecesAtLeastCount; // Default is 3 @@ -37,16 +39,18 @@ struct Rule bool isDefenderMoveFirst; - bool allowRemoveMultiPiecesWhenCloseMultiMill; + // When closing more than one mill at once, may also take several opponent pieces. + bool mayTakeMultiple; - bool allowRemovePieceInMill; + // May take from mills even if there are other pieces available. + bool mayTakeFromMillsAlways; bool isBlackLoseButNotDrawWhenBoardFull; bool isLoseButNotChangeSideWhenNoWay; - // Specifies if jumps are allowed when a player remains with three pieces on the board. - bool flyingAllowed; + // Player may fly if he is down to three pieces. + bool mayFly; int maxStepsLedToDraw; }; diff --git a/src/thread.cpp b/src/thread.cpp index b1c0f5c5..34ef8b99 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -439,9 +439,9 @@ Depth Thread::adjustDepth() const Depth flyingDepth = 9; if (rootPos->phase == Phase::placing) { - int index = rule.nTotalPiecesEachSide * 2 - rootPos->count(BLACK) - rootPos->count(WHITE); + int index = rule.piecesCount * 2 - rootPos->count(BLACK) - rootPos->count(WHITE); - if (rule.nTotalPiecesEachSide == 12) { + if (rule.piecesCount == 12) { assert(0 <= index && index <= 24); d = placingDepthTable_12[index]; } else { @@ -468,7 +468,7 @@ Depth Thread::adjustDepth() } // Can fly - if (rule.flyingAllowed) { + if (rule.mayFly) { if (pb == rule.piecesAtLeastCount || pw == rule.piecesAtLeastCount) { d = flyingDepth; diff --git a/src/types.h b/src/types.h index 073f58ab..1c7fa9a4 100644 --- a/src/types.h +++ b/src/types.h @@ -156,7 +156,7 @@ enum class Phase : uint16_t // - move a piece on the board: // - slide a piece between two adjacent locations; // - 'jump' a piece to any empty location if the player has less than -// three pieces and flyingAllowed is |true|; +// three pieces and mayFly is |true|; // - remove an opponent's piece after successfully closing a mill; enum class Action : uint16_t { diff --git a/src/ucioption.cpp b/src/ucioption.cpp index c836ec6d..26ba89fe 100644 --- a/src/ucioption.cpp +++ b/src/ucioption.cpp @@ -67,9 +67,9 @@ void on_random_move(const Option &o) // Rules -void on_nTotalPiecesEachSide(const Option &o) +void on_piecesCount(const Option &o) { - rule.nTotalPiecesEachSide = (int)o; + rule.piecesCount = (int)o; } void on_piecesAtLeastCount(const Option &o) @@ -92,14 +92,14 @@ void on_isDefenderMoveFirst(const Option &o) rule.isDefenderMoveFirst = (bool)o; } -void on_allowRemoveMultiPiecesWhenCloseMultiMill(const Option &o) +void on_mayTakeMultiple(const Option &o) { - rule.allowRemoveMultiPiecesWhenCloseMultiMill = (bool)o; + rule.mayTakeMultiple = (bool)o; } -void on_allowRemovePieceInMill(const Option &o) +void on_mayTakeFromMillsAlways(const Option &o) { - rule.allowRemovePieceInMill = (bool)o; + rule.mayTakeFromMillsAlways = (bool)o; } void on_isBlackLoseButNotDrawWhenBoardFull(const Option &o) @@ -112,9 +112,9 @@ void on_isLoseButNotChangeSideWhenNoWay(const Option &o) rule.isLoseButNotChangeSideWhenNoWay = (bool)o; } -void on_flyingAllowed(const Option &o) +void on_mayFly(const Option &o) { - rule.flyingAllowed = (bool)o; + rule.mayFly = (bool)o; } void on_maxStepsLedToDraw(const Option &o) @@ -156,16 +156,16 @@ void init(OptionsMap &o) o["Shuffling"] << Option(true, on_random_move); // Rules - o["nTotalPiecesEachSide"] << Option(12, 6, 12, on_nTotalPiecesEachSide); + o["piecesCount"] << Option(12, 6, 12, on_piecesCount); o["piecesAtLeastCount"] << Option(3, 3, 5, on_piecesAtLeastCount); o["hasObliqueLines"] << Option(true, on_hasObliqueLines); o["hasBannedLocations"] << Option(true, on_hasBannedLocations); o["isDefenderMoveFirst"] << Option(true, on_isDefenderMoveFirst); - o["allowRemoveMultiPiecesWhenCloseMultiMill"] << Option(false, on_allowRemoveMultiPiecesWhenCloseMultiMill); - o["allowRemovePieceInMill"] << Option(true, on_allowRemovePieceInMill); + o["mayTakeMultiple"] << Option(false, on_mayTakeMultiple); + o["mayTakeFromMillsAlways"] << Option(true, on_mayTakeFromMillsAlways); o["isBlackLoseButNotDrawWhenBoardFull"] << Option(true, on_isBlackLoseButNotDrawWhenBoardFull); o["isLoseButNotChangeSideWhenNoWay"] << Option(true, on_isLoseButNotChangeSideWhenNoWay); - o["flyingAllowed"] << Option(false, on_flyingAllowed); + o["mayFly"] << Option(false, on_mayFly); o["maxStepsLedToDraw"] << Option(50, 30, 50, on_maxStepsLedToDraw); } diff --git a/src/ui/flutter/lib/common/config.dart b/src/ui/flutter/lib/common/config.dart index 3ca75383..e10b89cb 100644 --- a/src/ui/flutter/lib/common/config.dart +++ b/src/ui/flutter/lib/common/config.dart @@ -37,16 +37,16 @@ class Config { static bool openingBook = false; // Rules - static int nTotalPiecesEachSide = 12; + static int piecesCount = 12; static int piecesAtLeastCount = 3; static bool hasObliqueLines = true; static bool hasBannedLocations = true; static bool isDefenderMoveFirst = true; - static bool allowRemoveMultiPiecesWhenCloseMultiMill = false; - static bool allowRemovePieceInMill = true; + static bool mayTakeMultiple = false; + static bool mayTakeFromMillsAlways = true; static bool isBlackLoseButNotDrawWhenBoardFull = true; static bool isLoseButNotChangeSideWhenNoWay = true; - static bool flyingAllowed = false; + static bool mayFly = false; static int maxStepsLedToDraw = 50; static Future loadProfile() async { @@ -67,8 +67,7 @@ class Config { Config.openingBook = profile['openingBook'] ?? false; // Rules - rule.nTotalPiecesEachSide = - Config.nTotalPiecesEachSide = profile['nTotalPiecesEachSide'] ?? 12; + rule.piecesCount = Config.piecesCount = profile['piecesCount'] ?? 12; rule.piecesAtLeastCount = Config.piecesAtLeastCount = profile['piecesAtLeastCount'] ?? 3; rule.hasObliqueLines = @@ -77,19 +76,17 @@ class Config { Config.hasBannedLocations = profile['hasBannedLocations'] ?? true; rule.isDefenderMoveFirst = Config.isDefenderMoveFirst = profile['isDefenderMoveFirst'] ?? true; - rule.allowRemoveMultiPiecesWhenCloseMultiMill = - Config.allowRemoveMultiPiecesWhenCloseMultiMill = - profile['allowRemoveMultiPiecesWhenCloseMultiMill'] ?? false; - rule.allowRemovePieceInMill = Config.allowRemovePieceInMill = - profile['allowRemovePieceInMill'] ?? true; + rule.mayTakeMultiple = + Config.mayTakeMultiple = profile['mayTakeMultiple'] ?? false; + rule.mayTakeFromMillsAlways = Config.mayTakeFromMillsAlways = + profile['mayTakeFromMillsAlways'] ?? true; rule.isBlackLoseButNotDrawWhenBoardFull = Config.isBlackLoseButNotDrawWhenBoardFull = profile['isBlackLoseButNotDrawWhenBoardFull'] ?? true; rule.isLoseButNotChangeSideWhenNoWay = Config.isLoseButNotChangeSideWhenNoWay = profile['isLoseButNotChangeSideWhenNoWay'] ?? true; - rule.flyingAllowed = - Config.flyingAllowed = profile['flyingAllowed'] ?? false; + rule.mayFly = Config.mayFly = profile['mayFly'] ?? false; rule.maxStepsLedToDraw = Config.maxStepsLedToDraw = profile['maxStepsLedToDraw'] ?? 50; @@ -114,19 +111,18 @@ class Config { profile['openingBook'] = Config.openingBook; // Rules - profile['nTotalPiecesEachSide'] = Config.nTotalPiecesEachSide; + profile['piecesCount'] = Config.piecesCount; profile['piecesAtLeastCount'] = Config.piecesAtLeastCount; profile['hasObliqueLines'] = Config.hasObliqueLines; profile['hasBannedLocations'] = Config.hasBannedLocations; profile['isDefenderMoveFirst'] = Config.isDefenderMoveFirst; - profile['allowRemoveMultiPiecesWhenCloseMultiMill'] = - Config.allowRemoveMultiPiecesWhenCloseMultiMill; - profile['allowRemovePieceInMill'] = Config.allowRemovePieceInMill; + profile['mayTakeMultiple'] = Config.mayTakeMultiple; + profile['mayTakeFromMillsAlways'] = Config.mayTakeFromMillsAlways; profile['isBlackLoseButNotDrawWhenBoardFull'] = Config.isBlackLoseButNotDrawWhenBoardFull; profile['isLoseButNotChangeSideWhenNoWay'] = Config.isLoseButNotChangeSideWhenNoWay; - profile['flyingAllowed'] = Config.flyingAllowed; + profile['mayFly'] = Config.mayFly; profile['maxStepsLedToDraw'] = Config.maxStepsLedToDraw; profile.commit(); diff --git a/src/ui/flutter/lib/engine/native_engine.dart b/src/ui/flutter/lib/engine/native_engine.dart index 0f2dc5e4..5690d802 100644 --- a/src/ui/flutter/lib/engine/native_engine.dart +++ b/src/ui/flutter/lib/engine/native_engine.dart @@ -134,8 +134,7 @@ class NativeEngine extends AiEngine { Future setOptions() async { await send('setoption name Shuffling value ${Config.shufflingEnabled}'); - await send( - 'setoption name nTotalPiecesEachSide value ${Config.nTotalPiecesEachSide}'); + await send('setoption name piecesCount value ${Config.piecesCount}'); await send( 'setoption name piecesAtLeastCount value ${Config.piecesAtLeastCount}'); await send( @@ -145,14 +144,14 @@ class NativeEngine extends AiEngine { await send( 'setoption name isDefenderMoveFirst value ${Config.isDefenderMoveFirst}'); await send( - 'setoption name allowRemoveMultiPiecesWhenCloseMultiMill value ${Config.allowRemoveMultiPiecesWhenCloseMultiMill}'); + 'setoption name mayTakeMultiple value ${Config.mayTakeMultiple}'); await send( - 'setoption name allowRemovePieceInMill value ${Config.allowRemovePieceInMill}'); + 'setoption name mayTakeFromMillsAlways value ${Config.mayTakeFromMillsAlways}'); await send( 'setoption name isBlackLoseButNotDrawWhenBoardFull value ${Config.isBlackLoseButNotDrawWhenBoardFull}'); await send( 'setoption name isLoseButNotChangeSideWhenNoWay value ${Config.isLoseButNotChangeSideWhenNoWay}'); - await send('setoption name flyingAllowed value ${Config.flyingAllowed}'); + await send('setoption name mayFly value ${Config.mayFly}'); await send( 'setoption name maxStepsLedToDraw value ${Config.maxStepsLedToDraw}'); } diff --git a/src/ui/flutter/lib/l10n/intl_en.arb b/src/ui/flutter/lib/l10n/intl_en.arb index f472cecf..91242dcc 100644 --- a/src/ui/flutter/lib/l10n/intl_en.arb +++ b/src/ui/flutter/lib/l10n/intl_en.arb @@ -311,8 +311,8 @@ "@rules": { "description": "Rules" }, - "nTotalPiecesEachSide": "Total Pieces Each Side", - "@nTotalPiecesEachSide": { + "piecesCount": "Total Pieces Each Side", + "@piecesCount": { "description": "Total Pieces Each Side" }, "ninePieces": "Nine Pieces", @@ -339,12 +339,12 @@ "@isDefenderMoveFirst": { "description": "Defender Move First" }, - "allowRemoveMultiPiecesWhenCloseMultiMill": "Allow Remove Multi Pieces When Close Multi Mill", - "@allowRemoveMultiPiecesWhenCloseMultiMill": { + "mayTakeMultiple": "Allow Remove Multi Pieces When Close Multi Mill", + "@mayTakeMultiple": { "description": "Allow Remove Multi Pieces When Close Multi Mill" }, - "allowRemovePieceInMill": "Allow Remove Piece In Mill", - "@allowRemovePieceInMill": { + "mayTakeFromMillsAlways": "Allow Remove Piece In Mill", + "@mayTakeFromMillsAlways": { "description": "Allow Remove Piece In Mill" }, "isBlackLoseButNotDrawWhenBoardFull": "Black Lose But Not Draw When Board Full", @@ -355,8 +355,8 @@ "@isLoseButNotChangeSideWhenNoWay": { "description": "Lose But Not Change Side When No Way" }, - "flyingAllowed": "Allow Fly When Remain Three Pieces", - "@flyingAllowed": { + "mayFly": "Allow Fly When Remain Three Pieces", + "@mayFly": { "description": "Allow Fly When Remain Three Pieces" }, "maxStepsLedToDraw": "Max Steps Led To Draw", diff --git a/src/ui/flutter/lib/l10n/intl_zh.arb b/src/ui/flutter/lib/l10n/intl_zh.arb index 5f7fce30..264c0e2d 100644 --- a/src/ui/flutter/lib/l10n/intl_zh.arb +++ b/src/ui/flutter/lib/l10n/intl_zh.arb @@ -77,17 +77,17 @@ "openingBook": "使用开局库", "misc": "其他", "rules": "棋规", - "nTotalPiecesEachSide": "棋子数", + "piecesCount": "棋子数", "ninePieces": "九子", "twelvePieces": "十二子", "piecesAtLeastCount": "少于几个子则输棋", "hasObliqueLines": "斜线", "hasBannedLocations": "禁点", "isDefenderMoveFirst": "后摆子的先走子", - "allowRemoveMultiPiecesWhenCloseMultiMill": "成几个三就吃几个子", - "allowRemovePieceInMill": "允许吃三中的子", + "mayTakeMultiple": "成几个三就吃几个子", + "mayTakeFromMillsAlways": "允许吃三中的子", "isBlackLoseButNotDrawWhenBoardFull": "当棋盘摆满时先摆子的输棋", "isLoseButNotChangeSideWhenNoWay": "当无路可走时输棋", - "flyingAllowed": "剩余三颗子时飞棋", + "mayFly": "剩余三颗子时飞棋", "maxStepsLedToDraw": "连续多少步无吃子则和棋" } \ No newline at end of file diff --git a/src/ui/flutter/lib/mill/position.dart b/src/ui/flutter/lib/mill/position.dart index 041ebdf4..9419f896 100644 --- a/src/ui/flutter/lib/mill/position.dart +++ b/src/ui/flutter/lib/mill/position.dart @@ -384,8 +384,8 @@ class Position { } } - if (pieceOnBoardCount[Color.black] > rule.nTotalPiecesEachSide || - pieceOnBoardCount[Color.white] > rule.nTotalPiecesEachSide) { + if (pieceOnBoardCount[Color.black] > rule.piecesCount || + pieceOnBoardCount[Color.white] > rule.piecesCount) { return -1; } @@ -394,9 +394,9 @@ class Position { int GetNPiecesInHand() { pieceInHandCount[Color.black] = - rule.nTotalPiecesEachSide - pieceOnBoardCount[Color.black]; + rule.piecesCount - pieceOnBoardCount[Color.black]; pieceInHandCount[Color.white] = - rule.nTotalPiecesEachSide - pieceOnBoardCount[Color.white]; + rule.piecesCount - pieceOnBoardCount[Color.white]; return pieceOnBoardCount[Color.black] + pieceOnBoardCount[Color.white]; } @@ -458,7 +458,7 @@ class Position { pieceOnBoardCount[Color.black] = pieceOnBoardCount[Color.white] = 0; pieceInHandCount[Color.black] = - pieceInHandCount[Color.white] = rule.nTotalPiecesEachSide; + pieceInHandCount[Color.white] = rule.piecesCount; pieceToRemoveCount = 0; currentSquare = 0; @@ -553,8 +553,7 @@ class Position { changeSideToMove(); } } else { - pieceToRemoveCount = - rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1; + pieceToRemoveCount = rule.mayTakeMultiple ? n : 1; action = Act.remove; } } else if (phase == Phase.moving) { @@ -564,7 +563,7 @@ class Position { // if illegal if (pieceOnBoardCount[sideToMove()] > rule.piecesAtLeastCount || - !rule.flyingAllowed) { + !rule.mayFly) { int md; for (md = 0; md < moveDirectionNumber; md++) { @@ -606,8 +605,7 @@ class Position { return true; } } else { - pieceToRemoveCount = - rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1; + pieceToRemoveCount = rule.mayTakeMultiple ? n : 1; action = Act.remove; } } else { @@ -627,7 +625,7 @@ class Position { // if piece is not their if (!(Color.opponent(sideToMove()) == board[s])) return false; - if (!rule.allowRemovePieceInMill && + if (!rule.mayTakeFromMillsAlways && inHowManyMills(s, Color.nobody) > 0 && !isAllInMills(Color.opponent(sideToMove()))) { return false; @@ -1418,7 +1416,7 @@ class Position { // Can fly if (pieceOnBoardCount[sideToMove()] <= rule.piecesAtLeastCount && - rule.flyingAllowed) { + rule.mayFly) { //print("Can fly."); return false; } diff --git a/src/ui/flutter/lib/mill/rule.dart b/src/ui/flutter/lib/mill/rule.dart index f82132d1..e8f61c69 100644 --- a/src/ui/flutter/lib/mill/rule.dart +++ b/src/ui/flutter/lib/mill/rule.dart @@ -19,16 +19,16 @@ class Rule { String name = "Da San Qi"; String description; - int nTotalPiecesEachSide = 12; // 9 or 12 + int piecesCount = 12; // 9 or 12 int piecesAtLeastCount = 3; // Default is 3 bool hasObliqueLines = true; bool hasBannedLocations = true; bool isDefenderMoveFirst = true; - bool allowRemoveMultiPiecesWhenCloseMultiMill = false; - bool allowRemovePieceInMill = true; + bool mayTakeMultiple = false; + bool mayTakeFromMillsAlways = true; bool isBlackLoseButNotDrawWhenBoardFull = true; bool isLoseButNotChangeSideWhenNoWay = true; - bool flyingAllowed = false; + bool mayFly = false; int maxStepsLedToDraw = 0; } diff --git a/src/ui/flutter/lib/widgets/settings_page.dart b/src/ui/flutter/lib/widgets/settings_page.dart index 64aefb49..da246bd6 100644 --- a/src/ui/flutter/lib/widgets/settings_page.dart +++ b/src/ui/flutter/lib/widgets/settings_page.dart @@ -200,13 +200,12 @@ class _SettingsPageState extends State { setNTotalPiecesEachSide() { // - callback(int nTotalPiecesEachSide) async { + callback(int piecesCount) async { // Navigator.of(context).pop(); setState(() { - rule.nTotalPiecesEachSide = - Config.nTotalPiecesEachSide = nTotalPiecesEachSide; + rule.piecesCount = Config.piecesCount = piecesCount; }); Config.save(); @@ -221,7 +220,7 @@ class _SettingsPageState extends State { RadioListTile( activeColor: UIColors.primaryColor, title: Text('6'), - groupValue: Config.nTotalPiecesEachSide, + groupValue: Config.piecesCount, value: 6, onChanged: callback, ), @@ -229,7 +228,7 @@ class _SettingsPageState extends State { RadioListTile( activeColor: UIColors.primaryColor, title: Text('9'), - groupValue: Config.nTotalPiecesEachSide, + groupValue: Config.piecesCount, value: 9, onChanged: callback, ), @@ -237,7 +236,7 @@ class _SettingsPageState extends State { RadioListTile( activeColor: UIColors.primaryColor, title: Text('12'), - groupValue: Config.nTotalPiecesEachSide, + groupValue: Config.piecesCount, value: 12, onChanged: callback, ), @@ -287,8 +286,7 @@ class _SettingsPageState extends State { setAllowRemoveMultiPiecesWhenCloseMultiMill(bool value) async { // setState(() { - rule.allowRemoveMultiPiecesWhenCloseMultiMill = - Config.allowRemoveMultiPiecesWhenCloseMultiMill = value; + rule.mayTakeMultiple = Config.mayTakeMultiple = value; }); Config.save(); @@ -297,7 +295,7 @@ class _SettingsPageState extends State { setAllowRemovePieceInMill(bool value) async { // setState(() { - rule.allowRemovePieceInMill = Config.allowRemovePieceInMill = value; + rule.mayTakeFromMillsAlways = Config.mayTakeFromMillsAlways = value; }); Config.save(); @@ -326,7 +324,7 @@ class _SettingsPageState extends State { setAllowFlyingAllowed(bool value) async { // setState(() { - rule.flyingAllowed = Config.flyingAllowed = value; + rule.mayFly = Config.mayFly = value; }); Config.save(); @@ -556,13 +554,12 @@ class _SettingsPageState extends State { child: Column( children: [ ListTile( - title: Text(S.of(context).nTotalPiecesEachSide, - style: itemStyle), + title: Text(S.of(context).piecesCount, style: itemStyle), trailing: Row(mainAxisSize: MainAxisSize.min, children: [ - Text(Config.nTotalPiecesEachSide == 6 + Text(Config.piecesCount == 6 ? '6' - : Config.nTotalPiecesEachSide == 9 + : Config.piecesCount == 9 ? '9' : '12'), Icon(Icons.keyboard_arrow_right, @@ -597,17 +594,16 @@ class _SettingsPageState extends State { _buildDivider(), SwitchListTile( activeColor: UIColors.primaryColor, - value: Config.allowRemoveMultiPiecesWhenCloseMultiMill, - title: Text( - S.of(context).allowRemoveMultiPiecesWhenCloseMultiMill, - style: itemStyle), + value: Config.mayTakeMultiple, + title: + Text(S.of(context).mayTakeMultiple, style: itemStyle), onChanged: setAllowRemoveMultiPiecesWhenCloseMultiMill, ), _buildDivider(), SwitchListTile( activeColor: UIColors.primaryColor, - value: Config.allowRemovePieceInMill, - title: Text(S.of(context).allowRemovePieceInMill, + value: Config.mayTakeFromMillsAlways, + title: Text(S.of(context).mayTakeFromMillsAlways, style: itemStyle), onChanged: setAllowRemovePieceInMill, ), @@ -631,8 +627,8 @@ class _SettingsPageState extends State { _buildDivider(), SwitchListTile( activeColor: UIColors.primaryColor, - value: Config.flyingAllowed, - title: Text(S.of(context).flyingAllowed, style: itemStyle), + value: Config.mayFly, + title: Text(S.of(context).mayFly, style: itemStyle), onChanged: setAllowFlyingAllowed, ), _buildDivider(), diff --git a/src/ui/qt/game.cpp b/src/ui/qt/game.cpp index f6cb769a..4aabdf45 100644 --- a/src/ui/qt/game.cpp +++ b/src/ui/qt/game.cpp @@ -233,7 +233,7 @@ void Game::gameReset() PieceItem::Models md; PieceItem *newP; - for (int i = 0; i < rule.nTotalPiecesEachSide; i++) { + for (int i = 0; i < rule.piecesCount; i++) { // 先手的棋子 md = isInverted ? PieceItem::Models::whitePiece : PieceItem::Models::blackPiece; newP = new PieceItem; @@ -1237,7 +1237,7 @@ bool Game::updateScence(Position &p) int key; // 棋子总数 - int nTotalPieces = rule.nTotalPiecesEachSide * 2; + int nTotalPieces = rule.piecesCount * 2; // 动画组 auto *animationGroup = new QParallelAnimationGroup;