[Haskell-cafe] How to represent a board?

Rafael Almeida almeidaraf at gmail.com
Fri Jun 20 15:24:25 UTC 2014


Hello,

There are many examples of games which use boards: chess, checkers, go,
etc. Many people starting out at programming and/or game programming are
very much tempted to code a board game. It looks like such a game would be
easy to build at first sight.

Even more sophisticated games sometimes use a grid system, which looks a
lot like boards as well. In a grid system the movements of a given agent
are bound do discrete positions. Although the user may not see the board
underneath pretty graphics, it is a board game.

Having in mind the sort of operations such games have to make on boards, I
ask: what are the best representations for a board in Haskell?

In many languages a NxN array seems like a good pick. In Haskell, most
would translate that into lists of lists. I know I have. However,
traversing those lists to get a position, calculate where a piece or agent
could go, etc., feels awkward and unefficient. Beside the point already
made, we have no type safe guarantee that our 64x64 won't become a 63x63 +
65x1 board due to some misbehaving function.

It strikes me that list of lists is not a great board representation. I
think STArrays are a better pick; from the perspective of translating an
NxN array into Haskell, at least. However, maybe there is an even more
elegant way to deal with a board in Haskell. I hope you can help me out
figuring it out.

[]'s
Rafael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140620/839b7868/attachment.html>


More information about the Haskell-Cafe mailing list