refactor: rule: Rename take to remove

This commit is contained in:
Calcitem 2020-12-31 03:02:05 +08:00
parent f3a88283de
commit 3f85a41652
12 changed files with 42 additions and 42 deletions

View File

@ -107,7 +107,7 @@ ExtMove *generate<REMOVE>(Position &pos, ExtMove *moveList)
for (auto i = EFFECTIVE_SQUARE_NB - 1; i >= 0; i--) {
s = MoveList<LEGAL>::movePriorityList[i];
if (pos.get_board()[s] & make_piece(them)) {
if (rule.mayTakeFromMillsAlways || !pos.potential_mills_count(s, NOBODY)) {
if (rule.mayRemoveFromMillsAlways || !pos.potential_mills_count(s, NOBODY)) {
*cur++ = (Move)-s;
}
}

View File

@ -65,7 +65,7 @@ void MovePicker::score()
int nTheirMills = 0;
#ifndef SORT_MOVE_WITHOUT_HUMAN_KNOWLEDGES
// TODO: rule.mayTakeMultiple adapt other rules
// TODO: rule.mayRemoveMultiple adapt other rules
if (type_of(m) != MOVETYPE_REMOVE) {
// all phrase, check if place sq can close mill
if (nOurMills > 0) {

View File

@ -836,7 +836,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
change_side_to_move();
}
} else {
pieceToRemoveCount = rule.mayTakeMultiple ? n : 1;
pieceToRemoveCount = rule.mayRemoveMultiple ? n : 1;
update_key_misc();
action = Action::remove;
}
@ -890,7 +890,7 @@ bool Position::put_piece(Square s, bool updateCmdlist)
return true;
}
} else {
pieceToRemoveCount = rule.mayTakeMultiple ? n : 1;
pieceToRemoveCount = rule.mayRemoveMultiple ? 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.mayTakeFromMillsAlways &&
if (!rule.mayRemoveFromMillsAlways &&
potential_mills_count(s, NOBODY) &&
!is_all_in_mills(~sideToMove)) {
return false;

View File

@ -39,11 +39,11 @@ struct Rule
bool isDefenderMoveFirst;
// When closing more than one mill at once, may also take several opponent pieces.
bool mayTakeMultiple;
// When closing more than one mill at once, may also remove several opponent pieces.
bool mayRemoveMultiple;
// May take from mills even if there are other pieces available.
bool mayTakeFromMillsAlways;
// May remove from mills even if there are other pieces available.
bool mayRemoveFromMillsAlways;
bool isBlackLoseButNotDrawWhenBoardFull;

View File

@ -92,14 +92,14 @@ void on_isDefenderMoveFirst(const Option &o)
rule.isDefenderMoveFirst = (bool)o;
}
void on_mayTakeMultiple(const Option &o)
void on_mayRemoveMultiple(const Option &o)
{
rule.mayTakeMultiple = (bool)o;
rule.mayRemoveMultiple = (bool)o;
}
void on_mayTakeFromMillsAlways(const Option &o)
void on_mayRemoveFromMillsAlways(const Option &o)
{
rule.mayTakeFromMillsAlways = (bool)o;
rule.mayRemoveFromMillsAlways = (bool)o;
}
void on_isBlackLoseButNotDrawWhenBoardFull(const Option &o)
@ -161,8 +161,8 @@ void init(OptionsMap &o)
o["hasObliqueLines"] << Option(true, on_hasObliqueLines);
o["hasBannedLocations"] << Option(true, on_hasBannedLocations);
o["isDefenderMoveFirst"] << Option(true, on_isDefenderMoveFirst);
o["mayTakeMultiple"] << Option(false, on_mayTakeMultiple);
o["mayTakeFromMillsAlways"] << Option(true, on_mayTakeFromMillsAlways);
o["mayRemoveMultiple"] << Option(false, on_mayRemoveMultiple);
o["mayRemoveFromMillsAlways"] << Option(true, on_mayRemoveFromMillsAlways);
o["isBlackLoseButNotDrawWhenBoardFull"] << Option(true, on_isBlackLoseButNotDrawWhenBoardFull);
o["isLoseButNotChangeSideWhenNoWay"] << Option(true, on_isLoseButNotChangeSideWhenNoWay);
o["mayFly"] << Option(false, on_mayFly);

View File

@ -42,8 +42,8 @@ class Config {
static bool hasObliqueLines = true;
static bool hasBannedLocations = true;
static bool isDefenderMoveFirst = true;
static bool mayTakeMultiple = false;
static bool mayTakeFromMillsAlways = true;
static bool mayRemoveMultiple = false;
static bool mayRemoveFromMillsAlways = true;
static bool isBlackLoseButNotDrawWhenBoardFull = true;
static bool isLoseButNotChangeSideWhenNoWay = true;
static bool mayFly = false;
@ -76,10 +76,10 @@ class Config {
Config.hasBannedLocations = profile['hasBannedLocations'] ?? true;
rule.isDefenderMoveFirst =
Config.isDefenderMoveFirst = profile['isDefenderMoveFirst'] ?? true;
rule.mayTakeMultiple =
Config.mayTakeMultiple = profile['mayTakeMultiple'] ?? false;
rule.mayTakeFromMillsAlways = Config.mayTakeFromMillsAlways =
profile['mayTakeFromMillsAlways'] ?? true;
rule.mayRemoveMultiple =
Config.mayRemoveMultiple = profile['mayRemoveMultiple'] ?? false;
rule.mayRemoveFromMillsAlways = Config.mayRemoveFromMillsAlways =
profile['mayRemoveFromMillsAlways'] ?? true;
rule.isBlackLoseButNotDrawWhenBoardFull =
Config.isBlackLoseButNotDrawWhenBoardFull =
profile['isBlackLoseButNotDrawWhenBoardFull'] ?? true;
@ -116,8 +116,8 @@ class Config {
profile['hasObliqueLines'] = Config.hasObliqueLines;
profile['hasBannedLocations'] = Config.hasBannedLocations;
profile['isDefenderMoveFirst'] = Config.isDefenderMoveFirst;
profile['mayTakeMultiple'] = Config.mayTakeMultiple;
profile['mayTakeFromMillsAlways'] = Config.mayTakeFromMillsAlways;
profile['mayRemoveMultiple'] = Config.mayRemoveMultiple;
profile['mayRemoveFromMillsAlways'] = Config.mayRemoveFromMillsAlways;
profile['isBlackLoseButNotDrawWhenBoardFull'] =
Config.isBlackLoseButNotDrawWhenBoardFull;
profile['isLoseButNotChangeSideWhenNoWay'] =

View File

@ -144,9 +144,9 @@ class NativeEngine extends AiEngine {
await send(
'setoption name isDefenderMoveFirst value ${Config.isDefenderMoveFirst}');
await send(
'setoption name mayTakeMultiple value ${Config.mayTakeMultiple}');
'setoption name mayRemoveMultiple value ${Config.mayRemoveMultiple}');
await send(
'setoption name mayTakeFromMillsAlways value ${Config.mayTakeFromMillsAlways}');
'setoption name mayRemoveFromMillsAlways value ${Config.mayRemoveFromMillsAlways}');
await send(
'setoption name isBlackLoseButNotDrawWhenBoardFull value ${Config.isBlackLoseButNotDrawWhenBoardFull}');
await send(

View File

@ -339,12 +339,12 @@
"@isDefenderMoveFirst": {
"description": "Defender Move First"
},
"mayTakeMultiple": "Allow Remove Multi Pieces When Close Multi Mill",
"@mayTakeMultiple": {
"mayRemoveMultiple": "Allow Remove Multi Pieces When Close Multi Mill",
"@mayRemoveMultiple": {
"description": "Allow Remove Multi Pieces When Close Multi Mill"
},
"mayTakeFromMillsAlways": "Allow Remove Piece In Mill",
"@mayTakeFromMillsAlways": {
"mayRemoveFromMillsAlways": "Allow Remove Piece In Mill",
"@mayRemoveFromMillsAlways": {
"description": "Allow Remove Piece In Mill"
},
"isBlackLoseButNotDrawWhenBoardFull": "Black Lose But Not Draw When Board Full",

View File

@ -84,8 +84,8 @@
"hasObliqueLines": "斜线",
"hasBannedLocations": "禁点",
"isDefenderMoveFirst": "后摆子的先走子",
"mayTakeMultiple": "成几个三就吃几个子",
"mayTakeFromMillsAlways": "允许吃三中的子",
"mayRemoveMultiple": "成几个三就吃几个子",
"mayRemoveFromMillsAlways": "允许吃三中的子",
"isBlackLoseButNotDrawWhenBoardFull": "当棋盘摆满时先摆子的输棋",
"isLoseButNotChangeSideWhenNoWay": "当无路可走时输棋",
"mayFly": "剩余三颗子时飞棋",

View File

@ -553,7 +553,7 @@ class Position {
changeSideToMove();
}
} else {
pieceToRemoveCount = rule.mayTakeMultiple ? n : 1;
pieceToRemoveCount = rule.mayRemoveMultiple ? n : 1;
action = Act.remove;
}
} else if (phase == Phase.moving) {
@ -605,7 +605,7 @@ class Position {
return true;
}
} else {
pieceToRemoveCount = rule.mayTakeMultiple ? n : 1;
pieceToRemoveCount = rule.mayRemoveMultiple ? n : 1;
action = Act.remove;
}
} else {
@ -625,7 +625,7 @@ class Position {
// if piece is not their
if (!(Color.opponent(sideToMove()) == board[s])) return false;
if (!rule.mayTakeFromMillsAlways &&
if (!rule.mayRemoveFromMillsAlways &&
potentialMillsCount(s, Color.nobody) > 0 &&
!isAllInMills(Color.opponent(sideToMove()))) {
return false;

View File

@ -24,8 +24,8 @@ class Rule {
bool hasObliqueLines = true;
bool hasBannedLocations = true;
bool isDefenderMoveFirst = true;
bool mayTakeMultiple = false;
bool mayTakeFromMillsAlways = true;
bool mayRemoveMultiple = false;
bool mayRemoveFromMillsAlways = true;
bool isBlackLoseButNotDrawWhenBoardFull = true;
bool isLoseButNotChangeSideWhenNoWay = true;
bool mayFly = false;

View File

@ -286,7 +286,7 @@ class _SettingsPageState extends State<SettingsPage> {
setAllowRemoveMultiPiecesWhenCloseMultiMill(bool value) async {
//
setState(() {
rule.mayTakeMultiple = Config.mayTakeMultiple = value;
rule.mayRemoveMultiple = Config.mayRemoveMultiple = value;
});
Config.save();
@ -295,7 +295,7 @@ class _SettingsPageState extends State<SettingsPage> {
setAllowRemovePieceInMill(bool value) async {
//
setState(() {
rule.mayTakeFromMillsAlways = Config.mayTakeFromMillsAlways = value;
rule.mayRemoveFromMillsAlways = Config.mayRemoveFromMillsAlways = value;
});
Config.save();
@ -594,16 +594,16 @@ class _SettingsPageState extends State<SettingsPage> {
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.mayTakeMultiple,
value: Config.mayRemoveMultiple,
title:
Text(S.of(context).mayTakeMultiple, style: itemStyle),
Text(S.of(context).mayRemoveMultiple, style: itemStyle),
onChanged: setAllowRemoveMultiPiecesWhenCloseMultiMill,
),
_buildDivider(),
SwitchListTile(
activeColor: UIColors.primaryColor,
value: Config.mayTakeFromMillsAlways,
title: Text(S.of(context).mayTakeFromMillsAlways,
value: Config.mayRemoveFromMillsAlways,
title: Text(S.of(context).mayRemoveFromMillsAlways,
style: itemStyle),
onChanged: setAllowRemovePieceInMill,
),