Code Monkey home page Code Monkey logo

chess-engine's Introduction

Chess

A few minor extensions to a learning exercise on the haskellwiki. There is only a minor change to the original implementation to make it compile with GHC. And some additional modules have been added.

The engine does not support double square pawn advances or castling and no support has yet been added.

Some things have been added, amateurishly:

  • Print a game state (turn, board and possible moves)
  • Parse a game state (and an optional move command)
  • Command line state parser / transformer
  • ØMQ binding

I'm using this to learn some Haskell and to work as a chess engine for a chess server.

This is not intended to be and efficient implementation and Parsing into FEN or something might be better but this is for fun and learning.

The ØMQ server has a dependency on the ØMQ and the Haskell bindings

To compile:

make             

Sample format:

$ cat sample/invalid_move.txt
White
BR BN BB BQ BK BB BN BR
BP BP BP BP BP BP BP BP
-- -- -- -- -- -- -- --
-- -- -- -- -- -- -- --
-- -- -- -- -- -- -- --
-- -- -- -- -- -- -- --
WP WP WP WP WP WP WP WP
WR WN WB WQ WK WB WN WR

It can generate moves:

cat sample/gen_moves.txt | ./bin/cli
White
BR BN BB BQ BK BB BN BR
BP BP BP BP BP BP BP BP
-- -- -- -- -- -- -- --
-- -- -- -- -- -- -- --
-- -- -- -- -- -- -- --
-- -- -- -- -- -- -- --
WP WP WP WP WP WP WP WP
WR WN WB WQ WK WB WN WR

WP a2:a3 WP b2:b3 WP c2:c3 WP d2:d3 WP e2:e3 WP f2:f3 WP g2:g3 WP h2:h3 WN b1:c3 WN b1:a3 WN g1:h3 WN g1:f3WP a2:a3 WP b2:b3 WP c2:c3 WP d2:d3 WP e2:e3 WP f2:f3 WP g2:g3 WP h2:h3 WN b1:c3 WN b1:a3 WN g1:h3 WN g1:f3

It parses a state and a move action and returns the updated state (the move list can be omitted):

cat sample/make_move.txt
White
BR BN BB BQ BK BB BN BR
BP BP BP BP BP BP BP BP
-- -- -- -- -- -- -- --
-- -- -- -- -- -- -- --
-- -- -- -- -- -- -- --
-- -- -- -- -- -- -- --
WP WP WP WP WP WP WP WP
WR WN WB WQ WK WB WN WR

WP a2:a3 WP b2:b3 WP c2:c3 WP d2:d3 WP e2:e3 WP f2:f3 WP g2:g3 WP h2:h3 WN b1:c3 WN b1:a3 WN g1:h3 WN g1:f3WP a2:a3 WP b2:b3 WP c2:c3 WP d2:d3 WP e2:e3 WP f2:f3 WP g2:g3 WP h2:h3 WN b1:c3 WN b1:a3 WN g1:h3 WN g1:f3

action: WP e2:e3

Returns updated board, the turns and the possible moves.

$ cat sample/make_move.txt | ./bin/cli
Black
BR BN BB BQ BK BB BN BR
BP BP BP BP BP BP BP BP
-- -- -- -- -- -- -- --
-- -- -- -- -- -- -- --
-- -- -- -- -- -- -- --
-- -- -- -- WP -- -- --
WP WP WP WP -- WP WP WP
WR WN WB WQ WK WB WN WR

BN b8:c6 BN b8:a6 BN g8:h6 BN g8:f6 BP a7:a6 BP b7:b6 BP c7:c6 BP d7:d6 BP e7:e6 BP f7:f6 BP g7:g6 BP h7:h6

It only accepts valid moves (moves which are in the list generated):

$ cat sample/invalid_move.txt | ./bin/cli
Invalid Move

Everything else it doesn't understand it returns a parse error, it doesn't test the validity of the game state, it will parse a board full of bishops:

$ echo "BK WZ KK" | ./bin/cli
Parse Error

The server can be started to listen for connections:

$ ./bin/server
Starting Server

Then the test client will send ./sample/make_move.txt, 10 times:

$ ./bin/client
..

chess-engine's People

Contributors

tarnacious avatar

Watchers

 avatar James Cloos 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.