Chess Game Design Java

Design of this chess game is divided in to following modules: 

  1. Board representation
  2. Move representation
  3. Piece representation
  4. Analyzer

Move representation: 

Representing the possible moves is really an important aspect in designing the chess game and this section explains the actual procedure followed to handle all the possible moves in this application. A separate module known as chess engine is designed in this program to handle all the possible moves and a separate module of code is required as the possible moves are really high in a chess game. Move against the human move from the computer side need lot of estimations and eliminations and in there, typical tree search algorithm can be used to search for the best move possible. These moves are mainly decided by the position of the piece on the chess board and few predefined moves are assigned to the piece based on the nature of the piece on the board. A typical switch and case condition loop is used to check the type of piece initially and then based on the case identified the moves are defined. The moves are assigned to these pieces based on the square positions, the corresponding characters assigned to the squares and position of the square on the total board. All the possible conditions are checked for all the pieces with respect to the position of the board initially and later the actual moves against the human moves are done in a separate way. The famous tree search algorithm known as alpha beta pruning algorithm is used to decide the best move for the computers from all the possible moves in front of the computer. To proceed with this algorithm, initially alpha and beta variables are considered and an initial depth is assigned as an integer and then these values are incremented or decremented and compared to follow the tree search process. Moves are represented based on the depth value of the alpha and beta and the kind of piece with respect to this depth position on the chess board. Alpha and beta are used to represent the current square position of the piece that need to be moved and the beta represents the target move and thus from the value of the depth calculated as discussed above, the actual move of the desired piece is decided. Once the best move is decided from all the possible moves, the actual move is shown to the users using the same graphic class of the Java Applet package. All the required action listeners are added to the piece movements and the most common among them are the mouse listeners and the computer always recognizes the moves made by the human player using the mouse action listeners and the moves are compared to the predefined moves saved at the memory with the moves made by the human player and as discussed these moves are identified using the mouse action listeners and even the validity of the moves made by the human player is also checked against many conditions. 

Piece representation: 

The very next once the move representation is done is to represent the graphical user interface of the pieces and the corresponding moves of them on the chess board considered. All the images of the required pieces are taken in the same folder where the coding files are maintained and the reference to them are made using the file path in the design process. All these pieces are placed on the squares of the chess board based on the characters assigned to the squares using the character array as discussed in the board representation section of this document. A separate method is used to represent the pieces on the board and is named as drawFigure and the parameters given to this method are like character for the square assigned, x-axis position and y-axis position. Board design takes care of the square positions and the corresponding square positions are designed with respect to the pieces and their respective placement on the squares. Properties for the pieces are assigned at the chess engine level and the corresponding hash codes are assigned as the constant values with respect to these pieces at the backend of the chess engine design. Few methods are defined these pieces in the form of a separate interface and these methods holds the required properties for the corresponding pieces used across the board. Moment of these pieces is defined with respect to the changing positions of the board and the required attributes are set accordingly in these methods. 

Analyzer: 

Design of the analyzer include the time controls used across the chess game and a detailed coding aspects to the alpha beta pruning algorithm based on the time limits imposed across the chess game. Five different time intervals are considered in this design like 50, 100, 300, 600 and 1800 and the corresponding limitations with respect to the time are given based on the human moves. As discussed in the previous section, the human player moves are captured by the mouse action listeners and the corresponding moves are compared against the time limits set across this design.  Time frame allocated in this design is incremented using exponential functions and if the time limit is reached the corresponding action to be taken by the computer program are also defined in this analyzer module. A minimum time limit is given to the human player during the initial moves and gradually the game process, more time limits is allocated to the player in the middle of the game, as the player need more time to analyze the moves and make the right move. A multi threading program is designed in this case to handle the time limits assigned to the human players. 

8 Replies to “Chess Game Design Java”

  1. Hii sir…may i want the source code for this game…am willing to do this project for my pg final yr project…so pls send it to me

Leave a Reply

Your email address will not be published. Required fields are marked *