Monday, April 27, 2009

Haskell RPG Game uploaded on Hackage!

I've worked on it on and off for months, I've rewritten parts of it entirely, it gave me the opportunity to knock together a real, complete application in Haskell, and it's finally done! I've uploaded my console based RPG game (read: nethack clone) to Hackage (get it here). You create a character and walk through mazes, trading, stealing, casting spells and fighting monsters.
You can look at the source code (no documentation, sorry) and see what I've used. I've used a monad to abstract away the state and the random generator (so I can plug a non random generator for testing, one that for example will guarantee that the next throw of the D20 die will give 8). I have developped my own little framework for console handling (executing actions from what the user typed in and displaying results) maybe I should look at the existing libraries and try to plug one in instead.
What I found was the most awkward was the record syntax for nested structures, I'll have to investigate to find an easier way to read and update my structures.
There are a few HUnit tests to verify that the most basic functionality works, so hopefully there is no huge bug.
It was fun to play around with Haskell and with game concepts. I hope I'll have time to work on even cooler stuff like adding AI for the monsters (so they can decide when to run away, etc...).
Any feedback on the game mechanism or on the code itself is welcome!

7 comments:

Unknown said...

Regarding the syntax for nested records, you might enjoy Data.Accessor. It can simplify that stuff quite a bit.

Justin said...

You might want to look at the HCL library for handling keyboard input. I played your game and after creating a character, it said:

Accept? (Y/n)

Entering "return" gave me:

mazesofmonad.exe: Prelude.head: empty list

HCL handles failure like that very gracefully.

I love nethack so I hope to check it out further soon!

Jedaï said...

I second the suggestion to look at data-accessor to manipulate your data.

I also noted some problems with your console handling (prompt appearing after the command is typed...), haskeline is a pretty good library, already used for GHCi (ghci-haskeline) to better effect than editline, and probably the library used instead of editline and readline in future GHC releases.

Good luck with future extensions too ! :)

Unknown said...

So you wrote a Role Playing Game game? :p

Michael Steele said...

Do you plan on putting this under revision control? I'd be interested in watching your progress.

JP Moresmau said...

Thanks everybody for the feedback. I've uploaded 1.0.1 to Hackage that fixes the Y/n issue (but anyway if you type Y it worked before) and changed the intro text :-p. I guess I have to review [HCL,Haskeline,Shellac] and others to see if using a framework would make my code easier. About source control, I don't have any plans to put that project in a public repository, but why not? Anyway I'll try to upload new versions when I have new features...

JP Moresmau said...

For those interested in seeing the code evolve (hopefully), there is now a darcs repository at http://code.haskell.org/MazesOfMonad/. Enjoy!