Code Monkey home page Code Monkey logo

elm-chess's Introduction

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.

elm-chess's People

Contributors

darrensiegel avatar jreina avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.