Traivok / chesskell

Haskell Chess Engine - College Assignment

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chesskell

Take turns with your opponent and play by writing in the extended chess notation the moves you want to make. A wrong move makes you lose instantly, so think carefully.

Running the game

to start the game just run:

./chesskell

If you want to run it on GHCi you can do

gchi main.hs

and then inside ghci run

chesskell

To start the main game loop.

Warning

If run the game inside ghci, you'll have a bad time using backspace. We recommend using the compiled version so you can correct your typing of the moves you intend to make.

Compiling

ghci main.hs -o chesskell

Things to note when playing

  • The syntax for a pawn promotion is as follows:
    • for a promotion with capture, you could do: Pg7xh8=N (pawn at g7 captures piece at h8 and gets promoted to a knight)
    • for a promotion without a capture, you could do: Pg7-g8=Q (pawn at g7 advances to g8 and gets promoted to a queen)
  • The rest of the syntax is pretty straightforward, here are a couple examples of valid input strings (the strings are valid, but the validity of moves is verified at runtime, since it depends on the current state of the board.):
    • Ph4-h5 (Pawn at H4 moves to H5)
    • Rh8-h4 (Rook at H8 moves to H4)
    • Ra1xa6 (Rook at A1 captures whatever enemy piece is standing at A6)
    • Qd2xg4 (Queen at D2 captures whatever enemy piece is standing at G4)
  • You can indicate that a move is a check by appending + to the end of the move that will put the opponent's king in check. E.g.: Qh5-g5+ (Queen on h5 moves to g5 and puts the opponent's king in check)
  • You can indicate that a move is a checkmate by appending ++ to the end of the move that will put the opponent's king in checkmate. E.g.: Qc8xd8++ (Queen on c8 captures piece on d8 and puts the opponent's king in checkmate)

Things we are not proud of

  • moves.hs is a complete mess. It works, but we focused too much on getting it working and not on code optimization/legibility. Since the project had a short deadline, we left the moves.hs in that horrendous state.

Things we think that can be done/enhanced

  • Cleanup move.hs
  • We would like to add an AI to play against the player, instead of 2 human players. We intend to use the minmax strategy counting the value of the Pieces and also evaluate for a mate / stalemate.
    • For that we tought about the following data structures, which would represent the value of the piece and how many turns would require to result in a win/draw/loss:
      • Data Evaluation = Value Double | Wins Int | Draw Int | Losses Int
      • Data Heuristic a = Evaluate (a -> Evaluation)
  • We would like to use the parser we learned in class instead of the simple parser we used at main.hs. We implemented the parser but we ended up not using it due to lack of time.

Examples - Chess Openings

Queen's Gambit:

One of the fundamental variations of 1.d4 is the Queen's Gambit. White immediately strikes at Black's central pawn from the side. Although the c4 pawn is not guarded, this is not a 'real' gambit, since White can always get the pawn back if he wants.

  • [W] Pd2-d4
  • [B] Pd7-d5
  • [W] Pc2-c4

Screen Shot 2021-05-04 at 18 43 58

Ruy Lopez

The Ruy Lopez, also known as the Spanish opening, develops the kingside pieces quickly and puts pressure on the center.

  • [W] Pe2-e4
  • [B] Pe7-e5
  • [W] Ng1-f3
  • [B] Nb8-c6
  • [W] Bf1-b5
  • [B] (Most popular, but not a rule) Pa7-a6

Screen Shot 2021-05-04 at 18 49 47

Screen Shot 2021-05-04 at 18 50 02

Example - Full Game

At the root of this project there is a file samplegame.txt. It contains a chess game of 49 moves where the white pieces win. You can type the game line by line to see it developing slowly, or you can just feed the input to the game by doing: ./chesskell < samplegame.txt. The final board it should produce should look like this:

Screen Shot 2021-05-04 at 19 35 19

As we can see there is a checkmate on the black pieces' king on g8.

About

Haskell Chess Engine - College Assignment

License:MIT License


Languages

Language:Haskell 100.0%