[Haskell-cafe] How to represent a board?
edwards.benj at gmail.com
Fri Jun 20 16:16:01 UTC 2014
There is also the grid package on hackage that has support for a number of different grid shapes.
On Fri, Jun 20, 2014 at 5:12 PM, Daniel Trstenjak
<daniel.trstenjak at gmail.com> wrote:
> Hi Rafael,
>> 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?
> What works pretty nicely is using a one dimensional Data.Vector to represent
> your board, a tuple (x, y) to represent a position on the board and then using
> a lens to transform the tuple (x, y) into an index of the one dimensional Data.Vector.
> You can then write code like:
> -- get board value at position (1, 2)
> board ^. atCoord (1, 2)
> -- set board value at position (1, 2)
> board & atCoord (1, 2) .~ newValue
> Having a one dimensional vector has the advantage, that's a lot nicer to e.g. map or fold over it.
> In the toy example hsbot I used this kind of representation.
>  https://hackage.haskell.org/package/vector
>  https://hackage.haskell.org/package/lens
>  https://github.com/dan-t/hsbot
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe