flutter: 目前可以用灰色显示移除的棋子
This commit is contained in:
parent
43a9eff2d8
commit
595fd5371f
|
@ -95,6 +95,7 @@ class Battle {
|
||||||
newGame() {
|
newGame() {
|
||||||
Battle.shared.position.init();
|
Battle.shared.position.init();
|
||||||
_focusIndex = _blurIndex = Move.invalidValue;
|
_focusIndex = _blurIndex = Move.invalidValue;
|
||||||
|
cmdlist = [""];
|
||||||
}
|
}
|
||||||
|
|
||||||
select(int pos) {
|
select(int pos) {
|
||||||
|
@ -192,7 +193,7 @@ class Battle {
|
||||||
String winner = position.winner;
|
String winner = position.winner;
|
||||||
|
|
||||||
if (winner != Color.nobody) {
|
if (winner != Color.nobody) {
|
||||||
//resumeAiThreads(position.sideToMove);
|
//resumeAiThreads(position.sideToMove());
|
||||||
// TODO
|
// TODO
|
||||||
} else {
|
} else {
|
||||||
// pauseThreads();
|
// pauseThreads();
|
||||||
|
|
|
@ -155,6 +155,9 @@ class Move {
|
||||||
toFile = int.parse(move[1]);
|
toFile = int.parse(move[1]);
|
||||||
toRank = int.parse(move[3]);
|
toRank = int.parse(move[3]);
|
||||||
captured = Piece.noPiece;
|
captured = Piece.noPiece;
|
||||||
|
} else if (move == "draw") {
|
||||||
|
// TODO
|
||||||
|
print("Computer request draw");
|
||||||
} else {
|
} else {
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
@ -198,6 +201,10 @@ class Move {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool validateEngineMove(String move) {
|
static bool validateEngineMove(String move) {
|
||||||
|
if (move == "draw") {
|
||||||
|
return true; // TODO
|
||||||
|
}
|
||||||
|
|
||||||
if (move == null || move.length > "(3,1)->(2,1)".length) return false;
|
if (move == null || move.length > "(3,1)->(2,1)".length) return false;
|
||||||
|
|
||||||
String sets = "0123456789(,)->";
|
String sets = "0123456789(,)->";
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Position {
|
||||||
|
|
||||||
Map<String, int> score = {Color.black: 0, Color.white: 0, Color.draw: 0};
|
Map<String, int> score = {Color.black: 0, Color.white: 0, Color.draw: 0};
|
||||||
|
|
||||||
int currentSquare;
|
int currentSquare = 0;
|
||||||
int nPlayed = 0;
|
int nPlayed = 0;
|
||||||
|
|
||||||
String cmdline;
|
String cmdline;
|
||||||
|
@ -478,14 +478,21 @@ class Position {
|
||||||
}
|
}
|
||||||
|
|
||||||
int setPosition(Rule newRule) {
|
int setPosition(Rule newRule) {
|
||||||
|
result = GameResult.pending;
|
||||||
|
|
||||||
rule = new Rule(); // TODO
|
rule = new Rule(); // TODO
|
||||||
|
|
||||||
gamePly = 0;
|
gamePly = 0;
|
||||||
rule50 = 0;
|
rule50 = 0;
|
||||||
|
pliesFromNull = 0;
|
||||||
|
|
||||||
phase = Phase.ready;
|
gameOverReason = GameOverReason.noReason;
|
||||||
|
phase = Phase.placing;
|
||||||
setSideToMove(Color.black);
|
setSideToMove(Color.black);
|
||||||
action = Act.place;
|
action = Act.place;
|
||||||
|
currentSquare = 0;
|
||||||
|
|
||||||
|
cmdline = "";
|
||||||
|
|
||||||
for (int i = 0; i < _grid.length; i++) {
|
for (int i = 0; i < _grid.length; i++) {
|
||||||
_grid[i] = Piece.noPiece;
|
_grid[i] = Piece.noPiece;
|
||||||
|
@ -796,7 +803,7 @@ class Position {
|
||||||
return set_position(&RULES[ruleIndex - 1]) >= 0 ? true : false;
|
return set_position(&RULES[ruleIndex - 1]) >= 0 ? true : false;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if (cmd.substring(0, 5) == "Player") {
|
if (cmd.length > 6 && cmd.substring(0, 5) == "Player") {
|
||||||
if (cmd[6] == '1') {
|
if (cmd[6] == '1') {
|
||||||
return resign(Color.black);
|
return resign(Color.black);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1531,7 +1538,7 @@ class Position {
|
||||||
rankNumber * fileNumber) return true;
|
rankNumber * fileNumber) return true;
|
||||||
|
|
||||||
// Can fly
|
// Can fly
|
||||||
if (pieceCountOnBoard[sideToMove] <= rule.nPiecesAtLeast &&
|
if (pieceCountOnBoard[sideToMove()] <= rule.nPiecesAtLeast &&
|
||||||
rule.allowFlyWhenRemainThreePieces) {
|
rule.allowFlyWhenRemainThreePieces) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1633,6 +1640,7 @@ class Position {
|
||||||
void changeSideToMove() {
|
void changeSideToMove() {
|
||||||
them = _sideToMove;
|
them = _sideToMove;
|
||||||
_sideToMove = Color.opponent(_sideToMove);
|
_sideToMove = Color.opponent(_sideToMove);
|
||||||
|
print("Change sideToMove to $_sideToMove");
|
||||||
}
|
}
|
||||||
|
|
||||||
get halfMove => _recorder.halfMove;
|
get halfMove => _recorder.halfMove;
|
||||||
|
|
|
@ -124,7 +124,7 @@ class _BattlePageState extends State<BattlePage> {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Act.remove:
|
case Act.remove:
|
||||||
if (position.remove_piece(sq)) {
|
if (position.removePiece(sq)) {
|
||||||
// 播放音效
|
// 播放音效
|
||||||
//playSound(GAME_SOUND_REMOVE, position.side_to_move());
|
//playSound(GAME_SOUND_REMOVE, position.side_to_move());
|
||||||
result = true;
|
result = true;
|
||||||
|
@ -174,13 +174,10 @@ class _BattlePageState extends State<BattlePage> {
|
||||||
// AI设置
|
// AI设置
|
||||||
// 如果还未决出胜负
|
// 如果还未决出胜负
|
||||||
if (position.winner == Color.nobody) {
|
if (position.winner == Color.nobody) {
|
||||||
//resumeAiThreads(position.sideToMove);
|
// Color.black is TODO
|
||||||
|
//resumeAiThreads(position.sideToMove());
|
||||||
engineToGo();
|
engineToGo();
|
||||||
}
|
}
|
||||||
// 如果已经决出胜负
|
|
||||||
else {
|
|
||||||
//pauseThreads();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Battle.shared.sideToMove = position.sideToMove();
|
Battle.shared.sideToMove = position.sideToMove();
|
||||||
|
@ -251,39 +248,40 @@ class _BattlePageState extends State<BattlePage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
engineToGo() async {
|
engineToGo() async {
|
||||||
//
|
while (Battle.shared.position.sideToMove() == Color.black) {
|
||||||
changeStatus('对方思考中...');
|
changeStatus('对方思考中...');
|
||||||
|
|
||||||
final response = await widget.engine.search(Battle.shared.position);
|
final response = await widget.engine.search(Battle.shared.position);
|
||||||
|
|
||||||
if (response.type == 'move') {
|
if (response.type == 'move') {
|
||||||
//
|
//
|
||||||
Move mv = response.value;
|
Move mv = response.value;
|
||||||
final Move move = new Move(mv.move);
|
final Move move = new Move(mv.move);
|
||||||
|
|
||||||
//Battle.shared.move = move;
|
//Battle.shared.move = move;
|
||||||
Battle.shared.command(move.move);
|
Battle.shared.command(move.move);
|
||||||
|
|
||||||
final result = Battle.shared.scanBattleResult();
|
final result = Battle.shared.scanBattleResult();
|
||||||
|
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case GameResult.pending:
|
case GameResult.pending:
|
||||||
changeStatus('请走棋...');
|
changeStatus('请走棋...');
|
||||||
break;
|
break;
|
||||||
case GameResult.win:
|
case GameResult.win:
|
||||||
gotWin();
|
gotWin();
|
||||||
break;
|
break;
|
||||||
case GameResult.lose:
|
case GameResult.lose:
|
||||||
gotLose();
|
gotLose();
|
||||||
break;
|
break;
|
||||||
case GameResult.draw:
|
case GameResult.draw:
|
||||||
gotDraw();
|
gotDraw();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
changeStatus('Error: ${response.type}');
|
||||||
}
|
}
|
||||||
//
|
|
||||||
} else {
|
|
||||||
//
|
|
||||||
changeStatus('Error: ${response.type}');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,9 +306,8 @@ class _BattlePageState extends State<BattlePage> {
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title:
|
title: Text('新局?', style: TextStyle(color: Properties.primaryColor)),
|
||||||
Text('放弃对局?', style: TextStyle(color: Properties.primaryColor)),
|
content: SingleChildScrollView(child: Text('开始新局?')),
|
||||||
content: SingleChildScrollView(child: Text('你确定要放弃当前的对局吗?')),
|
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
FlatButton(child: Text('确定'), onPressed: confirm),
|
FlatButton(child: Text('确定'), onPressed: confirm),
|
||||||
FlatButton(child: Text('取消'), onPressed: cancel),
|
FlatButton(child: Text('取消'), onPressed: cancel),
|
||||||
|
|
Loading…
Reference in New Issue