import java.awt.*; public class Board { Piece[][] board; public Board() { board = new Piece[8][8]; for (int i = 0; i <= 7; i++) { board[i][1] = new Pawn(i, 1, "Black"); } for (int i = 0; i <= 7; i++) { board[i][6] = new Pawn(i, 6, "White"); } } public Board(boolean isCopy) { board = new Piece[8][8]; } public void draw(Graphics g) { for (Piece[] row : board) { for (Piece p : row) { if (p != null) p.draw(g); } } } public static boolean inBounds(Position pos) { return (pos.x >= 0 && pos.x <= 7) && (pos.y >= 0 && pos.y <= 7); } public boolean isOpen(Position pos) { return this.getPiece(pos) == null; } public Piece getPiece(Position pos) { return this.board[pos.x][pos.y]; } public Piece getPiece(int x, int y) { return this.board[x][y]; } public void setPiece(int x, int y, Piece p) { this.board[x][y] = p; } public void setPiece(Position pos, Piece p) { this.board[pos.x][pos.y] = p; } public static Board copy(Board b) { Board newBoard = new Board(); for (int i = 0; i <= 7; i++) { for (int j = 0; j <= 7; j++) { Piece p = b.getPiece(i, j); if (p == null) continue; newBoard.board[i][j] = p.copy(); } } return newBoard; } }