Introduction to Chess Board Representation Java:
Board representation is the key aspect in the chess design and in general 8X8 grid chess board is designed across many computer based chess games. There are different approaches that were followed while designing the chess board and even there are few cases where a chess board of size 10X12 grid is also used and the main reason to use this type of broad representation is to identify the out of bound and the corresponding illegal moves across the board. In this project an 8X8 grid board is used and the Java applet coding is used to design the board window.
A total of 64 squares are used in this case and the board is represented as an array of integers in the memory using the int variables. All the squared in the board are assigned either black or white color based on few conditions and they are as explained. Graphics object of Java applet class is used to draw the basic board and once the empty board is represented, now the colors to the squares are assigned using setColor method of the graphics class from the Applet package.
Few offset values are assigned to the square initially and they are incremented using the while loop and then the corresponding black and white colors are assigned to the corresponding squares by checking these offset values and this procedure is repeated for all the 64 squares and all the squares are assigned either black or white color. Few characters and alphabets are assigned to each and every square of the board and the colors to the board are assigned by checking the position of these characters using the if loop and this loop iterated till every character choosen is assigned a color.
A special character array is used hold all these characters assigned to the squares and these characters are fetched from the array as per the user requirement based on their index in the array considered. Important conditions like rotating the board at any condition of the game is also handled and the colors to the square of the board are assigned considering these entire rotation angles and the corresponding conditions. A string variable is used to handle the complete rotation aspects of the board and few conditions are used to check the board position using this string variable.