Engine Breakdown - SamChenYu/JavaChessEngine GitHub Wiki

This document is designed to breakdown the engine class.

ChessUML

Lightblue: chessengine package
Green: GUI package
Purple: Move package
Orange: Game package

Method Breakdown:

evaluate()

Evaluates the game state and who is winning. Returns a double between -1 and 1. Where -1 is checkmate for black and 1 is checkmate for white. 0 is even or stalemate. It takes into account position from piece square tables and material. These two factors are weighted dynamically based on the material difference.

updateMoves()

Loop through each square on the board, and depending on it's piece type, calculates every single move that it can play legally through the chcekIfMoveIsValid() method.

checkIfMoveIsValid()

Performs a move on the board. If the active player is still in check, then the move is invalid, and returns false. If the active player is not in check, it will return true.

isInCheck()

Inputs a board state, and returns whether or not the player is in check.

isSquareInCheck()

Inputs a board state and x y coordinates and returns whether that particular square is attacked or not.

MakeMove()

Given a board state and a Move object, it will execute the move onto the game state It also saves vital data such that the move can be perfectly reverted.

RevertMove()

Given a board and already executed Move object, it will revert the move back to the original state. This method is vital for the minimax algorithm.

isGameOver()

Returns true if the current board state is checkmate or stalemate

findBestMove()

Implementation of the minimax algorithm.

Structure of Engine:

updateMoves() -> Every single move is generated. To check if it is legal, the board is execute checkIfMoveIsValid() by makeMove() and then isInCheck(). If it is in check, then it is an invalid move. revertMove() is called to revert back to original state.

findBestMove()

For every legal move generated, execute the move, and then updateMoves() until the desired depth is required. Evaluate the moves, and given the highest evaluation for the maximising player