Rory Nicholas

University College London - Computer Science BSc


Knifefish Chess Engine

This project contains two chess engines. I originally wrote it in Python for a school project, before re-writing it years later in Java in order to improve its speed as well as improve the code quality and introduce new concepts for a higher playing skill. It includes a chess-playing application with an AI opponent of variable difficulty.

The engine uses a Minimax backtracking algorithm alongside Alphabeta pruning. In this way, the AI will exhaustively search through all positions up to a certain number of moves away (or a terminal game state).

This is then improved with Quiescience search, which will conditionally search the game tree more deeply based on how volatile a position appears to be. This avoids the 'horizon effect', where a position is inaccurately judged by a search with fixed depth because a game changing move was 'just over the horizon' and out of sight.

Additionally, note that an exhaustive search will search the same game state several times; often the same moves may be made in a different sequence, and so there are multiple ways to reach a particular position. To that end, transposition tables allow previous evaluations of positions to be used to prevent redundant calculations. This is implemented with a hash table, where Zobrist hashing allows extremely fast calculations of the table keys.

Finally, the static evaluations of a given position are calculated by using a piece-square table to adapt the estimated score of a given piece according to its position on the board. The values of these tables were populated by using a genetic algorithm to find the optimal scores.

The results of this project were a decent chess engine alongside a much-improved one. The newer engine showcases both a much higher code quality and overall project organisation, and an AI which beats a much higher percentile of the population.

The repositories for these engines are available in Python and Java.