movement
This commit is contained in:
parent
2e04e59529
commit
0d64a41fa1
|
|
@ -20,3 +20,6 @@ public class Main {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -216,12 +216,25 @@ public class Board {
|
|||
|
||||
switch (piece.getType()) {
|
||||
case Pawn:
|
||||
int forwardY = y + dir;
|
||||
if (getPieceAt(x, forwardY) == null)
|
||||
int forwardY = y + dir;
|
||||
|
||||
// Move one square forward if it's empty
|
||||
if (isInBounds(x, forwardY) && getPieceAt(x, forwardY) == null) {
|
||||
moves.add(new int[] {x, forwardY});
|
||||
|
||||
// Move two squares forward if at starting position and both squares are empty
|
||||
int twoForwardY = y + 2 * dir;
|
||||
boolean atStartingRank = (piece.isWhite() && y == 1) || (!piece.isWhite() && y == 6);
|
||||
if (atStartingRank && isInBounds(x, twoForwardY) && getPieceAt(x, twoForwardY) == null) {
|
||||
moves.add(new int[] {x, twoForwardY});
|
||||
}
|
||||
}
|
||||
|
||||
// Capture diagonally
|
||||
Piece diagLeft = getPieceAt(x - 1, forwardY);
|
||||
if (diagLeft != null && diagLeft.isWhite() != piece.isWhite())
|
||||
moves.add(new int[] {x - 1, forwardY});
|
||||
|
||||
Piece diagRight = getPieceAt(x + 1, forwardY);
|
||||
if (diagRight != null && diagRight.isWhite() != piece.isWhite())
|
||||
moves.add(new int[] {x + 1, forwardY});
|
||||
|
|
|
|||
Loading…
Reference in New Issue