Skip to content
Snippets Groups Projects
Commit 1c6addee authored by dsjohns2's avatar dsjohns2
Browse files

add custom pieces

parent 51119fd8
No related branches found
No related tags found
No related merge requests found
...@@ -40,8 +40,10 @@ public class Game { ...@@ -40,8 +40,10 @@ public class Game {
board[i][j] = new_square; board[i][j] = new_square;
} }
} }
add_piece_to_location(5, 2, "Q", false, true); add_piece_to_location(2, 3, "A", false, true);
add_piece_to_location(6, 3, "", true, false); add_piece_to_location(2, 4, "B", false, true);
add_piece_to_location(5, 3, "A", true, true);
add_piece_to_location(5, 4, "B", true, true);
} }
public void add_piece_to_location(int x, int y, String name, boolean white, boolean occupied){ public void add_piece_to_location(int x, int y, String name, boolean white, boolean occupied){
...@@ -124,12 +126,12 @@ public class Game { ...@@ -124,12 +126,12 @@ public class Game {
public int make_move() throws InterruptedException { public int make_move() throws InterruptedException {
Square[][][] legal_moves = get_all_moves(white_turn, this.board); Square[][][] legal_moves = get_all_moves(white_turn, this.board);
/*
for(int i=0; i<legal_moves.length; i++){ for(int i=0; i<legal_moves.length; i++){
TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(1);
print_board(legal_moves[i]); print_board(legal_moves[i]);
} }
*/
/* Check for end of game */ /* Check for end of game */
if(legal_moves.length == 0){ if(legal_moves.length == 0){
......
...@@ -16,7 +16,7 @@ public class Main { ...@@ -16,7 +16,7 @@ public class Main {
int end_of_game = -1; int end_of_game = -1;
while(end_of_game == -1){ while(end_of_game == -1){
end_of_game = my_game.make_move(); end_of_game = my_game.make_move();
//TimeUnit.SECONDS.sleep(1); TimeUnit.SECONDS.sleep(5);
my_game.print_board(my_game.board); my_game.print_board(my_game.board);
} }
if(end_of_game == 0){ if(end_of_game == 0){
......
...@@ -61,6 +61,12 @@ public class Square { ...@@ -61,6 +61,12 @@ public class Square {
else if(this.name == "Q"){ else if(this.name == "Q"){
return queen_squares(board); return queen_squares(board);
} }
else if(this.name == "A"){
return A_squares(board);
}
else if(this.name == "B"){
return B_squares(board);
}
else{ else{
return king_squares(board); return king_squares(board);
} }
...@@ -261,6 +267,43 @@ public class Square { ...@@ -261,6 +267,43 @@ public class Square {
return squares.toArray(new int[squares.size()][2]); return squares.toArray(new int[squares.size()][2]);
} }
/**
* A helper method returning the possible locations of A piece
* @param board the current state of the board
* @return an array of tuples representing x and y, the locations that can be reached
*/
public int[][] A_squares(Square[][] board) {
List<int[]> squares = new Vector<int[]>();
int x = this.x;
int y = this.y;
for(int i=0; i<=7; i++){
for(int j=0; j<=7; j++){
if(!(i==x && j==y) && board[i][j].name != "K" && board[i][j].name != "A") {
squares.addAll(square_checker(board, x, y, i, j));
}
}
}
return squares.toArray(new int[squares.size()][2]);
}
/**
* A helper method returning the possible locations of B piece
* @param board the current state of the board
* @return an array of tuples representing x and y, the locations that can be reached
*/
public int[][] B_squares(Square[][] board) {
List<int[]> squares = new Vector<int[]>();
int x = this.x;
int y = this.y;
if(x+y % 2 == 0) {
squares.addAll(Arrays.asList(bishop_squares(board)));
}
else {
squares.addAll(Arrays.asList(rook_squares(board)));
}
return squares.toArray(new int[squares.size()][2]);
}
/** /**
* A helper method returning the possible locations of a king * A helper method returning the possible locations of a king
* @param board the current state of the board * @param board the current state of the board
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment