public class Chessboard2 { char[][] board; // Every position on the board // - either contains " " if there is nothing there // - contains an alphabet signifying the piece present // indexing convention [row][column] Chessboard2(){ // initialize an empty chessboard board = new char[8][8]; for(int row = 0; row < 8; row++) for(int col = 0; col < 8; col++) board[row][col] = ' '; board[0][0] = 'r'; // rook board[0][1] = 'h'; // knight / horse board[0][2] = 'b'; // bishop board[0][3] = 'q'; // queen board[0][4] = 'k'; // king board[0][5] = 'b'; // bishop 2 board[0][6] = 'h'; // knight / horse 2 board[0][7] = 'r'; // rook 2 for(int i = 0; i < 8; i++){ board[1][i] = 'p'; // pawn board[6][i] = 'P'; } board[7][0] = 'R'; // rook board[7][1] = 'H'; // knight / horse board[7][2] = 'B'; // bishop board[7][3] = 'Q'; // queen board[7][4] = 'K'; // king board[7][5] = 'B'; // bishop 2 board[7][6] = 'H'; // knight / horse 2 board[7][7] = 'R'; // rook 2 } void printChessboard(){ System.out.println("---------------"); for(int row = 0; row < 8; row++){ for(int col = 0; col < 8; col++){ System.out.print(board[row][col]); System.out.print(' '); } System.out.println(""); } } void movePiece(int from_row, int from_col, int to_row, int to_col){ board[to_row][to_col] = board[from_row][from_col]; // empty the location from where the piece was moved board[from_row][from_col] = ' '; } public static void main(String args[]){ Chessboard2 cb; cb = new Chessboard2(); cb.printChessboard(); cb.movePiece(6, 1, 5, 1); cb.printChessboard(); cb.movePiece(1, 6, 2, 6); cb.printChessboard(); } }