flutter: rule50: Fix rule50 doesn't work

This commit is contained in:
Calcitem 2021-04-17 13:10:53 +08:00
parent adf331811b
commit 4921966b77
4 changed files with 27 additions and 6 deletions

View File

@ -200,9 +200,9 @@
"@loseReasonTimeOver": {
"description": "Time Over"
},
"drawReasonRule50": "Rule50",
"drawReasonRule50": "In moving phase, no piece has been removed in the last fifty moves.",
"@drawReasonRule50": {
"description": "Rule50"
"description": "In moving phase, no piece has been removed in the last fifty moves."
},
"drawReasonBoardIsFull": "Draw, because the board is full",
"@drawReasonBoardIsFull": {

View File

@ -50,7 +50,7 @@
"loseReasonNoWay": "被闷杀。",
"loseReasonBoardIsFull": "因棋盘摆满而无路可走。",
"loseReasonTimeOver": "超时判负。",
"drawReasonRule50": "连续超过50步未吃子判和。",
"drawReasonRule50": "走子阶段连续50步未吃子判和。",
"drawReasonBoardIsFull": "棋盘摆满,无路可走,判和。",
"drawReasonThreefoldRepetition": "三次重复局面和。",
"gameOverUnknownReason": "游戏结束,原因未知!",

View File

@ -27,7 +27,7 @@ import 'types.dart';
import 'zobrist.dart';
int repetition = 0;
late List<int> posKeyHistory;
List<int> posKeyHistory = [];
class StateInfo {
// Copied when making a move
@ -334,6 +334,16 @@ class Position {
++gamePly;
++st.pliesFromNull;
if (record != null && record!.length > "-(1,2)".length) {
if (posKeyHistory.length == 0 ||
(posKeyHistory.length > 0 &&
st.key != posKeyHistory[posKeyHistory.length - 1])) {
posKeyHistory.add(st.key);
}
} else {
posKeyHistory.clear();
}
this.move = m;
recorder!.moveIn(m, this); // TODO: Is Right?
@ -715,8 +725,8 @@ class Position {
return true;
}
// TOOD: cpp: posKeyHistory.size() > rule.maxStepsLedToDraw
if (rule.maxStepsLedToDraw > 0 && st.rule50 > rule.maxStepsLedToDraw) {
if (rule.maxStepsLedToDraw > 0 &&
posKeyHistory.length > rule.maxStepsLedToDraw) {
setGameOver(PieceColor.draw, GameOverReason.drawReasonRule50);
return true;
}

View File

@ -26,6 +26,7 @@ import 'package:sanmill/engine/native_engine.dart';
import 'package:sanmill/generated/l10n.dart';
import 'package:sanmill/main.dart';
import 'package:sanmill/mill/game.dart';
import 'package:sanmill/mill/position.dart';
import 'package:sanmill/mill/types.dart';
import 'package:sanmill/services/audios.dart';
import 'package:sanmill/style/app_theme.dart';
@ -227,6 +228,16 @@ class _GamePageState extends State<GamePage> with RouteAware {
++position.st.rule50;
++position.st.pliesFromNull;
if (position.record.length > "-(1,2)".length) {
if (posKeyHistory.length == 0 ||
(posKeyHistory.length > 0 &&
position.st.key != posKeyHistory[posKeyHistory.length - 1])) {
posKeyHistory.add(position.st.key);
}
} else {
posKeyHistory.clear();
}
//position.move = m;
Move m = Move(position.record);