kida fixed promotion
parent
d5cfa77e09
commit
cbad409db7
|
|
@ -22,7 +22,10 @@ public class ButtonMovePieceListener implements ActionListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
this.game.playMove(this.mv);
|
if (game.isPromotionMove(this.mv))
|
||||||
|
game.doPromotionMove(this.sf.showPromotion(), mv.getFrom(), mv.getTo());
|
||||||
|
else
|
||||||
|
this.game.playMove(this.mv);
|
||||||
|
|
||||||
if (this.game.isDraw()) {
|
if (this.game.isDraw()) {
|
||||||
this.game.stopClock();
|
this.game.stopClock();
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
@ -156,13 +183,13 @@ public class Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopClock() {
|
public void stopClock() {
|
||||||
clock.endGame();
|
clock.endGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPromotionMove(Move move) {
|
public boolean isPromotionMove(Move move) {
|
||||||
return ((move.getTo().getRank().equals(Rank.RANK_8) || move.getTo().getRank().equals(Rank.RANK_1)) &&
|
return ((move.getTo().getRank().equals(Rank.RANK_8) || move.getTo().getRank().equals(Rank.RANK_1)) &&
|
||||||
(board.getPiece(move.getFrom()) == Piece.BLACK_PAWN || board.getPiece(move.getFrom()) == Piece.WHITE_PAWN));
|
(board.getPiece(move.getFrom()) == Piece.BLACK_PAWN || board.getPiece(move.getFrom()) == Piece.WHITE_PAWN));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a list of all legal moveable squares from the current board state.
|
* Retrieves a list of all legal moveable squares from the current board state.
|
||||||
|
|
@ -188,39 +215,38 @@ public class Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doPromotionMove(int piece, Square origin, Square destination) {
|
public void doPromotionMove(int piece, Square origin, Square destination) {
|
||||||
System.out.println(piece);
|
System.out.println(piece);
|
||||||
Piece promotedTo;
|
Piece promotedTo;
|
||||||
switch(piece) {
|
switch (piece) {
|
||||||
case 7:
|
case 7:
|
||||||
promotedTo = Piece.BLACK_KNIGHT;
|
promotedTo = Piece.BLACK_KNIGHT;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
promotedTo = Piece.BLACK_QUEEN;
|
promotedTo = Piece.BLACK_QUEEN;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
promotedTo = Piece.BLACK_ROOK;
|
promotedTo = Piece.BLACK_ROOK;
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
promotedTo = Piece.BLACK_BISHOP;
|
promotedTo = Piece.BLACK_BISHOP;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
promotedTo = Piece.WHITE_KNIGHT;
|
promotedTo = Piece.WHITE_KNIGHT;
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
promotedTo = Piece.WHITE_QUEEN;
|
promotedTo = Piece.WHITE_QUEEN;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
promotedTo = Piece.WHITE_ROOK;
|
promotedTo = Piece.WHITE_ROOK;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
promotedTo = Piece.WHITE_BISHOP;
|
promotedTo = Piece.WHITE_BISHOP;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue