kida fixed promotion

devUi
dstuck 2025-06-21 16:09:55 +02:00 committed by stuckd
parent d5cfa77e09
commit cbad409db7
2 changed files with 79 additions and 42 deletions

View File

@ -22,6 +22,9 @@ public class ButtonMovePieceListener implements ActionListener {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (game.isPromotionMove(this.mv))
game.doPromotionMove(this.sf.showPromotion(), mv.getFrom(), mv.getTo());
else
this.game.playMove(this.mv); this.game.playMove(this.mv);
if (this.game.isDraw()) { if (this.game.isDraw()) {

View File

@ -127,6 +127,33 @@ public class Game {
this.board.undoMove(); this.board.undoMove();
this.movelist.removeLast(); this.movelist.removeLast();
} }
/**
* Plays the move on the board and adds it to the movelist
*
* @param origin The square from wich it moves from.
* @param desination The square where it will move to.
*/
public void playMove(Square origin, Square desination) {
Move move = new Move(origin, desination);
this.board.doMove(move);
this.movelist.add(move);
}
public boolean isMate() {
return board.isMated();
}
public boolean isDraw() {
return board.isDraw();
}
public int getActivePlayer() {
if (board.getSideToMove() == Side.WHITE) {
return 1;
}
return 2;
}
public boolean isMate() { public boolean isMate() {
return board.isMated(); return board.isMated();
@ -219,8 +246,7 @@ public class Game {
promotedTo = Piece.WHITE_QUEEN; promotedTo = Piece.WHITE_QUEEN;
} }
Move promotionMove = new Move(origin, destination, promotedTo); Move promotionMove = new Move(origin, destination, promotedTo);
board.doMove(promotionMove); playMove(promotionMove);
movelist.add(promotionMove);
} }
public String toFEN() { public String toFEN() {
@ -264,4 +290,12 @@ public class Game {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return this.board; return this.board;
} }
public String toFEN() {
board.toString();
return board.getFen();
}
public Square getSelectedSquare() {
return this.getSelectedSquare();
}
} }