I recently implemented Chess in Haskell. I used a standard minmax-Algorithm and a very simple evaluation function for computing moves.
The following problems and oddities occured:
- easiest evaluation function: difference of material on board (without any positional judgement)
- value of the King is infinity, winning threshold a little bit less than infinity :-), because the losing player may have a material advantage, so the threshold should be infinity minus the maximal material value of all pieces but the King
- winning "player" keeps playing instead of just capturing the king, because he can capture in the future as well and tries to maximize benefit by trying to capture other pieces
- king is captured by naive algorithm -> delete last two moves (King tries to run away of the chessmate, but is captured nevertheless...)
- the capturing en passant and castling rules are the worst things from a programmers point of view, because they make moves depending on previous moves, thats why I ignored both rules in my implementation
- a depth of the game tree of 4 is already very, very slow
Have a look at my implementation at hsChess.zip. You may start trying the test functions exampleGame and exampleMateGame.
Tags: chess haskell minmax