[Haskell-cafe] Infinite grid
Martijn van Steenbergen
martijn at van.steenbergen.nl
Fri Jan 2 11:44:59 EST 2009
Henning Thielemann wrote:
> A dungeon game? :-)
Yes. :-)
Thank you all for your answers! I especially like David's
no-intermediate-structure solution because it allows for defining the
area in terms of neighbours instead of needing an index on the rooms.
Now that I have core functionality in my game I want to try and build
some interesting areas, such as infinite ones: a infinite grid, or an
N-dimensional Hilbert curve. Because rooms are mutable, I am building
them inside a state monad and use ids:
mkRoom :: M RoomId
addExit :: RoomId -> Exit -> M ()
type Exit = (String, RoomId)
I thought my original question would give me some ideas on how to
construct infinite areas, but this monadic interface complicates things
somewhat. If I create all rooms at once, runState never returns, so I
will have to create them lazily, perhaps by changing:
type Exit = M (String, RoomId)
But I think in addition to that I will also needs refs, so that the
monadic computation can check using a ref whether it's created its
target room before.
I will have to experiment and think on this some more.
Martijn.
More information about the Haskell-Cafe
mailing list