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 ||
!rule.allowFlyWhenRemainThreePieces) {
!rule.flyingAllowed) {
for (auto direction = MD_BEGIN; direction < MD_NB; ++direction) {
to = static_cast<Square>(MoveList<LEGAL>::adjacentSquares[from][direction]);
if (to && !pos.get_board()[to]) {
@ -69,7 +69,7 @@ ExtMove *generate<MOVE>(Position &pos, ExtMove *moveList)
}
}
} 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) {
if (!pos.get_board()[to]) {
*cur++ = make_move(from, to);

View File

@ -849,7 +849,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
// if illegal
if (pieceCountOnBoard[sideToMove] > rule.nPiecesAtLeast ||
!rule.allowFlyWhenRemainThreePieces) {
!rule.flyingAllowed) {
if ((square_bb(s) & MoveList<LEGAL>::adjacentSquaresBB[currentSquare]) == 0) {
return false;
}
@ -1487,7 +1487,7 @@ int Position::surrounded_empty_squares_count(Square s, bool includeFobidden)
int n = 0;
if (pieceCountOnBoard[sideToMove] > rule.nPiecesAtLeast ||
!rule.allowFlyWhenRemainThreePieces) {
!rule.flyingAllowed) {
Square moveSquare;
for (MoveDirection d = MD_BEGIN; d < MD_NB; ++d) {
moveSquare = static_cast<Square>(MoveList<LEGAL>::adjacentSquares[s][d]);
@ -1542,7 +1542,7 @@ bool Position::is_all_surrounded() const
// Can fly
if (pieceCountOnBoard[sideToMove] <= rule.nPiecesAtLeast &&
rule.allowFlyWhenRemainThreePieces) {
rule.flyingAllowed) {
return false;
}

View File

@ -24,17 +24,30 @@
struct Rule
{
const char name[32];
const char description[512];
int nTotalPiecesEachSide; // 9 or 12
int nPiecesAtLeast; // Default is 3
bool hasObliqueLines;
bool hasBannedLocations;
bool isDefenderMoveFirst;
bool allowRemoveMultiPiecesWhenCloseMultiMill;
bool allowRemovePieceInMill;
bool isBlackLoseButNotDrawWhenBoardFull;
bool isLoseButNotChangeSideWhenNoWay;
bool allowFlyWhenRemainThreePieces;
// Specifies if jumps are allowed when a player remains with three pieces on the board.
bool flyingAllowed;
int maxStepsLedToDraw;
};

View File

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

View File

@ -112,9 +112,9 @@ void on_isLoseButNotChangeSideWhenNoWay(const Option &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)
@ -165,7 +165,7 @@ void init(OptionsMap &o)
o["allowRemovePieceInMill"] << Option(true, on_allowRemovePieceInMill);
o["isBlackLoseButNotDrawWhenBoardFull"] << Option(true, on_isBlackLoseButNotDrawWhenBoardFull);
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);
}

View File

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

View File

@ -151,8 +151,7 @@ class NativeEngine extends AiEngine {
'setoption name isBlackLoseButNotDrawWhenBoardFull value ${Config.isBlackLoseButNotDrawWhenBoardFull}');
await send(
'setoption name isLoseButNotChangeSideWhenNoWay value ${Config.isLoseButNotChangeSideWhenNoWay}');
await send(
'setoption name allowFlyWhenRemainThreePieces value ${Config.allowFlyWhenRemainThreePieces}');
await send('setoption name flyingAllowed value ${Config.flyingAllowed}');
await send(
'setoption name maxStepsLedToDraw value ${Config.maxStepsLedToDraw}');
}

View File

@ -355,8 +355,8 @@
"@isLoseButNotChangeSideWhenNoWay": {
"description": "Lose But Not Change Side When No Way"
},
"allowFlyWhenRemainThreePieces": "Allow Fly When Remain Three Pieces",
"@allowFlyWhenRemainThreePieces": {
"flyingAllowed": "Allow Fly When Remain Three Pieces",
"@flyingAllowed": {
"description": "Allow Fly When Remain Three Pieces"
},
"maxStepsLedToDraw": "Max Steps Led To Draw",

View File

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

View File

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

View File

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

View File

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