better undo
This commit is contained in:
@@ -30,23 +30,6 @@ public class Game {
|
||||
playerTurn = Color.getEnemy(playerTurn);
|
||||
}
|
||||
|
||||
public boolean checkPromotion(Coordinate pieceCoords) {
|
||||
|
||||
Piece piece = getBoard().pieceAt(pieceCoords);
|
||||
|
||||
if (piece == null || !(piece instanceof Pawn))
|
||||
return false;
|
||||
|
||||
int destY = pieceCoords.getY();
|
||||
|
||||
int enemyLine = piece.getColor() == Color.White ? 0 : 7;
|
||||
|
||||
if (destY != enemyLine)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public GameStatus checkGameStatus() {
|
||||
final Color enemy = Color.getEnemy(getPlayerTurn());
|
||||
|
||||
@@ -63,20 +46,38 @@ public class Game {
|
||||
}
|
||||
|
||||
public boolean pawnShouldBePromoted() {
|
||||
if (pawnShouldBePromoted(Color.White))
|
||||
return true;
|
||||
return pawnShouldBePromoted(Color.Black);
|
||||
return pawnPromotePosition() != null;
|
||||
}
|
||||
|
||||
private boolean pawnShouldBePromoted(Color color) {
|
||||
/**
|
||||
*
|
||||
* @return Null if there is no pawn to promote
|
||||
*/
|
||||
public Coordinate pawnPromotePosition() {
|
||||
Coordinate piecePos = pawnPromotePosition(Color.White);
|
||||
if (piecePos != null)
|
||||
return piecePos;
|
||||
return pawnPromotePosition(Color.Black);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Null if there is no pawn to promote
|
||||
*/
|
||||
private Coordinate pawnPromotePosition(Color color) {
|
||||
int enemyLineY = color == Color.White ? 0 : 7;
|
||||
|
||||
for (int x = 0; x < Coordinate.VALUE_MAX; x++) {
|
||||
if (checkPromotion(new Coordinate(x, enemyLineY)))
|
||||
return true;
|
||||
Coordinate pieceCoords = new Coordinate(x, enemyLineY);
|
||||
Piece piece = getBoard().pieceAt(pieceCoords);
|
||||
|
||||
if (piece == null || !(piece instanceof Pawn) || piece.getColor() != color)
|
||||
continue;
|
||||
|
||||
return pieceCoords;
|
||||
}
|
||||
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user