Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Commit

Permalink
Started working on en passant (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyAZ authored May 26, 2017
1 parent 6723a68 commit 3452827
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Java Problem Sets/Chess/src/control/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void main(String[] args) {
gc = new GameConductor();
board.placePieces();
window = new Window();
gc.mySide = false;
gc.mySide = true;
if (gc.mySide == true)
gc.startListening();
}
Expand Down
22 changes: 22 additions & 0 deletions Java Problem Sets/Chess/src/pieces/Pawn.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.HashSet;

import board.Cell;
import control.Main;

public class Pawn extends Piece {

Expand Down Expand Up @@ -57,6 +58,8 @@ public HashSet<Cell> getPossibleMoves() {

}

addEnPassant(possibleMoves);

removeIllegalMoves(possibleMoves);

return possibleMoves;
Expand Down Expand Up @@ -109,4 +112,23 @@ public HashSet<Cell> getPossibleMovesWithoutCheck() {
return possibleMoves;
}

private void addEnPassant(HashSet<Cell> possibleMoves) {
if (Main.gc.network.state.isEmpty())
return;

String[] parts = Main.gc.network.state.get(Main.gc.network.state.size() - 1).split(" ");

if (!parts[1].equals("Pawn"))
return;

if ((Main.gc.notationToCell(parts[3]) == getBoard().getCell(location.x + 1, location.y))
&& (Main.gc.notationToCell(parts[3]) == getBoard().getCell(location.x + 1, location.y - 2))) {
possibleMoves.add(getBoard().getCell(location.x + 1, location.y - 1));
}
if ((Main.gc.notationToCell(parts[3]) == getBoard().getCell(location.x - 1, location.y))
&& (Main.gc.notationToCell(parts[3]) == getBoard().getCell(location.x - 1, location.y - 2))) {
possibleMoves.add(getBoard().getCell(location.x - 1, location.y - 1));
}
}

}

0 comments on commit 3452827

Please sign in to comment.