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
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()) {

View File

@ -127,6 +127,33 @@ public class Game {
this.board.undoMove();
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() {
return board.isMated();
@ -190,7 +217,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;
@ -219,8 +246,7 @@ 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() {
@ -264,4 +290,12 @@ public class Game {
// TODO Auto-generated method stub
return this.board;
}
public String toFEN() {
board.toString();
return board.getFen();
}
public Square getSelectedSquare() {
return this.getSelectedSquare();
}
}