added classes for each piece, with possible moves. Also updated board initialization to include all pieces.
parent
b5dc5a4228
commit
17e81feac0
@ -0,0 +1,18 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Bishop extends Piece {
|
||||
public Bishop(boolean black) {
|
||||
super(black);
|
||||
}
|
||||
|
||||
public ArrayList<BoardCoordinate> getPossibleMoves(BoardCoordinate position) {
|
||||
ArrayList<BoardCoordinate> possibleMoves = new ArrayList<>();
|
||||
for(int i = 1; i <= 7; i++) {
|
||||
possibleMoves.add(new BoardCoordinate(position.x - i, position.y - i));
|
||||
possibleMoves.add(new BoardCoordinate(position.x - i, position.y + i));
|
||||
possibleMoves.add(new BoardCoordinate(position.x + i, position.y - i));
|
||||
possibleMoves.add(new BoardCoordinate(position.x + i, position.y + i));
|
||||
}
|
||||
return possibleMoves;
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class King extends Piece {
|
||||
public King(boolean black) {
|
||||
super(black);
|
||||
}
|
||||
|
||||
public ArrayList<BoardCoordinate> getPossibleMoves(BoardCoordinate position) {
|
||||
ArrayList<BoardCoordinate> possibleMoves = new ArrayList<>();
|
||||
possibleMoves.add(new BoardCoordinate(position.x - 1, position.y - 1));
|
||||
possibleMoves.add(new BoardCoordinate(position.x - 1, position.y + 1));
|
||||
possibleMoves.add(new BoardCoordinate(position.x - 1, position.y));
|
||||
possibleMoves.add(new BoardCoordinate(position.x + 1, position.y - 1));
|
||||
possibleMoves.add(new BoardCoordinate(position.x + 1, position.y + 1));
|
||||
possibleMoves.add(new BoardCoordinate(position.x + 1, position.y));
|
||||
possibleMoves.add(new BoardCoordinate(position.x, position.y + 1));
|
||||
possibleMoves.add(new BoardCoordinate(position.x, position.y - 1));
|
||||
return possibleMoves;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Pawn extends Piece {
|
||||
public Pawn(boolean black) {
|
||||
super(black);
|
||||
}
|
||||
|
||||
public ArrayList<BoardCoordinate> getPossibleMoves(BoardCoordinate position) {
|
||||
ArrayList<BoardCoordinate> possibleMoves = new ArrayList<>();
|
||||
if (this.black) {
|
||||
possibleMoves.add(new BoardCoordinate(position.x, position.y + 1));
|
||||
} else {
|
||||
possibleMoves.add(new BoardCoordinate(position.x, position.y - 1));
|
||||
}
|
||||
return possibleMoves;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Queen extends Piece {
|
||||
public Queen(boolean black) {
|
||||
super(black);
|
||||
}
|
||||
|
||||
public ArrayList<BoardCoordinate> getPossibleMoves(BoardCoordinate position) {
|
||||
ArrayList<BoardCoordinate> possibleMoves = new ArrayList<>();
|
||||
for(int i = 1; i <= 7; i++) {
|
||||
possibleMoves.add(new BoardCoordinate(position.x - i, position.y - i));
|
||||
possibleMoves.add(new BoardCoordinate(position.x - i, position.y + i));
|
||||
possibleMoves.add(new BoardCoordinate(position.x + i, position.y - i));
|
||||
possibleMoves.add(new BoardCoordinate(position.x + i, position.y + i));
|
||||
possibleMoves.add(new BoardCoordinate(position.x - i, position.y));
|
||||
possibleMoves.add(new BoardCoordinate(position.x + i, position.y));
|
||||
possibleMoves.add(new BoardCoordinate(position.x, position.y - i));
|
||||
possibleMoves.add(new BoardCoordinate(position.x, position.y + i));
|
||||
}
|
||||
return possibleMoves;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Rook extends Piece {
|
||||
public Rook(boolean black) {
|
||||
super(black);
|
||||
}
|
||||
|
||||
public ArrayList<BoardCoordinate> getPossibleMoves(BoardCoordinate position) {
|
||||
ArrayList<BoardCoordinate> possibleMoves = new ArrayList<>();
|
||||
for(int i = 1; i <= 7; i++) {
|
||||
possibleMoves.add(new BoardCoordinate(position.x - i, position.y));
|
||||
possibleMoves.add(new BoardCoordinate(position.x + i, position.y));
|
||||
possibleMoves.add(new BoardCoordinate(position.x, position.y - i));
|
||||
possibleMoves.add(new BoardCoordinate(position.x, position.y + i));
|
||||
}
|
||||
return possibleMoves;
|
||||
}
|
||||
}
|
Reference in new issue