flutter: Support standard notation
This commit is contained in:
parent
8d6a961877
commit
c88e3fd60a
|
@ -40,6 +40,7 @@ class Config {
|
|||
static bool developerMode = false;
|
||||
|
||||
// Display
|
||||
static bool standardNotationEnabled = true;
|
||||
static bool isPieceCountInHandShown = false;
|
||||
static double boardBorderLineWidth = 2.0;
|
||||
static double boardInnerLineWidth = 2.0;
|
||||
|
@ -86,6 +87,8 @@ class Config {
|
|||
Config.developerMode = settings['DeveloperMode'] ?? false;
|
||||
|
||||
// Display
|
||||
Config.standardNotationEnabled =
|
||||
settings['StandardNotationEnabled'] ?? true;
|
||||
Config.isPieceCountInHandShown =
|
||||
settings['IsPieceCountInHandShown'] ?? false;
|
||||
Config.boardBorderLineWidth = settings['BoardBorderLineWidth'] ?? 2;
|
||||
|
@ -151,6 +154,7 @@ class Config {
|
|||
settings['DeveloperMode'] = Config.developerMode;
|
||||
|
||||
// Display
|
||||
settings['StandardNotationEnabled'] = Config.standardNotationEnabled;
|
||||
settings['IsPieceCountInHandShown'] = Config.isPieceCountInHandShown;
|
||||
settings['BoardBorderLineWidth'] = Config.boardBorderLineWidth;
|
||||
settings['BoardInnerLineWidth'] = Config.boardInnerLineWidth;
|
||||
|
|
|
@ -596,6 +596,10 @@
|
|||
"@boardInnerLineWidth": {
|
||||
"description": "Board inner line width"
|
||||
},
|
||||
"standardNotation": "Standard notation",
|
||||
"@standardNotation": {
|
||||
"description": "Standard notation"
|
||||
},
|
||||
"restore": "Restore",
|
||||
"@restore": {
|
||||
"description": "Restore"
|
||||
|
|
|
@ -149,6 +149,7 @@
|
|||
"display": "显示",
|
||||
"boardBorderLineWidth": "棋盘外框线宽",
|
||||
"boardInnerLineWidth": "棋盘内部线宽",
|
||||
"standardNotation": "标准棋谱格式",
|
||||
"restore": "重置",
|
||||
"restoreDefaultSettings": "恢复默认设置",
|
||||
"exitApp": "App 将退出。",
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:sanmill/common/config.dart';
|
||||
|
||||
import 'position.dart';
|
||||
import 'types.dart';
|
||||
|
||||
|
@ -91,12 +93,38 @@ class GameRecorder {
|
|||
}
|
||||
|
||||
String buildMoveHistoryText({cols = 2}) {
|
||||
//
|
||||
var moveHistoryText = '';
|
||||
int k = 1;
|
||||
String num = "";
|
||||
|
||||
for (var i = 0; i < _history.length; i++) {
|
||||
moveHistoryText += '${i < 9 ? ' ' : ''}${i + 1}. ${_history[i].move} ';
|
||||
if ((i + 1) % cols == 0) moveHistoryText += '\n';
|
||||
if (Config.standardNotationEnabled) {
|
||||
if (k % cols == 1) {
|
||||
num = "${(k + 1) ~/ 2}. ";
|
||||
if (k < 9 * cols) {
|
||||
num = " " + num + " ";
|
||||
}
|
||||
} else {
|
||||
num = "";
|
||||
}
|
||||
if (i + 1 < _history.length &&
|
||||
_history[i + 1].type == MoveType.remove) {
|
||||
moveHistoryText +=
|
||||
'$num${_history[i].notation}${_history[i + 1].notation} ';
|
||||
i++;
|
||||
} else {
|
||||
moveHistoryText += '$num${_history[i].notation} ';
|
||||
}
|
||||
k++;
|
||||
} else {
|
||||
moveHistoryText += '${i < 9 ? ' ' : ''}${i + 1}. ${_history[i].move} ';
|
||||
}
|
||||
|
||||
if (Config.standardNotationEnabled) {
|
||||
if ((k + 1) % cols == 0) moveHistoryText += '\n';
|
||||
} else {
|
||||
if ((i + 1) % cols == 0) moveHistoryText += '\n';
|
||||
}
|
||||
}
|
||||
|
||||
if (moveHistoryText.isEmpty) {
|
||||
|
|
|
@ -40,6 +40,9 @@ class Move {
|
|||
// 'move' is the UCI engine's move-string
|
||||
String? move = "";
|
||||
|
||||
// "notation" is Standard Notation
|
||||
String? notation = "";
|
||||
|
||||
MoveType type = MoveType.none;
|
||||
|
||||
// Used to restore fen step counter when undoing move
|
||||
|
@ -55,6 +58,8 @@ class Move {
|
|||
from = fromFile = fromRank = fromIndex = invalidMove;
|
||||
toFile = int.parse(move![2]);
|
||||
toRank = int.parse(move![4]);
|
||||
to = makeSquare(toFile, toRank);
|
||||
notation = "x${squareToNotation[to]}";
|
||||
//captured = Piece.noPiece;
|
||||
} else if (move!.length == "(1,2)->(3,4)".length) {
|
||||
type = MoveType.move;
|
||||
|
@ -64,12 +69,16 @@ class Move {
|
|||
fromIndex = squareToIndex[from] ?? invalidMove;
|
||||
toFile = int.parse(move![8]);
|
||||
toRank = int.parse(move![10]);
|
||||
to = makeSquare(toFile, toRank);
|
||||
notation = "${squareToNotation[from]}-${squareToNotation[to]}";
|
||||
removed = Piece.noPiece;
|
||||
} else if (move!.length == "(1,2)".length) {
|
||||
type = MoveType.place;
|
||||
from = fromFile = fromRank = fromIndex = invalidMove;
|
||||
toFile = int.parse(move![1]);
|
||||
toRank = int.parse(move![3]);
|
||||
to = makeSquare(toFile, toRank);
|
||||
notation = "${squareToNotation[to]}";
|
||||
removed = Piece.noPiece;
|
||||
} else if (move == "draw") {
|
||||
// TODO
|
||||
|
@ -78,7 +87,6 @@ class Move {
|
|||
assert(false);
|
||||
}
|
||||
|
||||
to = makeSquare(toFile, toRank);
|
||||
toIndex = squareToIndex[to] ?? invalidMove;
|
||||
}
|
||||
|
||||
|
@ -315,6 +323,48 @@ Map<int, int> squareToIndex = {
|
|||
31: 0
|
||||
};
|
||||
|
||||
/*
|
||||
a b c d e f g
|
||||
7 X --- X --- X 7
|
||||
|\ | /|
|
||||
6 | X - X - X | 6
|
||||
| |\ | /| |
|
||||
5 | | X-X-X | | 5
|
||||
4 X-X-X X-X-X 4
|
||||
3 | | X-X-X | | 3
|
||||
| |/ | \| |
|
||||
2 | X - X - X | 2
|
||||
|/ | \|
|
||||
1 X --- X --- X 1
|
||||
a b c d e f g
|
||||
*/
|
||||
Map<int, String> squareToNotation = {
|
||||
8: "d5",
|
||||
9: "e5",
|
||||
10: "e4",
|
||||
11: "e3",
|
||||
12: "d3",
|
||||
13: "c3",
|
||||
14: "c4",
|
||||
15: "c5",
|
||||
16: "d6",
|
||||
17: "f6",
|
||||
18: "f4",
|
||||
19: "f2",
|
||||
20: "d2",
|
||||
21: "b2",
|
||||
22: "b4",
|
||||
23: "b6",
|
||||
24: "d7",
|
||||
25: "g7",
|
||||
26: "g4",
|
||||
27: "g1",
|
||||
28: "d1",
|
||||
29: "a1",
|
||||
30: "a4",
|
||||
31: "a7"
|
||||
};
|
||||
|
||||
Map<int, int> indexToSquare = squareToIndex.map((k, v) => MapEntry(v, k));
|
||||
|
||||
enum GameResult { pending, win, lose, draw, none }
|
||||
|
|
|
@ -498,4 +498,14 @@ class _GameSettingsPageState extends State<GameSettingsPage> {
|
|||
|
||||
Config.save();
|
||||
}
|
||||
|
||||
setStandardNotationEnabled(bool value) async {
|
||||
setState(() {
|
||||
Config.standardNotationEnabled = value;
|
||||
});
|
||||
|
||||
print("[config] standardNotationEnabled: $value");
|
||||
|
||||
Config.save();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -249,6 +249,13 @@ class _PersonalizationSettingsPageState
|
|||
titleString: S.of(context).boardTop,
|
||||
onTap: setBoardTop,
|
||||
),
|
||||
ListItemDivider(),
|
||||
SettingsSwitchListTile(
|
||||
context: context,
|
||||
value: Config.standardNotationEnabled,
|
||||
onChanged: setStandardNotationEnabled,
|
||||
titleString: S.of(context).standardNotation,
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: AppTheme.sizedBoxHeight),
|
||||
|
@ -304,4 +311,14 @@ class _PersonalizationSettingsPageState
|
|||
|
||||
Config.save();
|
||||
}
|
||||
|
||||
setStandardNotationEnabled(bool value) async {
|
||||
setState(() {
|
||||
Config.standardNotationEnabled = value;
|
||||
});
|
||||
|
||||
print("[config] standardNotationEnabled: $value");
|
||||
|
||||
Config.save();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue