[Haskell-cafe] How to represent a board?

Corentin Dupont corentin.dupont at gmail.com
Fri Jun 20 15:38:32 UTC 2014


Instead of encoding the board, I would encode the position of the pieces:
there is usually much less pieces than squares.


On Fri, Jun 20, 2014 at 5:33 PM, Bob Ippolito <bob at redivi.com> wrote:

> I've used Data.Array or Data.Vector when trying to solve these sorts of
> problems. The size of the board is not encoded in the type with either
> library, but that's not something that's easy to do or commonly implemented
> in Haskell.
>
> Data.Vector has better functionality, but the index is always an Int, so
> Array can be more convenient in many cases as it can be indexed by any
> instance of Ix.
>
> STArray, MVector, etc. are all options as well, but I prefer to write
> functional solutions when possible.
>
>
> On Fri, Jun 20, 2014 at 8:24 AM, Rafael Almeida <almeidaraf at gmail.com>
> wrote:
>
>> 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
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>
>>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140620/203ff109/attachment.html>


More information about the Haskell-Cafe mailing list