Author Topic: developing a roguelike with a functional language  (Read 12513 times)

hawk66

  • Newcomer
  • Posts: 23
  • Karma: +0/-0
    • View Profile
developing a roguelike with a functional language
« on: April 25, 2011, 06:03:27 PM »
I'm currently learning F# and I have the feeling that this (and other hybrid functional languages) language would help a lot in developing the game engine of a roguelike - since you can express algorithms in a  much more powerful way and with less number of coding lines.

Has anybody already started developing a roguelike with F#/Scala etc. and can share his experience?

I plan to do the UI in C# (using libtcod) and the engine itself with F#.

purestrain

  • Rogueliker
  • ***
  • Posts: 172
  • Karma: +0/-0
    • View Profile
Re: developing a roguelike with a functional language
« Reply #1 on: April 26, 2011, 05:46:48 AM »
I did it (Scala) and remember some other roguelikes. Stopped it because IDE-Support was limited and the scala library on android is quite big.

Ari Rahikkala

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 64
  • Karma: +0/-0
    • View Profile
    • Email
Re: developing a roguelike with a functional language
« Reply #2 on: April 26, 2011, 06:11:28 AM »
I haven't done much roguelike development, but there's a couple of things I might be able to say based on my extremely limited Haskell experience:

Immutable data is your friend. At least, in Haskell it is (though, well, in Haskell you don't really have a choice). If your entire gameworld is built out of immutable data, it becomes easy to do things like save the game in a background thread, roll the game state back (for instance, you could store a reference to the game state at the beginning of a turn and, if something goes wrong that turn, pop up a warning, make the stored state the current one, and make a debugging save), allow simulating the gameworld forward, etc.. A Sands of Time-ish rewind mechanic is the easiest thing ever to implement if your gameworld is made of immutable data. And even if you didn't care for or intend to implement any of those features, it's still a great idea for architecture since it forces you to use proper functional design instead of leaving state lying around all over the place.

However, just as well in my limited experience, there's only so far you can go doing "proper functional design" in a roguelike engine. If it seems the code of many roguelike games is messy, the reason mightn't be so much that the programmers are bad than that roguelike games themselves are big weird messes of rules and exceptions and adjustments that look at and modify the game state in really arbitrary ways. So prepare to write a fair amount of code, and don't expect to be able to develop much of the engine's internals as modules with clean, coherent and uncoupled interfaces. You'll have to be made of sterner stuff than most designers to find those inside a roguelike.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: developing a roguelike with a functional language
« Reply #3 on: April 26, 2011, 06:55:37 AM »
since you can express algorithms in a  much more powerful way and with less number of coding lines.

It's a common misconception to think that "more powerful" languages would make it that much easier.

hawk66

  • Newcomer
  • Posts: 23
  • Karma: +0/-0
    • View Profile
Re: developing a roguelike with a functional language
« Reply #4 on: April 26, 2011, 11:03:30 AM »
since you can express algorithms in a  much more powerful way and with less number of coding lines.

It's a common misconception to think that "more powerful" languages would make it that much easier.

I do not think that it is 'much' easier but to give an example, I started to implement a simple urban city generator for my roguelike in C#...and I'd think the algorithm can be better expressed (->also easier coding maintenance later) in F#...but let's see

I also do not want to abandon C# completely (I think for the UI it is a better match) but that's the beauty of .NET: you can choose now from a big, mature toolset.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: developing a roguelike with a functional language
« Reply #5 on: April 29, 2011, 09:56:56 AM »
but that's the beauty of .NET: you can choose now from a big, mature toolset.

Great. Now, where were the .NET roguelikes again...

TSMI

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
    • View Profile
    • Email
Re: developing a roguelike with a functional language
« Reply #6 on: May 06, 2011, 07:37:33 AM »
but that's the beauty of .NET: you can choose now from a big, mature toolset.

Great. Now, where were the .NET roguelikes again...

*NIX users seem to be a much more represented among roguelikers, so comparatively few people would program using .NET languages. I really don't see anything about F# or C# that would make them unsuitable for writing a roguelike.

OP: given what I said above, you should make sure your code at least runs on mono, or you're likely to be slashing your potential audience by quite a bit. Also I'd love to do RL stuff in a functional language, but I can't find one I'd want to use (usually because they have a poor bridge to the C world).

kipar

  • Rogueliker
  • ***
  • Posts: 105
  • Karma: +0/-0
    • View Profile
    • Email
Re: developing a roguelike with a functional language
« Reply #7 on: May 20, 2011, 06:47:58 AM »
Caves of Qud and Rogue Survivor - two great roguelikes written in .NET (but not on the functional language, I think).