[Haskell-cafe] How to represent a board?

Benjamin Edwards 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.

Ben

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[1] to represent
> your board, a tuple (x, y) to represent a position on the board and then using
> a lens[2] 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[3] I used this kind of representation.
> Greetings,
> Daniel
> [1] https://hackage.haskell.org/package/vector
> [2] https://hackage.haskell.org/package/lens
> [3] https://github.com/dan-t/hsbot
> _______________________________________________
> 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/849e9a46/attachment-0001.html>


More information about the Haskell-Cafe mailing list