[Haskell-cafe] How can I represent 4x4 map in haskell
rendel at rbg.informatik.tu-darmstadt.de
Mon Mar 31 11:22:33 EDT 2008
> type Line = [Char]
> type Board = [Line]
> so my question is if this is ok to represent a map. If yes I will try to
> write the function which makes it 4 x 4 myself. What I jsut need as an
> answer is Yes or No. Just to let you know is that I am trying to build the
> Wumpus World
A list of lists of cells is a possible representation for a two-dimensional
array, yes. for bigger maps, there may be a performance problem,
but for such a small world, it should be fine.
You may consider using an array, e.g. with
type Board = Array (Int, Int) Char
Boards will be indexed by coordinate tuples.
Another point: maybe you should use an algebraic data type instead of
Char to represent the individual cells? e.g.
data Cell = Wumpus | Trap | Gold | Nothing
type Board = [[Cell]]
Be aware of the Wumpus!
More information about the Haskell-Cafe