Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add move with uci param and return move result #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions lib/src/chess_board_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,41 @@ class ChessBoardController extends ValueNotifier<Chess> {
super(game);

/// Makes move on the board
void makeMove({required String from, required String to}) {
game.move({"from": from, "to": to});
bool makeMove({required String from, required String to}) {
bool res = game.move({"from": from, "to": to});
notifyListeners();
return res;
}

/// Makes move on the board
bool makeMoveUci({required String uci}) {
String src = uci.substring(0, 2);
String dst = uci.substring(2, 4);
String promotion = uci.substring(4);
if (promotion.isEmpty)
return makeMove(from: src, to: dst);
else
return makeMoveWithPromotion(
from: src, to: dst, pieceToPromoteTo: promotion);
}

/// Makes move and promotes pawn to piece (from is a square like d4, to is also a square like e3, pieceToPromoteTo is a String like "Q".
/// pieceToPromoteTo String will be changed to enum in a future update and this method will be deprecated in the future
void makeMoveWithPromotion(
bool makeMoveWithPromotion(
{required String from,
required String to,
required String pieceToPromoteTo}) {
game.move({"from": from, "to": to, "promotion": pieceToPromoteTo});
bool res =
game.move({"from": from, "to": to, "promotion": pieceToPromoteTo});
notifyListeners();
return res;
}

/// Makes move on the board
void makeMoveWithNormalNotation(String move) {
game.move(move);
bool makeMoveWithNormalNotation(String move) {
bool res = game.move(move);
notifyListeners();
return res;
}

void undoMove() {
Expand Down