When I was young, I read a newspaper article about a teenager who built a chess program in Visual Basic (!), but I didn't have the skills to do it back then.
I decided to write a chess program in Haskell to fulfil a childhood goal, as well as to:
- Write a non-trivial program in a functional programming language. I learnt ML in university but it was (to quote a lecturer) "good only for counting change (page 52)". I chose Haskell because "what are monads"?
- Write a web application in Haskell, using Yesod. I was too comfortable with the Spring Framework and wanted to try something different. It turned out to be very different, and this program admittedly doesn't do persistence and Yesod just serves as a simple user interface for the chess engine.
- Implement the minimax algorithm and alpha-beta pruning. While I had an idea of how they worked, one doesn't really know how an algorithm works until one works through it, or implement it, or even better, implement it in a functional programming language.
The program is laughably slow and weak at chess. A list of to-dos:
- Improve the web user interface (and stop play after checkmate).
- Improve performance.
- Improve the web user interface to make it look nicer in Chrome (currently tested only in Firefox).
- Make the command line interface work (this was before Yesod came along).
- Implement persistence to host multiple sessions/games.
ormolu -i $(find . -name '*.hs')
hlint src
stack build
stack test
stack run chesskell # command line UI
stack run chesskell-web # web UI at localhost:3000