kida fixed promotion

buttonActions
dstuck 2025-06-21 16:09:55 +02:00
parent 8cb621d804
commit 64cf321511
2 changed files with 58 additions and 51 deletions

View File

@ -22,7 +22,11 @@ public class ButtonMovePieceListener implements ActionListener {
@Override
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);
if (this.game.isDraw()) {
this.game.stopClock();
this.sf.setBoardMode(BoardMode.finished);

View File

@ -162,7 +162,7 @@ public class Game {
public void doPromotionMove(int piece, Square origin, Square destination) {
System.out.println(piece);
Piece promotedTo;
switch(piece) {
switch (piece) {
case 7:
promotedTo = Piece.BLACK_KNIGHT;
break;
@ -191,12 +191,15 @@ public class Game {
promotedTo = Piece.WHITE_QUEEN;
}
Move promotionMove = new Move(origin, destination, promotedTo);
board.doMove(promotionMove);
movelist.add(promotionMove);
playMove(promotionMove);
}
public String toFEN() {
board.toString();
return board.getFen();
}
public Square getSelectedSquare() {
return this.getSelectedSquare();
}
}