public class Chessboard { public static void main(String args[]){ 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] board = new char[8][8]; // initialize an empty chessboard 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 printChessboard(board); movePiece(board, 6, 1, 5, 1); printChessboard(board); movePiece(board, 1, 6, 2, 6); printChessboard(board); } static void printChessboard(char[][] chessboard){ System.out.println("---------------"); for(int row = 0; row < 8; row++){ for(int col = 0; col < 8; col++){ System.out.print(chessboard[row][col]); System.out.print(' '); } System.out.println(""); } } static void movePiece(char[][] chessboard, int from_row, int from_col, int to_row, int to_col){ chessboard[to_row][to_col] = chessboard[from_row][from_col]; // empty the location from where the piece was moved chessboard[from_row][from_col] = ' '; } }