colinrmitchell.com

Chess

Overview

One of my interests has been developing a chess game with a decent AI. I decided to try to build a chess game as my first project in learning the programming language Haskell.

I have gone through three iterations of a chess engine so far. The first chess engine contained a hodge-podge combination of different move considerations, and it chose the final move based on a preference of available moves. This engine doesn't look into the future at all, it simply looks at the moves available, and what pieces it can take and what pieces can be taken. Pretty easy to beat. The code for it can be found here.

The second engine is more sophisticated and provided a much better opponent. It uses a branching tree to look at and weigh games leading off of each move available to the computer. I kept up some documentation about it, describing how it worked and how I got it to work on a cluster of obselete desktops running FreeBSD. The documentation is available here.

The third, and current, iteration of the chess engine builds on the successful elements of the second chess engine, but increases performance, allowing the engine to search further than the last and present more of a challenge. The biggest improvements are constructive discovery of the valid moves for pieces, which seems to have increased performance by around eight times, and an implemenation of the alpha-beta pruning algorithm, which allows many branches in the game tree to be ignored, saving considerable computation time. The code for it can be found here.


Features

The game contains a variety of interesting features that were fun to implement and add to the accessibility of the game for beginners:

Drag and drop
The game is played by using HTML 5 drag and drop. Click and hold on a piece, move it to another square, and let go of the mouse button. This registers your move.
Valid move highlighting
Hovering the mouse over a piece highlights in yellow the valid squares that that piece can move to.
AI move data
Some basic data for each move the AI had available to it is displayed. The algebraic notation of each move is hoverable, showing the move on the board. The computed evaluation of the move is shown, as well as the number of boards evaluated and the number of branches skipped by the alpha-beta algorithm.
Play for me
You can have the computer choose what it believes is the best move for you. This also allows you to watch the computer play itself.
Analyze my play
You can use the AI to evaluate the move that you picked and suggest other moves that it believes are better.

Current Engine

Play now!