refactor: rules: Rename some val

Reference: Morris (Author: Dirk Farin)
This commit is contained in:
Calcitem 2020-12-31 02:33:46 +08:00
parent 91a06e2ed0
commit 90ca5f0e49
16 changed files with 109 additions and 116 deletions

View File

@ -277,12 +277,12 @@ void move_priority_list_shuffle()
std::array<Square, 4> movePriorityList2; std::array<Square, 4> movePriorityList2;
std::array<Square, 8> movePriorityList3; std::array<Square, 8> movePriorityList3;
if (rule.nTotalPiecesEachSide == 9) { if (rule.piecesCount == 9) {
movePriorityList0 = { SQ_16, SQ_18, SQ_20, SQ_22 }; 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 }; 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 }; 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 }; 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 }; 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 }; 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 }; movePriorityList2 = { SQ_16, SQ_18, SQ_20, SQ_22 };

View File

@ -61,7 +61,7 @@ ExtMove *generate<MOVE>(Position &pos, ExtMove *moveList)
} }
if (pos.piece_on_board_count(pos.side_to_move()) > rule.piecesAtLeastCount || 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) { 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]);
if (to && !pos.get_board()[to]) { if (to && !pos.get_board()[to]) {
@ -107,7 +107,7 @@ ExtMove *generate<REMOVE>(Position &pos, ExtMove *moveList)
for (auto i = EFFECTIVE_SQUARE_NB - 1; i >= 0; i--) { for (auto i = EFFECTIVE_SQUARE_NB - 1; i >= 0; i--) {
s = MoveList<LEGAL>::movePriorityList[i]; s = MoveList<LEGAL>::movePriorityList[i];
if (pos.get_board()[s] & make_piece(them)) { 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; *cur++ = (Move)-s;
} }
} }

View File

@ -65,7 +65,7 @@ void MovePicker::score()
int nTheirMills = 0; int nTheirMills = 0;
#ifndef SORT_MOVE_WITHOUT_HUMAN_KNOWLEDGES #ifndef SORT_MOVE_WITHOUT_HUMAN_KNOWLEDGES
// TODO: rule.allowRemoveMultiPiecesWhenCloseMultiMill adapt other rules // TODO: rule.mayTakeMultiple adapt other rules
if (type_of(m) != MOVETYPE_REMOVE) { if (type_of(m) != MOVETYPE_REMOVE) {
// all phrase, check if place sq can close mill // all phrase, check if place sq can close mill
if (nOurMills > 0) { if (nOurMills > 0) {
@ -90,7 +90,7 @@ void MovePicker::score()
if (sq % 2 == 0 && nTheirPieces == 3) { if (sq % 2 == 0 && nTheirPieces == 3) {
cur->value += RATING_BLOCK_ONE_MILL * nTheirMills; 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; cur->value += RATING_BLOCK_ONE_MILL * nTheirMills;
} }
} }
@ -100,7 +100,7 @@ void MovePicker::score()
//cur->value += nBanned; // placing phrase, place nearby ban point //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) // 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<ON_BOARD>(WHITE) < 2 && // patch: only when white's 2nd move pos.count<ON_BOARD>(WHITE) < 2 && // patch: only when white's 2nd move
Position::is_star_square(static_cast<Square>(m))) { Position::is_star_square(static_cast<Square>(m))) {
cur->value += RATING_STAR_SQUARE; cur->value += RATING_STAR_SQUARE;

View File

@ -685,8 +685,8 @@ int Position::piece_on_board_count_count()
} }
} }
if (pieceOnBoardCount[BLACK] > rule.nTotalPiecesEachSide || if (pieceOnBoardCount[BLACK] > rule.piecesCount ||
pieceOnBoardCount[WHITE] > rule.nTotalPiecesEachSide) { pieceOnBoardCount[WHITE] > rule.piecesCount) {
return -1; return -1;
} }
@ -695,8 +695,8 @@ int Position::piece_on_board_count_count()
int Position::get_piece_in_hand_count() int Position::get_piece_in_hand_count()
{ {
pieceInHandCount[BLACK] = rule.nTotalPiecesEachSide - pieceOnBoardCount[BLACK]; pieceInHandCount[BLACK] = rule.piecesCount - pieceOnBoardCount[BLACK];
pieceInHandCount[WHITE] = rule.nTotalPiecesEachSide - pieceOnBoardCount[WHITE]; pieceInHandCount[WHITE] = rule.piecesCount - pieceOnBoardCount[WHITE];
return pieceInHandCount[BLACK] + pieceInHandCount[WHITE]; return pieceInHandCount[BLACK] + pieceInHandCount[WHITE];
} }
@ -727,7 +727,7 @@ bool Position::reset()
memset(byColorBB, 0, sizeof(byColorBB)); memset(byColorBB, 0, sizeof(byColorBB));
pieceOnBoardCount[BLACK] = pieceOnBoardCount[WHITE] = 0; pieceOnBoardCount[BLACK] = pieceOnBoardCount[WHITE] = 0;
pieceInHandCount[BLACK] = pieceInHandCount[WHITE] = rule.nTotalPiecesEachSide; pieceInHandCount[BLACK] = pieceInHandCount[WHITE] = rule.piecesCount;
pieceToRemoveCount = 0; pieceToRemoveCount = 0;
millListSize = 0; millListSize = 0;
@ -792,7 +792,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
} }
if (phase == Phase::placing) { 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]--; pieceInHandCount[us]--;
pieceOnBoardCount[us]++; pieceOnBoardCount[us]++;
@ -836,7 +836,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
change_side_to_move(); change_side_to_move();
} }
} else { } else {
pieceToRemoveCount = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1; pieceToRemoveCount = rule.mayTakeMultiple ? n : 1;
update_key_misc(); update_key_misc();
action = Action::remove; action = Action::remove;
} }
@ -849,7 +849,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
// if illegal // if illegal
if (pieceOnBoardCount[sideToMove] > rule.piecesAtLeastCount || if (pieceOnBoardCount[sideToMove] > rule.piecesAtLeastCount ||
!rule.flyingAllowed) { !rule.mayFly) {
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 {
pieceToRemoveCount = rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1; pieceToRemoveCount = rule.mayTakeMultiple ? n : 1;
update_key_misc(); update_key_misc();
action = Action::remove; action = Action::remove;
} }
@ -916,7 +916,7 @@ bool Position::remove_piece(Square s, bool updateCmdlist)
if (!(make_piece(~side_to_move()) & board[s])) if (!(make_piece(~side_to_move()) & board[s]))
return false; return false;
if (!rule.allowRemovePieceInMill && if (!rule.mayTakeFromMillsAlways &&
in_how_many_mills(s, NOBODY) && in_how_many_mills(s, NOBODY) &&
!is_all_in_mills(~sideToMove)) { !is_all_in_mills(~sideToMove)) {
return false; return false;
@ -1487,7 +1487,7 @@ int Position::surrounded_empty_squares_count(Square s, bool includeFobidden)
int n = 0; int n = 0;
if (pieceOnBoardCount[sideToMove] > rule.piecesAtLeastCount || if (pieceOnBoardCount[sideToMove] > rule.piecesAtLeastCount ||
!rule.flyingAllowed) { !rule.mayFly) {
Square moveSquare; Square moveSquare;
for (MoveDirection d = MD_BEGIN; d < MD_NB; ++d) { for (MoveDirection d = MD_BEGIN; d < MD_NB; ++d) {
moveSquare = static_cast<Square>(MoveList<LEGAL>::adjacentSquares[s][d]); moveSquare = static_cast<Square>(MoveList<LEGAL>::adjacentSquares[s][d]);
@ -1542,7 +1542,7 @@ bool Position::is_all_surrounded() const
// Can fly // Can fly
if (pieceOnBoardCount[sideToMove] <= rule.piecesAtLeastCount && if (pieceOnBoardCount[sideToMove] <= rule.piecesAtLeastCount &&
rule.flyingAllowed) { rule.mayFly) {
return false; return false;
} }
@ -1573,7 +1573,7 @@ bool Position::is_star_square(Square s)
void Position::print_board() void Position::print_board()
{ {
if (rule.nTotalPiecesEachSide == 12) { if (rule.piecesCount == 12) {
printf("\n" printf("\n"
"31 ----- 24 ----- 25\n" "31 ----- 24 ----- 25\n"
"| \\ | / |\n" "| \\ | / |\n"

View File

@ -21,13 +21,15 @@
#include "types.h" #include "types.h"
// The rule struct manages the various variants of the rules.
struct Rule struct Rule
{ {
const char name[32]; const char name[32];
const char description[512]; 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 int piecesAtLeastCount; // Default is 3
@ -37,16 +39,18 @@ struct Rule
bool isDefenderMoveFirst; 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 isBlackLoseButNotDrawWhenBoardFull;
bool isLoseButNotChangeSideWhenNoWay; bool isLoseButNotChangeSideWhenNoWay;
// Specifies if jumps are allowed when a player remains with three pieces on the board. // Player may fly if he is down to three pieces.
bool flyingAllowed; bool mayFly;
int maxStepsLedToDraw; int maxStepsLedToDraw;
}; };

View File

@ -439,9 +439,9 @@ Depth Thread::adjustDepth()
const Depth flyingDepth = 9; const Depth flyingDepth = 9;
if (rootPos->phase == Phase::placing) { if (rootPos->phase == Phase::placing) {
int index = rule.nTotalPiecesEachSide * 2 - rootPos->count<IN_HAND>(BLACK) - rootPos->count<IN_HAND>(WHITE); int index = rule.piecesCount * 2 - rootPos->count<IN_HAND>(BLACK) - rootPos->count<IN_HAND>(WHITE);
if (rule.nTotalPiecesEachSide == 12) { if (rule.piecesCount == 12) {
assert(0 <= index && index <= 24); assert(0 <= index && index <= 24);
d = placingDepthTable_12[index]; d = placingDepthTable_12[index];
} else { } else {
@ -468,7 +468,7 @@ Depth Thread::adjustDepth()
} }
// Can fly // Can fly
if (rule.flyingAllowed) { if (rule.mayFly) {
if (pb == rule.piecesAtLeastCount || if (pb == rule.piecesAtLeastCount ||
pw == rule.piecesAtLeastCount) { pw == rule.piecesAtLeastCount) {
d = flyingDepth; d = flyingDepth;

View File

@ -156,7 +156,7 @@ enum class Phase : uint16_t
// - move a piece on the board: // - move a piece on the board:
// - slide a piece between two adjacent locations; // - slide a piece between two adjacent locations;
// - 'jump' a piece to any empty location if the player has less than // - '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; // - remove an opponent's piece after successfully closing a mill;
enum class Action : uint16_t enum class Action : uint16_t
{ {

View File

@ -67,9 +67,9 @@ void on_random_move(const Option &o)
// Rules // 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) void on_piecesAtLeastCount(const Option &o)
@ -92,14 +92,14 @@ void on_isDefenderMoveFirst(const Option &o)
rule.isDefenderMoveFirst = (bool)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) void on_isBlackLoseButNotDrawWhenBoardFull(const Option &o)
@ -112,9 +112,9 @@ void on_isLoseButNotChangeSideWhenNoWay(const Option &o)
rule.isLoseButNotChangeSideWhenNoWay = (bool)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) void on_maxStepsLedToDraw(const Option &o)
@ -156,16 +156,16 @@ void init(OptionsMap &o)
o["Shuffling"] << Option(true, on_random_move); o["Shuffling"] << Option(true, on_random_move);
// Rules // 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["piecesAtLeastCount"] << Option(3, 3, 5, on_piecesAtLeastCount);
o["hasObliqueLines"] << Option(true, on_hasObliqueLines); o["hasObliqueLines"] << Option(true, on_hasObliqueLines);
o["hasBannedLocations"] << Option(true, on_hasBannedLocations); o["hasBannedLocations"] << Option(true, on_hasBannedLocations);
o["isDefenderMoveFirst"] << Option(true, on_isDefenderMoveFirst); o["isDefenderMoveFirst"] << Option(true, on_isDefenderMoveFirst);
o["allowRemoveMultiPiecesWhenCloseMultiMill"] << Option(false, on_allowRemoveMultiPiecesWhenCloseMultiMill); o["mayTakeMultiple"] << Option(false, on_mayTakeMultiple);
o["allowRemovePieceInMill"] << Option(true, on_allowRemovePieceInMill); o["mayTakeFromMillsAlways"] << Option(true, on_mayTakeFromMillsAlways);
o["isBlackLoseButNotDrawWhenBoardFull"] << Option(true, on_isBlackLoseButNotDrawWhenBoardFull); o["isBlackLoseButNotDrawWhenBoardFull"] << Option(true, on_isBlackLoseButNotDrawWhenBoardFull);
o["isLoseButNotChangeSideWhenNoWay"] << Option(true, on_isLoseButNotChangeSideWhenNoWay); 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); o["maxStepsLedToDraw"] << Option(50, 30, 50, on_maxStepsLedToDraw);
} }

View File

@ -37,16 +37,16 @@ class Config {
static bool openingBook = false; static bool openingBook = false;
// Rules // Rules
static int nTotalPiecesEachSide = 12; static int piecesCount = 12;
static int piecesAtLeastCount = 3; static int piecesAtLeastCount = 3;
static bool hasObliqueLines = true; static bool hasObliqueLines = true;
static bool hasBannedLocations = true; static bool hasBannedLocations = true;
static bool isDefenderMoveFirst = true; static bool isDefenderMoveFirst = true;
static bool allowRemoveMultiPiecesWhenCloseMultiMill = false; static bool mayTakeMultiple = false;
static bool allowRemovePieceInMill = true; static bool mayTakeFromMillsAlways = true;
static bool isBlackLoseButNotDrawWhenBoardFull = true; static bool isBlackLoseButNotDrawWhenBoardFull = true;
static bool isLoseButNotChangeSideWhenNoWay = true; static bool isLoseButNotChangeSideWhenNoWay = true;
static bool flyingAllowed = false; static bool mayFly = false;
static int maxStepsLedToDraw = 50; static int maxStepsLedToDraw = 50;
static Future<void> loadProfile() async { static Future<void> loadProfile() async {
@ -67,8 +67,7 @@ class Config {
Config.openingBook = profile['openingBook'] ?? false; Config.openingBook = profile['openingBook'] ?? false;
// Rules // Rules
rule.nTotalPiecesEachSide = rule.piecesCount = Config.piecesCount = profile['piecesCount'] ?? 12;
Config.nTotalPiecesEachSide = profile['nTotalPiecesEachSide'] ?? 12;
rule.piecesAtLeastCount = rule.piecesAtLeastCount =
Config.piecesAtLeastCount = profile['piecesAtLeastCount'] ?? 3; Config.piecesAtLeastCount = profile['piecesAtLeastCount'] ?? 3;
rule.hasObliqueLines = rule.hasObliqueLines =
@ -77,19 +76,17 @@ class Config {
Config.hasBannedLocations = profile['hasBannedLocations'] ?? true; Config.hasBannedLocations = profile['hasBannedLocations'] ?? true;
rule.isDefenderMoveFirst = rule.isDefenderMoveFirst =
Config.isDefenderMoveFirst = profile['isDefenderMoveFirst'] ?? true; Config.isDefenderMoveFirst = profile['isDefenderMoveFirst'] ?? true;
rule.allowRemoveMultiPiecesWhenCloseMultiMill = rule.mayTakeMultiple =
Config.allowRemoveMultiPiecesWhenCloseMultiMill = Config.mayTakeMultiple = profile['mayTakeMultiple'] ?? false;
profile['allowRemoveMultiPiecesWhenCloseMultiMill'] ?? false; rule.mayTakeFromMillsAlways = Config.mayTakeFromMillsAlways =
rule.allowRemovePieceInMill = Config.allowRemovePieceInMill = profile['mayTakeFromMillsAlways'] ?? true;
profile['allowRemovePieceInMill'] ?? true;
rule.isBlackLoseButNotDrawWhenBoardFull = rule.isBlackLoseButNotDrawWhenBoardFull =
Config.isBlackLoseButNotDrawWhenBoardFull = Config.isBlackLoseButNotDrawWhenBoardFull =
profile['isBlackLoseButNotDrawWhenBoardFull'] ?? true; profile['isBlackLoseButNotDrawWhenBoardFull'] ?? true;
rule.isLoseButNotChangeSideWhenNoWay = rule.isLoseButNotChangeSideWhenNoWay =
Config.isLoseButNotChangeSideWhenNoWay = Config.isLoseButNotChangeSideWhenNoWay =
profile['isLoseButNotChangeSideWhenNoWay'] ?? true; profile['isLoseButNotChangeSideWhenNoWay'] ?? true;
rule.flyingAllowed = rule.mayFly = Config.mayFly = profile['mayFly'] ?? false;
Config.flyingAllowed = profile['flyingAllowed'] ?? false;
rule.maxStepsLedToDraw = rule.maxStepsLedToDraw =
Config.maxStepsLedToDraw = profile['maxStepsLedToDraw'] ?? 50; Config.maxStepsLedToDraw = profile['maxStepsLedToDraw'] ?? 50;
@ -114,19 +111,18 @@ class Config {
profile['openingBook'] = Config.openingBook; profile['openingBook'] = Config.openingBook;
// Rules // Rules
profile['nTotalPiecesEachSide'] = Config.nTotalPiecesEachSide; profile['piecesCount'] = Config.piecesCount;
profile['piecesAtLeastCount'] = Config.piecesAtLeastCount; profile['piecesAtLeastCount'] = Config.piecesAtLeastCount;
profile['hasObliqueLines'] = Config.hasObliqueLines; profile['hasObliqueLines'] = Config.hasObliqueLines;
profile['hasBannedLocations'] = Config.hasBannedLocations; profile['hasBannedLocations'] = Config.hasBannedLocations;
profile['isDefenderMoveFirst'] = Config.isDefenderMoveFirst; profile['isDefenderMoveFirst'] = Config.isDefenderMoveFirst;
profile['allowRemoveMultiPiecesWhenCloseMultiMill'] = profile['mayTakeMultiple'] = Config.mayTakeMultiple;
Config.allowRemoveMultiPiecesWhenCloseMultiMill; profile['mayTakeFromMillsAlways'] = Config.mayTakeFromMillsAlways;
profile['allowRemovePieceInMill'] = Config.allowRemovePieceInMill;
profile['isBlackLoseButNotDrawWhenBoardFull'] = profile['isBlackLoseButNotDrawWhenBoardFull'] =
Config.isBlackLoseButNotDrawWhenBoardFull; Config.isBlackLoseButNotDrawWhenBoardFull;
profile['isLoseButNotChangeSideWhenNoWay'] = profile['isLoseButNotChangeSideWhenNoWay'] =
Config.isLoseButNotChangeSideWhenNoWay; Config.isLoseButNotChangeSideWhenNoWay;
profile['flyingAllowed'] = Config.flyingAllowed; profile['mayFly'] = Config.mayFly;
profile['maxStepsLedToDraw'] = Config.maxStepsLedToDraw; profile['maxStepsLedToDraw'] = Config.maxStepsLedToDraw;
profile.commit(); profile.commit();

View File

@ -134,8 +134,7 @@ class NativeEngine extends AiEngine {
Future<void> setOptions() async { Future<void> setOptions() async {
await send('setoption name Shuffling value ${Config.shufflingEnabled}'); await send('setoption name Shuffling value ${Config.shufflingEnabled}');
await send( await send('setoption name piecesCount value ${Config.piecesCount}');
'setoption name nTotalPiecesEachSide value ${Config.nTotalPiecesEachSide}');
await send( await send(
'setoption name piecesAtLeastCount value ${Config.piecesAtLeastCount}'); 'setoption name piecesAtLeastCount value ${Config.piecesAtLeastCount}');
await send( await send(
@ -145,14 +144,14 @@ class NativeEngine extends AiEngine {
await send( await send(
'setoption name isDefenderMoveFirst value ${Config.isDefenderMoveFirst}'); 'setoption name isDefenderMoveFirst value ${Config.isDefenderMoveFirst}');
await send( await send(
'setoption name allowRemoveMultiPiecesWhenCloseMultiMill value ${Config.allowRemoveMultiPiecesWhenCloseMultiMill}'); 'setoption name mayTakeMultiple value ${Config.mayTakeMultiple}');
await send( await send(
'setoption name allowRemovePieceInMill value ${Config.allowRemovePieceInMill}'); 'setoption name mayTakeFromMillsAlways value ${Config.mayTakeFromMillsAlways}');
await send( await send(
'setoption name isBlackLoseButNotDrawWhenBoardFull value ${Config.isBlackLoseButNotDrawWhenBoardFull}'); 'setoption name isBlackLoseButNotDrawWhenBoardFull value ${Config.isBlackLoseButNotDrawWhenBoardFull}');
await send( await send(
'setoption name isLoseButNotChangeSideWhenNoWay value ${Config.isLoseButNotChangeSideWhenNoWay}'); 'setoption name isLoseButNotChangeSideWhenNoWay value ${Config.isLoseButNotChangeSideWhenNoWay}');
await send('setoption name flyingAllowed value ${Config.flyingAllowed}'); await send('setoption name mayFly value ${Config.mayFly}');
await send( await send(
'setoption name maxStepsLedToDraw value ${Config.maxStepsLedToDraw}'); 'setoption name maxStepsLedToDraw value ${Config.maxStepsLedToDraw}');
} }

View File

@ -311,8 +311,8 @@
"@rules": { "@rules": {
"description": "Rules" "description": "Rules"
}, },
"nTotalPiecesEachSide": "Total Pieces Each Side", "piecesCount": "Total Pieces Each Side",
"@nTotalPiecesEachSide": { "@piecesCount": {
"description": "Total Pieces Each Side" "description": "Total Pieces Each Side"
}, },
"ninePieces": "Nine Pieces", "ninePieces": "Nine Pieces",
@ -339,12 +339,12 @@
"@isDefenderMoveFirst": { "@isDefenderMoveFirst": {
"description": "Defender Move First" "description": "Defender Move First"
}, },
"allowRemoveMultiPiecesWhenCloseMultiMill": "Allow Remove Multi Pieces When Close Multi Mill", "mayTakeMultiple": "Allow Remove Multi Pieces When Close Multi Mill",
"@allowRemoveMultiPiecesWhenCloseMultiMill": { "@mayTakeMultiple": {
"description": "Allow Remove Multi Pieces When Close Multi Mill" "description": "Allow Remove Multi Pieces When Close Multi Mill"
}, },
"allowRemovePieceInMill": "Allow Remove Piece In Mill", "mayTakeFromMillsAlways": "Allow Remove Piece In Mill",
"@allowRemovePieceInMill": { "@mayTakeFromMillsAlways": {
"description": "Allow Remove Piece In Mill" "description": "Allow Remove Piece In Mill"
}, },
"isBlackLoseButNotDrawWhenBoardFull": "Black Lose But Not Draw When Board Full", "isBlackLoseButNotDrawWhenBoardFull": "Black Lose But Not Draw When Board Full",
@ -355,8 +355,8 @@
"@isLoseButNotChangeSideWhenNoWay": { "@isLoseButNotChangeSideWhenNoWay": {
"description": "Lose But Not Change Side When No Way" "description": "Lose But Not Change Side When No Way"
}, },
"flyingAllowed": "Allow Fly When Remain Three Pieces", "mayFly": "Allow Fly When Remain Three Pieces",
"@flyingAllowed": { "@mayFly": {
"description": "Allow Fly When Remain Three Pieces" "description": "Allow Fly When Remain Three Pieces"
}, },
"maxStepsLedToDraw": "Max Steps Led To Draw", "maxStepsLedToDraw": "Max Steps Led To Draw",

View File

@ -77,17 +77,17 @@
"openingBook": "使用开局库", "openingBook": "使用开局库",
"misc": "其他", "misc": "其他",
"rules": "棋规", "rules": "棋规",
"nTotalPiecesEachSide": "棋子数", "piecesCount": "棋子数",
"ninePieces": "九子", "ninePieces": "九子",
"twelvePieces": "十二子", "twelvePieces": "十二子",
"piecesAtLeastCount": "少于几个子则输棋", "piecesAtLeastCount": "少于几个子则输棋",
"hasObliqueLines": "斜线", "hasObliqueLines": "斜线",
"hasBannedLocations": "禁点", "hasBannedLocations": "禁点",
"isDefenderMoveFirst": "后摆子的先走子", "isDefenderMoveFirst": "后摆子的先走子",
"allowRemoveMultiPiecesWhenCloseMultiMill": "成几个三就吃几个子", "mayTakeMultiple": "成几个三就吃几个子",
"allowRemovePieceInMill": "允许吃三中的子", "mayTakeFromMillsAlways": "允许吃三中的子",
"isBlackLoseButNotDrawWhenBoardFull": "当棋盘摆满时先摆子的输棋", "isBlackLoseButNotDrawWhenBoardFull": "当棋盘摆满时先摆子的输棋",
"isLoseButNotChangeSideWhenNoWay": "当无路可走时输棋", "isLoseButNotChangeSideWhenNoWay": "当无路可走时输棋",
"flyingAllowed": "剩余三颗子时飞棋", "mayFly": "剩余三颗子时飞棋",
"maxStepsLedToDraw": "连续多少步无吃子则和棋" "maxStepsLedToDraw": "连续多少步无吃子则和棋"
} }

View File

@ -384,8 +384,8 @@ class Position {
} }
} }
if (pieceOnBoardCount[Color.black] > rule.nTotalPiecesEachSide || if (pieceOnBoardCount[Color.black] > rule.piecesCount ||
pieceOnBoardCount[Color.white] > rule.nTotalPiecesEachSide) { pieceOnBoardCount[Color.white] > rule.piecesCount) {
return -1; return -1;
} }
@ -394,9 +394,9 @@ class Position {
int GetNPiecesInHand() { int GetNPiecesInHand() {
pieceInHandCount[Color.black] = pieceInHandCount[Color.black] =
rule.nTotalPiecesEachSide - pieceOnBoardCount[Color.black]; rule.piecesCount - pieceOnBoardCount[Color.black];
pieceInHandCount[Color.white] = pieceInHandCount[Color.white] =
rule.nTotalPiecesEachSide - pieceOnBoardCount[Color.white]; rule.piecesCount - pieceOnBoardCount[Color.white];
return pieceOnBoardCount[Color.black] + pieceOnBoardCount[Color.white]; return pieceOnBoardCount[Color.black] + pieceOnBoardCount[Color.white];
} }
@ -458,7 +458,7 @@ class Position {
pieceOnBoardCount[Color.black] = pieceOnBoardCount[Color.white] = 0; pieceOnBoardCount[Color.black] = pieceOnBoardCount[Color.white] = 0;
pieceInHandCount[Color.black] = pieceInHandCount[Color.black] =
pieceInHandCount[Color.white] = rule.nTotalPiecesEachSide; pieceInHandCount[Color.white] = rule.piecesCount;
pieceToRemoveCount = 0; pieceToRemoveCount = 0;
currentSquare = 0; currentSquare = 0;
@ -553,8 +553,7 @@ class Position {
changeSideToMove(); changeSideToMove();
} }
} else { } else {
pieceToRemoveCount = pieceToRemoveCount = rule.mayTakeMultiple ? n : 1;
rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
action = Act.remove; action = Act.remove;
} }
} else if (phase == Phase.moving) { } else if (phase == Phase.moving) {
@ -564,7 +563,7 @@ class Position {
// if illegal // if illegal
if (pieceOnBoardCount[sideToMove()] > rule.piecesAtLeastCount || if (pieceOnBoardCount[sideToMove()] > rule.piecesAtLeastCount ||
!rule.flyingAllowed) { !rule.mayFly) {
int md; int md;
for (md = 0; md < moveDirectionNumber; md++) { for (md = 0; md < moveDirectionNumber; md++) {
@ -606,8 +605,7 @@ class Position {
return true; return true;
} }
} else { } else {
pieceToRemoveCount = pieceToRemoveCount = rule.mayTakeMultiple ? n : 1;
rule.allowRemoveMultiPiecesWhenCloseMultiMill ? n : 1;
action = Act.remove; action = Act.remove;
} }
} else { } else {
@ -627,7 +625,7 @@ class Position {
// 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;
if (!rule.allowRemovePieceInMill && if (!rule.mayTakeFromMillsAlways &&
inHowManyMills(s, Color.nobody) > 0 && inHowManyMills(s, Color.nobody) > 0 &&
!isAllInMills(Color.opponent(sideToMove()))) { !isAllInMills(Color.opponent(sideToMove()))) {
return false; return false;
@ -1418,7 +1416,7 @@ class Position {
// Can fly // Can fly
if (pieceOnBoardCount[sideToMove()] <= rule.piecesAtLeastCount && if (pieceOnBoardCount[sideToMove()] <= rule.piecesAtLeastCount &&
rule.flyingAllowed) { rule.mayFly) {
//print("Can fly."); //print("Can fly.");
return false; return false;
} }

View File

@ -19,16 +19,16 @@
class Rule { class Rule {
String name = "Da San Qi"; String name = "Da San Qi";
String description; String description;
int nTotalPiecesEachSide = 12; // 9 or 12 int piecesCount = 12; // 9 or 12
int piecesAtLeastCount = 3; // Default is 3 int piecesAtLeastCount = 3; // Default is 3
bool hasObliqueLines = true; bool hasObliqueLines = true;
bool hasBannedLocations = true; bool hasBannedLocations = true;
bool isDefenderMoveFirst = true; bool isDefenderMoveFirst = true;
bool allowRemoveMultiPiecesWhenCloseMultiMill = false; bool mayTakeMultiple = false;
bool allowRemovePieceInMill = true; bool mayTakeFromMillsAlways = true;
bool isBlackLoseButNotDrawWhenBoardFull = true; bool isBlackLoseButNotDrawWhenBoardFull = true;
bool isLoseButNotChangeSideWhenNoWay = true; bool isLoseButNotChangeSideWhenNoWay = true;
bool flyingAllowed = false; bool mayFly = false;
int maxStepsLedToDraw = 0; int maxStepsLedToDraw = 0;
} }

View File

@ -200,13 +200,12 @@ class _SettingsPageState extends State<SettingsPage> {
setNTotalPiecesEachSide() { setNTotalPiecesEachSide() {
// //
callback(int nTotalPiecesEachSide) async { callback(int piecesCount) async {
// //
Navigator.of(context).pop(); Navigator.of(context).pop();
setState(() { setState(() {
rule.nTotalPiecesEachSide = rule.piecesCount = Config.piecesCount = piecesCount;
Config.nTotalPiecesEachSide = nTotalPiecesEachSide;
}); });
Config.save(); Config.save();
@ -221,7 +220,7 @@ class _SettingsPageState extends State<SettingsPage> {
RadioListTile( RadioListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
title: Text('6'), title: Text('6'),
groupValue: Config.nTotalPiecesEachSide, groupValue: Config.piecesCount,
value: 6, value: 6,
onChanged: callback, onChanged: callback,
), ),
@ -229,7 +228,7 @@ class _SettingsPageState extends State<SettingsPage> {
RadioListTile( RadioListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
title: Text('9'), title: Text('9'),
groupValue: Config.nTotalPiecesEachSide, groupValue: Config.piecesCount,
value: 9, value: 9,
onChanged: callback, onChanged: callback,
), ),
@ -237,7 +236,7 @@ class _SettingsPageState extends State<SettingsPage> {
RadioListTile( RadioListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
title: Text('12'), title: Text('12'),
groupValue: Config.nTotalPiecesEachSide, groupValue: Config.piecesCount,
value: 12, value: 12,
onChanged: callback, onChanged: callback,
), ),
@ -287,8 +286,7 @@ class _SettingsPageState extends State<SettingsPage> {
setAllowRemoveMultiPiecesWhenCloseMultiMill(bool value) async { setAllowRemoveMultiPiecesWhenCloseMultiMill(bool value) async {
// //
setState(() { setState(() {
rule.allowRemoveMultiPiecesWhenCloseMultiMill = rule.mayTakeMultiple = Config.mayTakeMultiple = value;
Config.allowRemoveMultiPiecesWhenCloseMultiMill = value;
}); });
Config.save(); Config.save();
@ -297,7 +295,7 @@ class _SettingsPageState extends State<SettingsPage> {
setAllowRemovePieceInMill(bool value) async { setAllowRemovePieceInMill(bool value) async {
// //
setState(() { setState(() {
rule.allowRemovePieceInMill = Config.allowRemovePieceInMill = value; rule.mayTakeFromMillsAlways = Config.mayTakeFromMillsAlways = value;
}); });
Config.save(); Config.save();
@ -326,7 +324,7 @@ class _SettingsPageState extends State<SettingsPage> {
setAllowFlyingAllowed(bool value) async { setAllowFlyingAllowed(bool value) async {
// //
setState(() { setState(() {
rule.flyingAllowed = Config.flyingAllowed = value; rule.mayFly = Config.mayFly = value;
}); });
Config.save(); Config.save();
@ -556,13 +554,12 @@ class _SettingsPageState extends State<SettingsPage> {
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
ListTile( ListTile(
title: Text(S.of(context).nTotalPiecesEachSide, title: Text(S.of(context).piecesCount, style: itemStyle),
style: itemStyle),
trailing: trailing:
Row(mainAxisSize: MainAxisSize.min, children: <Widget>[ Row(mainAxisSize: MainAxisSize.min, children: <Widget>[
Text(Config.nTotalPiecesEachSide == 6 Text(Config.piecesCount == 6
? '6' ? '6'
: Config.nTotalPiecesEachSide == 9 : Config.piecesCount == 9
? '9' ? '9'
: '12'), : '12'),
Icon(Icons.keyboard_arrow_right, Icon(Icons.keyboard_arrow_right,
@ -597,17 +594,16 @@ class _SettingsPageState extends State<SettingsPage> {
_buildDivider(), _buildDivider(),
SwitchListTile( SwitchListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.allowRemoveMultiPiecesWhenCloseMultiMill, value: Config.mayTakeMultiple,
title: Text( title:
S.of(context).allowRemoveMultiPiecesWhenCloseMultiMill, Text(S.of(context).mayTakeMultiple, style: itemStyle),
style: itemStyle),
onChanged: setAllowRemoveMultiPiecesWhenCloseMultiMill, onChanged: setAllowRemoveMultiPiecesWhenCloseMultiMill,
), ),
_buildDivider(), _buildDivider(),
SwitchListTile( SwitchListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.allowRemovePieceInMill, value: Config.mayTakeFromMillsAlways,
title: Text(S.of(context).allowRemovePieceInMill, title: Text(S.of(context).mayTakeFromMillsAlways,
style: itemStyle), style: itemStyle),
onChanged: setAllowRemovePieceInMill, onChanged: setAllowRemovePieceInMill,
), ),
@ -631,8 +627,8 @@ class _SettingsPageState extends State<SettingsPage> {
_buildDivider(), _buildDivider(),
SwitchListTile( SwitchListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.flyingAllowed, value: Config.mayFly,
title: Text(S.of(context).flyingAllowed, style: itemStyle), title: Text(S.of(context).mayFly, style: itemStyle),
onChanged: setAllowFlyingAllowed, onChanged: setAllowFlyingAllowed,
), ),
_buildDivider(), _buildDivider(),

View File

@ -233,7 +233,7 @@ void Game::gameReset()
PieceItem::Models md; PieceItem::Models md;
PieceItem *newP; 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; md = isInverted ? PieceItem::Models::whitePiece : PieceItem::Models::blackPiece;
newP = new PieceItem; newP = new PieceItem;
@ -1237,7 +1237,7 @@ bool Game::updateScence(Position &p)
int key; int key;
// 棋子总数 // 棋子总数
int nTotalPieces = rule.nTotalPiecesEachSide * 2; int nTotalPieces = rule.piecesCount * 2;
// 动画组 // 动画组
auto *animationGroup = new QParallelAnimationGroup; auto *animationGroup = new QParallelAnimationGroup;