Skip to content

Engine Breakdown

Sam Chen Yu edited this page Feb 10, 2024 · 4 revisions

This document is designed to breakdown the engine class.

Move Objects

public Move(int startX, int startY, int endX, int endY, String moveType, String capturedPiece, int enPassantX, int enPassantY, String promotePieceTo)

Move objects are created to generate every legal move in the position. It stores all the information required to make a move, and then later to revert that move to return to the original position. Therefore, it has to store data

Types Of Moves:

  • Move - Any piece that moves
  • Moved_Twice - For pawns moving twice on their first move to update the en passant square
  • Capture - Any piece capturing another piece
  • En_Passant_Capture - Capturing a pawn that moved twice on their on their en passant square
  • Promote - A pawn that promotes via moving
  • Promote_Capture - A pawn that promotes via capturing an enemy piece
  • Castle_KingSide - Either king castling king side
  • Castle_QueenSide - Either king castling queen side

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

Clone this wiki locally