Skip to content

Commit

Permalink
Refactored some stuff to shorten the code
Browse files Browse the repository at this point in the history
  • Loading branch information
john committed Apr 21, 2016
1 parent 15701da commit d868467
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/model/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,29 @@ public ArrayList<Move> generateMoves(Piece p) {
up = p.getColor() == Color.BLACK || p.getType() == Type.KING;
down = p.getColor() == Color.RED || p.getType() == Type.KING;
if (up) {
// up left
Move upLeft = new Move(p.getLocation(), new Location(row - 1, col - 1));
if (isValidMove(upLeft)) {
avail_moves.add(new Move(p.getLocation(), new Location(row - 1, col - 1)));
avail_moves.add(upLeft);
}

// up right
Move upRight = new Move(p.getLocation(), new Location(row - 1, col + 1));
if (isValidMove(upRight)) {
avail_moves.add(new Move(p.getLocation(), new Location(row - 1, col + 1)));
avail_moves.add(upRight);
}
}
if (down) {
// down left
Move downLeft = new Move(p.getLocation(), new Location(row + 1, col - 1));
if (isValidMove(downLeft)) {
avail_moves.add(new Move(p.getLocation(), new Location(row + 1, col - 1)));
avail_moves.add(downLeft);
}

// down right
Move downRight = new Move(p.getLocation(), new Location(row + 1, col + 1));
if (isValidMove(downRight)) {
avail_moves.add(new Move(p.getLocation(), new Location(row + 1, col + 1)));
avail_moves.add(downRight);
}
}
return avail_moves;
Expand Down

0 comments on commit d868467

Please sign in to comment.