refactor: Replace oblique to diagonal
This commit is contained in:
parent
8ef01c247a
commit
3b358f0d8c
|
@ -246,7 +246,7 @@ void adjacent_squares_init() noexcept
|
|||
/* 39 */ 0,
|
||||
};
|
||||
|
||||
if (rule.hasObliqueLines) {
|
||||
if (rule.hasDiagonalLines) {
|
||||
memcpy(MoveList<LEGAL>::adjacentSquares, adjacentSquares12, sizeof(MoveList<LEGAL>::adjacentSquares));
|
||||
memcpy(MoveList<LEGAL>::adjacentSquaresBB, adjacentSquaresBB12, sizeof(MoveList<LEGAL>::adjacentSquaresBB));
|
||||
} else {
|
||||
|
@ -368,7 +368,7 @@ void mill_table_init()
|
|||
};
|
||||
|
||||
// TODO: change to ptr?
|
||||
if (rule.hasObliqueLines) {
|
||||
if (rule.hasDiagonalLines) {
|
||||
memcpy(Position::millTableBB, millTableBB12, sizeof(Position::millTableBB));
|
||||
} else {
|
||||
memcpy(Position::millTableBB, millTableBB9, sizeof(Position::millTableBB));
|
||||
|
|
|
@ -127,7 +127,7 @@ std::ostream &operator<<(std::ostream &os, const Position &pos)
|
|||
|
||||
#define P(s) PieceToChar(pos.piece_on(Square(s)))
|
||||
|
||||
if (rule.hasObliqueLines) {
|
||||
if (rule.hasDiagonalLines) {
|
||||
os << "\n";
|
||||
os << P(31) << " --- " << P(24) << " --- " << P(25) << "\n";
|
||||
os << "|\\ | /|\n";
|
||||
|
@ -1306,7 +1306,7 @@ bool Position::is_all_surrounded(Color c
|
|||
|
||||
bool Position::is_star_square(Square s)
|
||||
{
|
||||
if (rule.hasObliqueLines == true) {
|
||||
if (rule.hasDiagonalLines == true) {
|
||||
return (s == 17 ||
|
||||
s == 19 ||
|
||||
s == 21 ||
|
||||
|
|
|
@ -33,7 +33,7 @@ struct Rule
|
|||
|
||||
int piecesAtLeastCount; // Default is 3
|
||||
|
||||
bool hasObliqueLines;
|
||||
bool hasDiagonalLines;
|
||||
|
||||
bool hasBannedLocations;
|
||||
|
||||
|
|
|
@ -87,9 +87,9 @@ void on_piecesAtLeastCount(const Option &o)
|
|||
rule.piecesAtLeastCount = (int)o;
|
||||
}
|
||||
|
||||
void on_hasObliqueLines(const Option &o)
|
||||
void on_hasDiagonalLines(const Option &o)
|
||||
{
|
||||
rule.hasObliqueLines = (bool)o;
|
||||
rule.hasDiagonalLines = (bool)o;
|
||||
}
|
||||
|
||||
void on_hasBannedLocations(const Option &o)
|
||||
|
@ -169,7 +169,7 @@ void init(OptionsMap &o)
|
|||
// Rules
|
||||
o["PiecesCount"] << Option(12, 6, 12, on_piecesCount);
|
||||
o["PiecesAtLeastCount"] << Option(3, 3, 5, on_piecesAtLeastCount);
|
||||
o["HasObliqueLines"] << Option(true, on_hasObliqueLines);
|
||||
o["HasDiagonalLines"] << Option(true, on_hasDiagonalLines);
|
||||
o["HasBannedLocations"] << Option(true, on_hasBannedLocations);
|
||||
o["IsDefenderMoveFirst"] << Option(true, on_isDefenderMoveFirst);
|
||||
o["MayRemoveMultiple"] << Option(false, on_mayRemoveMultiple);
|
||||
|
|
|
@ -51,7 +51,7 @@ class Config {
|
|||
// Rules
|
||||
static int piecesCount = 12;
|
||||
static int piecesAtLeastCount = 3;
|
||||
static bool hasObliqueLines = true;
|
||||
static bool hasDiagonalLines = true;
|
||||
static bool hasBannedLocations = true;
|
||||
static bool isDefenderMoveFirst = true;
|
||||
static bool mayRemoveMultiple = false;
|
||||
|
@ -100,8 +100,8 @@ class Config {
|
|||
rule.piecesCount = Config.piecesCount = profile['PiecesCount'] ?? 12;
|
||||
rule.piecesAtLeastCount =
|
||||
Config.piecesAtLeastCount = profile['PiecesAtLeastCount'] ?? 3;
|
||||
rule.hasObliqueLines =
|
||||
Config.hasObliqueLines = profile['HasObliqueLines'] ?? true;
|
||||
rule.hasDiagonalLines =
|
||||
Config.hasDiagonalLines = profile['HasDiagonalLines'] ?? true;
|
||||
rule.hasBannedLocations =
|
||||
Config.hasBannedLocations = profile['HasBannedLocations'] ?? true;
|
||||
rule.isDefenderMoveFirst =
|
||||
|
@ -153,7 +153,7 @@ class Config {
|
|||
// Rules
|
||||
profile['PiecesCount'] = Config.piecesCount;
|
||||
profile['PiecesAtLeastCount'] = Config.piecesAtLeastCount;
|
||||
profile['HasObliqueLines'] = Config.hasObliqueLines;
|
||||
profile['HasDiagonalLines'] = Config.hasDiagonalLines;
|
||||
profile['HasBannedLocations'] = Config.hasBannedLocations;
|
||||
profile['IsDefenderMoveFirst'] = Config.isDefenderMoveFirst;
|
||||
profile['MayRemoveMultiple'] = Config.mayRemoveMultiple;
|
||||
|
|
|
@ -112,7 +112,7 @@ class NativeEngine extends AiEngine {
|
|||
await send(
|
||||
'setoption name PiecesAtLeastCount value ${Config.piecesAtLeastCount}');
|
||||
await send(
|
||||
'setoption name HasObliqueLines value ${Config.hasObliqueLines}');
|
||||
'setoption name HasDiagonalLines value ${Config.hasDiagonalLines}');
|
||||
await send(
|
||||
'setoption name HasBannedLocations value ${Config.hasBannedLocations}');
|
||||
await send(
|
||||
|
|
|
@ -372,9 +372,9 @@
|
|||
"@piecesAtLeastCount": {
|
||||
"description": "Pieces At Least"
|
||||
},
|
||||
"hasObliqueLines": "Has Oblique Lines",
|
||||
"@hasObliqueLines": {
|
||||
"description": "Has Oblique Lines"
|
||||
"hasDiagonalLines": "Has Diagonal Lines",
|
||||
"@hasDiagonalLines": {
|
||||
"description": "Has Diagonal Lines"
|
||||
},
|
||||
"hasBannedLocations": "Has Banned Locations",
|
||||
"@hasBannedLocations": {
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
"ninePieces": "九子",
|
||||
"twelvePieces": "十二子",
|
||||
"piecesAtLeastCount": "少于几个子则输棋",
|
||||
"hasObliqueLines": "斜线",
|
||||
"hasDiagonalLines": "斜线",
|
||||
"hasBannedLocations": "禁点",
|
||||
"hasBannedLocations_Detail": "在摆子阶段,被吃掉的棋子的位置将不能再落子,除非进入走子阶段。",
|
||||
"isDefenderMoveFirst": "后摆子的先走子",
|
||||
|
|
|
@ -849,7 +849,7 @@ class Position {
|
|||
}
|
||||
|
||||
void createMillTable() {
|
||||
const millTable_noObliqueLine = [
|
||||
const millTable_noDiagonalLine = [
|
||||
/* 0 */ [
|
||||
[0, 0],
|
||||
[0, 0],
|
||||
|
@ -1056,7 +1056,7 @@ class Position {
|
|||
]
|
||||
];
|
||||
|
||||
const millTable_hasObliqueLines = [
|
||||
const millTable_hasDiagonalLines = [
|
||||
/* 0 */ [
|
||||
[0, 0],
|
||||
[0, 0],
|
||||
|
@ -1263,16 +1263,16 @@ class Position {
|
|||
]
|
||||
];
|
||||
|
||||
if (rule.hasObliqueLines) {
|
||||
millTable = millTable_hasObliqueLines;
|
||||
if (rule.hasDiagonalLines) {
|
||||
millTable = millTable_hasDiagonalLines;
|
||||
} else {
|
||||
millTable = millTable_noObliqueLine;
|
||||
millTable = millTable_noDiagonalLine;
|
||||
}
|
||||
}
|
||||
|
||||
void createMoveTable() {
|
||||
// Note: Not follow order of MoveDirection array
|
||||
const moveTable_obliqueLine = [
|
||||
const moveTable_diagonalLine = [
|
||||
/* 0 */ [0, 0, 0, 0],
|
||||
/* 1 */ [0, 0, 0, 0],
|
||||
/* 2 */ [0, 0, 0, 0],
|
||||
|
@ -1319,7 +1319,7 @@ class Position {
|
|||
/* 39 */ [0, 0, 0, 0],
|
||||
];
|
||||
|
||||
const moveTable_noObliqueLine = [
|
||||
const moveTable_noDiagonalLine = [
|
||||
/* 0 */ [0, 0, 0, 0],
|
||||
/* 1 */ [0, 0, 0, 0],
|
||||
/* 2 */ [0, 0, 0, 0],
|
||||
|
@ -1366,10 +1366,10 @@ class Position {
|
|||
/* 39 */ [0, 0, 0, 0],
|
||||
];
|
||||
|
||||
if (rule.hasObliqueLines) {
|
||||
moveTable = moveTable_obliqueLine;
|
||||
if (rule.hasDiagonalLines) {
|
||||
moveTable = moveTable_diagonalLine;
|
||||
} else {
|
||||
moveTable = moveTable_noObliqueLine;
|
||||
moveTable = moveTable_noDiagonalLine;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1495,7 +1495,7 @@ class Position {
|
|||
}
|
||||
|
||||
bool isStarSquare(int s) {
|
||||
if (rule.hasObliqueLines == true) {
|
||||
if (rule.hasDiagonalLines == true) {
|
||||
return (s == 17 || s == 19 || s == 21 || s == 23);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class Rule {
|
|||
String description = "";
|
||||
int piecesCount = 12; // 9 or 12
|
||||
int piecesAtLeastCount = 3; // Default is 3
|
||||
bool hasObliqueLines = true;
|
||||
bool hasDiagonalLines = true;
|
||||
bool hasBannedLocations = true;
|
||||
bool isDefenderMoveFirst = true;
|
||||
bool mayRemoveMultiple = false;
|
||||
|
|
|
@ -177,32 +177,32 @@ class BoardPainter extends PiecesBasePainter {
|
|||
paint,
|
||||
);
|
||||
|
||||
if (!Config.hasObliqueLines) {
|
||||
if (!Config.hasDiagonalLines) {
|
||||
return;
|
||||
}
|
||||
|
||||
// top left oblique line
|
||||
// top left diagonal line
|
||||
canvas.drawLine(
|
||||
Offset(left + 0, top),
|
||||
Offset(left + squareWidth * 2, top + squareWidth * 2),
|
||||
paint,
|
||||
);
|
||||
|
||||
// lower right oblique line
|
||||
// lower right diagonal line
|
||||
canvas.drawLine(
|
||||
Offset(left + squareWidth * 4, top + squareWidth * 4),
|
||||
Offset(left + squareWidth * 6, top + squareWidth * 6),
|
||||
paint,
|
||||
);
|
||||
|
||||
// top right oblique line
|
||||
// top right diagonal line
|
||||
canvas.drawLine(
|
||||
Offset(left + squareWidth * 6, top),
|
||||
Offset(left + squareWidth * 4, top + squareWidth * 2),
|
||||
paint,
|
||||
);
|
||||
|
||||
// lower left oblique line
|
||||
// lower left diagonal line
|
||||
canvas.drawLine(
|
||||
Offset(left + squareWidth * 2, top + squareWidth * 4),
|
||||
Offset(left + squareWidth * 0, top + squareWidth * 6),
|
||||
|
|
|
@ -92,10 +92,10 @@ class _RuleSettingsPageState extends State<RuleSettingsPage> {
|
|||
Config.save();
|
||||
}
|
||||
|
||||
setHasObliqueLines(bool value) async {
|
||||
setHasDiagonalLines(bool value) async {
|
||||
//
|
||||
setState(() {
|
||||
rule.hasObliqueLines = Config.hasObliqueLines = value;
|
||||
rule.hasDiagonalLines = Config.hasDiagonalLines = value;
|
||||
});
|
||||
|
||||
Config.save();
|
||||
|
@ -214,10 +214,10 @@ class _RuleSettingsPageState extends State<RuleSettingsPage> {
|
|||
_buildDivider(),
|
||||
SwitchListTile(
|
||||
activeColor: UIColors.primaryColor,
|
||||
value: Config.hasObliqueLines,
|
||||
value: Config.hasDiagonalLines,
|
||||
title:
|
||||
Text(S.of(context).hasObliqueLines, style: itemStyle),
|
||||
onChanged: setHasObliqueLines,
|
||||
Text(S.of(context).hasDiagonalLines, style: itemStyle),
|
||||
onChanged: setHasDiagonalLines,
|
||||
),
|
||||
_buildDivider(),
|
||||
SwitchListTile(
|
||||
|
|
|
@ -78,7 +78,7 @@ QPainterPath BoardItem::shape() const
|
|||
|
||||
void BoardItem::setDiagonal(bool arg)
|
||||
{
|
||||
hasObliqueLine = arg;
|
||||
hasDiagonalLine = arg;
|
||||
update(boundingRect());
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ void BoardItem::paint(QPainter *painter,
|
|||
painter->drawLine(position[i], position[(FILE_NB - 1) * RANK_NB + i]);
|
||||
}
|
||||
|
||||
if (hasObliqueLine) {
|
||||
if (hasDiagonalLine) {
|
||||
// Draw 4 diagonal lines
|
||||
for (int i = 1; i < RANK_NB; i += 2) {
|
||||
painter->drawLine(position[i], position[(FILE_NB - 1) * RANK_NB + i]);
|
||||
|
|
|
@ -69,7 +69,7 @@ private:
|
|||
int size; // board size
|
||||
int sizeShadow {5};
|
||||
QPointF position[EFFECTIVE_SQUARE_NB]; // 24 points
|
||||
bool hasObliqueLine {false};
|
||||
bool hasDiagonalLine {false};
|
||||
};
|
||||
|
||||
#endif // BOARDITEM_H
|
||||
|
|
|
@ -257,7 +257,7 @@ void Game::gameReset()
|
|||
currentPiece = nullptr;
|
||||
|
||||
// Redraw pieces
|
||||
scene.setDiagonal(rule.hasObliqueLines);
|
||||
scene.setDiagonal(rule.hasDiagonalLines);
|
||||
|
||||
// Draw all the pieces and put them in the starting position
|
||||
// 0: the first piece in the first hand; 1: the first piece in the second hand
|
||||
|
|
Loading…
Reference in New Issue