All Projects → darrensiegel → Elm Chess

darrensiegel / Elm Chess

Human vs computer chess game entirely in Elm

Programming Languages

elm
856 projects

elm-chess

A human versus computer chess game, entirely in Elm. Nothing fancy: play it live here.

Background

I was inspired to write a chess engine after watching a lecture on the minimax algorithm and alpha beta pruning from MIT's AI course. I have been itching to try out Elm in a non-trivial project, so I eschewed my usual React/Redux stack and dove into Elm.

Details

My original plan was to implement the chess engine as a webservice, which then a client application (written in Elm) would send requests to in order to receive the computer generated moves. I figured this would be a good way for me to finally gain some experience with Elm. After digging in and building the beginnings of the client, I was enjoying the development enough that I continued and implemented everything in Elm, client-side, eschewing my original plan.

Module Engine

Module Engine contains an implementation of minimax with alpha-beta pruning. The engine, as it is checked in right now, only explores two levels (the computer move and a subsequent human move). On my MacBook Pro it takes only a second or two to generate a move. Increasing the depth of search to three levels is still fairly playable, though moves take closer to twenty or thirty seconds to calculate. At this point the browser will sometimes show a long running script warning.

Module Eval

Board evaulation was perhaps the most fun aspect of the game to implement. Piece count, control of center, pawn structure, as well as threatened pieces all factor in to the strength of board evaluation. There are still some ideas that I'd like to explore such as piece weightings that change according to the game phase. As it stands right now, the evaluation function yields a computer player that is quite aggressive.

Module FEN

Module for parsing Forsyth-Edwards Notation. My original intent was to use FEN as the format for requests to the server. After going completely client-side, I found FEN still useful for specifying initial starting boards for debugging and testing.

Running from source

Build the JS:

$ elm-make source/Game.elm --output=elm.js

And run it

$ elm-reactor

Feedback

Besides being entirely new to Elm, I am still fairly new to functional programming. If you have any feedback or suggestions I'd love to hear them.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].