[Haskell-beginners] Simple Chess Program for Learning FP
Yitzchak Gale
gale at sefer.org
Tue Jun 1 15:37:26 EDT 2010
Daniel Fischer wrote:
> If performance isn't important, you can also use a two-dimensional array
> (Data.Array; Array (Int,Int) (Maybe Piece) for example) in Haskell.
> Actually, immutable arrays in Haskell are surprisingly snappy (at least if
> you compile with optimisations).
> Another option is using Data.Map and representing the gamestate as a Map
> from positions to pieces.
> There are also mutable arrays,
A chess board is only 8x8, so depending on your algorithms,
a simple 2 dimensional list might be the fastest:
[[Maybe Piece]]
That also allows you to write simple, beautiful functional code, using
the wide selection of list functions available in the Prelude
and Data.List.
If you choose a map from positions to pieces, it might turn out
to be just about as fast to use a simple association list
[(Int, Int), Maybe Piece]
instead of all the machinery of Data.Map.Map (Int, Int) (Maybe Piece)
A chess board has only 64 locations.
Regards,
Yitz
Regards,
Yitz
More information about the Beginners
mailing list