refactor: Rename to flyingAllowed

This commit is contained in:
Calcitem 2020-12-30 01:06:43 +08:00
parent 40723f4d94
commit 84d016b3de
12 changed files with 39 additions and 30 deletions

View File

@ -61,7 +61,7 @@ ExtMove *generate<MOVE>(Position &pos, ExtMove *moveList)
} }
if (pos.pieces_count_on_board(pos.side_to_move()) > rule.nPiecesAtLeast || if (pos.pieces_count_on_board(pos.side_to_move()) > rule.nPiecesAtLeast ||
!rule.allowFlyWhenRemainThreePieces) { !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]);
if (to && !pos.get_board()[to]) { if (to && !pos.get_board()[to]) {
@ -69,7 +69,7 @@ ExtMove *generate<MOVE>(Position &pos, ExtMove *moveList)
} }
} }
} else { } else {
// piece count < 3£¬and allow fly, if is empty point, that's ok, do not need in move list // piece count < 3 and allow fly, if is empty point, that's ok, do not need in move list
for (to = SQ_BEGIN; to < SQ_END; ++to) { for (to = SQ_BEGIN; to < SQ_END; ++to) {
if (!pos.get_board()[to]) { if (!pos.get_board()[to]) {
*cur++ = make_move(from, to); *cur++ = make_move(from, to);

View File

@ -849,7 +849,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
// if illegal // if illegal
if (pieceCountOnBoard[sideToMove] > rule.nPiecesAtLeast || if (pieceCountOnBoard[sideToMove] > rule.nPiecesAtLeast ||
!rule.allowFlyWhenRemainThreePieces) { !rule.flyingAllowed) {
if ((square_bb(s) & MoveList<LEGAL>::adjacentSquaresBB[currentSquare]) == 0) { if ((square_bb(s) & MoveList<LEGAL>::adjacentSquaresBB[currentSquare]) == 0) {
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 (pieceCountOnBoard[sideToMove] > rule.nPiecesAtLeast || if (pieceCountOnBoard[sideToMove] > rule.nPiecesAtLeast ||
!rule.allowFlyWhenRemainThreePieces) { !rule.flyingAllowed) {
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 (pieceCountOnBoard[sideToMove] <= rule.nPiecesAtLeast && if (pieceCountOnBoard[sideToMove] <= rule.nPiecesAtLeast &&
rule.allowFlyWhenRemainThreePieces) { rule.flyingAllowed) {
return false; return false;
} }

View File

@ -24,17 +24,30 @@
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 int nTotalPiecesEachSide; // 9 or 12
int nPiecesAtLeast; // Default is 3 int nPiecesAtLeast; // Default is 3
bool hasObliqueLines; bool hasObliqueLines;
bool hasBannedLocations; bool hasBannedLocations;
bool isDefenderMoveFirst; bool isDefenderMoveFirst;
bool allowRemoveMultiPiecesWhenCloseMultiMill; bool allowRemoveMultiPiecesWhenCloseMultiMill;
bool allowRemovePieceInMill; bool allowRemovePieceInMill;
bool isBlackLoseButNotDrawWhenBoardFull; bool isBlackLoseButNotDrawWhenBoardFull;
bool isLoseButNotChangeSideWhenNoWay; bool isLoseButNotChangeSideWhenNoWay;
bool allowFlyWhenRemainThreePieces;
// Specifies if jumps are allowed when a player remains with three pieces on the board.
bool flyingAllowed;
int maxStepsLedToDraw; int maxStepsLedToDraw;
}; };

View File

@ -468,7 +468,7 @@ Depth Thread::adjustDepth()
} }
// Can fly // Can fly
if (rule.allowFlyWhenRemainThreePieces) { if (rule.flyingAllowed) {
if (pb == rule.nPiecesAtLeast || if (pb == rule.nPiecesAtLeast ||
pw == rule.nPiecesAtLeast) { pw == rule.nPiecesAtLeast) {
d = flyingDepth; d = flyingDepth;

View File

@ -112,9 +112,9 @@ void on_isLoseButNotChangeSideWhenNoWay(const Option &o)
rule.isLoseButNotChangeSideWhenNoWay = (bool)o; rule.isLoseButNotChangeSideWhenNoWay = (bool)o;
} }
void on_allowFlyWhenRemainThreePieces(const Option &o) void on_flyingAllowed(const Option &o)
{ {
rule.allowFlyWhenRemainThreePieces = (bool)o; rule.flyingAllowed = (bool)o;
} }
void on_maxStepsLedToDraw(const Option &o) void on_maxStepsLedToDraw(const Option &o)
@ -165,7 +165,7 @@ void init(OptionsMap &o)
o["allowRemovePieceInMill"] << Option(true, on_allowRemovePieceInMill); o["allowRemovePieceInMill"] << Option(true, on_allowRemovePieceInMill);
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["allowFlyWhenRemainThreePieces"] << Option(false, on_allowFlyWhenRemainThreePieces); o["flyingAllowed"] << Option(false, on_flyingAllowed);
o["maxStepsLedToDraw"] << Option(50, 30, 50, on_maxStepsLedToDraw); o["maxStepsLedToDraw"] << Option(50, 30, 50, on_maxStepsLedToDraw);
} }

View File

@ -46,7 +46,7 @@ class Config {
static bool allowRemovePieceInMill = true; static bool allowRemovePieceInMill = true;
static bool isBlackLoseButNotDrawWhenBoardFull = true; static bool isBlackLoseButNotDrawWhenBoardFull = true;
static bool isLoseButNotChangeSideWhenNoWay = true; static bool isLoseButNotChangeSideWhenNoWay = true;
static bool allowFlyWhenRemainThreePieces = false; static bool flyingAllowed = false;
static int maxStepsLedToDraw = 50; static int maxStepsLedToDraw = 50;
static Future<void> loadProfile() async { static Future<void> loadProfile() async {
@ -88,8 +88,8 @@ class Config {
rule.isLoseButNotChangeSideWhenNoWay = rule.isLoseButNotChangeSideWhenNoWay =
Config.isLoseButNotChangeSideWhenNoWay = Config.isLoseButNotChangeSideWhenNoWay =
profile['isLoseButNotChangeSideWhenNoWay'] ?? true; profile['isLoseButNotChangeSideWhenNoWay'] ?? true;
rule.allowFlyWhenRemainThreePieces = Config.allowFlyWhenRemainThreePieces = rule.flyingAllowed =
profile['allowFlyWhenRemainThreePieces'] ?? false; Config.flyingAllowed = profile['flyingAllowed'] ?? false;
rule.maxStepsLedToDraw = rule.maxStepsLedToDraw =
Config.maxStepsLedToDraw = profile['maxStepsLedToDraw'] ?? 50; Config.maxStepsLedToDraw = profile['maxStepsLedToDraw'] ?? 50;
@ -126,8 +126,7 @@ class Config {
Config.isBlackLoseButNotDrawWhenBoardFull; Config.isBlackLoseButNotDrawWhenBoardFull;
profile['isLoseButNotChangeSideWhenNoWay'] = profile['isLoseButNotChangeSideWhenNoWay'] =
Config.isLoseButNotChangeSideWhenNoWay; Config.isLoseButNotChangeSideWhenNoWay;
profile['allowFlyWhenRemainThreePieces'] = profile['flyingAllowed'] = Config.flyingAllowed;
Config.allowFlyWhenRemainThreePieces;
profile['maxStepsLedToDraw'] = Config.maxStepsLedToDraw; profile['maxStepsLedToDraw'] = Config.maxStepsLedToDraw;
profile.commit(); profile.commit();

View File

@ -151,8 +151,7 @@ class NativeEngine extends AiEngine {
'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( await send('setoption name flyingAllowed value ${Config.flyingAllowed}');
'setoption name allowFlyWhenRemainThreePieces value ${Config.allowFlyWhenRemainThreePieces}');
await send( await send(
'setoption name maxStepsLedToDraw value ${Config.maxStepsLedToDraw}'); 'setoption name maxStepsLedToDraw value ${Config.maxStepsLedToDraw}');
} }

View File

@ -355,8 +355,8 @@
"@isLoseButNotChangeSideWhenNoWay": { "@isLoseButNotChangeSideWhenNoWay": {
"description": "Lose But Not Change Side When No Way" "description": "Lose But Not Change Side When No Way"
}, },
"allowFlyWhenRemainThreePieces": "Allow Fly When Remain Three Pieces", "flyingAllowed": "Allow Fly When Remain Three Pieces",
"@allowFlyWhenRemainThreePieces": { "@flyingAllowed": {
"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

@ -88,6 +88,6 @@
"allowRemovePieceInMill": "允许吃三中的子", "allowRemovePieceInMill": "允许吃三中的子",
"isBlackLoseButNotDrawWhenBoardFull": "当棋盘摆满时先摆子的输棋", "isBlackLoseButNotDrawWhenBoardFull": "当棋盘摆满时先摆子的输棋",
"isLoseButNotChangeSideWhenNoWay": "当无路可走时输棋", "isLoseButNotChangeSideWhenNoWay": "当无路可走时输棋",
"allowFlyWhenRemainThreePieces": "剩余三颗子时飞棋", "flyingAllowed": "剩余三颗子时飞棋",
"maxStepsLedToDraw": "连续多少步无吃子则和棋" "maxStepsLedToDraw": "连续多少步无吃子则和棋"
} }

View File

@ -564,7 +564,7 @@ class Position {
// if illegal // if illegal
if (pieceCountOnBoard[sideToMove()] > rule.nPiecesAtLeast || if (pieceCountOnBoard[sideToMove()] > rule.nPiecesAtLeast ||
!rule.allowFlyWhenRemainThreePieces) { !rule.flyingAllowed) {
int md; int md;
for (md = 0; md < moveDirectionNumber; md++) { for (md = 0; md < moveDirectionNumber; md++) {
@ -1418,7 +1418,7 @@ class Position {
// Can fly // Can fly
if (pieceCountOnBoard[sideToMove()] <= rule.nPiecesAtLeast && if (pieceCountOnBoard[sideToMove()] <= rule.nPiecesAtLeast &&
rule.allowFlyWhenRemainThreePieces) { rule.flyingAllowed) {
//print("Can fly."); //print("Can fly.");
return false; return false;
} }

View File

@ -28,7 +28,7 @@ class Rule {
bool allowRemovePieceInMill = true; bool allowRemovePieceInMill = true;
bool isBlackLoseButNotDrawWhenBoardFull = true; bool isBlackLoseButNotDrawWhenBoardFull = true;
bool isLoseButNotChangeSideWhenNoWay = true; bool isLoseButNotChangeSideWhenNoWay = true;
bool allowFlyWhenRemainThreePieces = false; bool flyingAllowed = false;
int maxStepsLedToDraw = 0; int maxStepsLedToDraw = 0;
} }

View File

@ -323,11 +323,10 @@ class _SettingsPageState extends State<SettingsPage> {
Config.save(); Config.save();
} }
setAllowFlyWhenRemainThreePieces(bool value) async { setAllowFlyingAllowed(bool value) async {
// //
setState(() { setState(() {
rule.allowFlyWhenRemainThreePieces = rule.flyingAllowed = Config.flyingAllowed = value;
Config.allowFlyWhenRemainThreePieces = value;
}); });
Config.save(); Config.save();
@ -632,10 +631,9 @@ class _SettingsPageState extends State<SettingsPage> {
_buildDivider(), _buildDivider(),
SwitchListTile( SwitchListTile(
activeColor: UIColors.primaryColor, activeColor: UIColors.primaryColor,
value: Config.allowFlyWhenRemainThreePieces, value: Config.flyingAllowed,
title: Text(S.of(context).allowFlyWhenRemainThreePieces, title: Text(S.of(context).flyingAllowed, style: itemStyle),
style: itemStyle), onChanged: setAllowFlyingAllowed,
onChanged: setAllowFlyWhenRemainThreePieces,
), ),
_buildDivider(), _buildDivider(),
/* /*