Thursday, October 20, 2011

[Inform 7] Complex interaction, events, and rulebooks

Suppose that your game involves people that can be sleeping or awake; and a huge gong, that, when struck, wakes up everyone in the room and all adjacent rooms. This is the most natural way to implement something like that in Inform 7:
Carry out hitting the huge gong:
   say "You hit the huge gong!";
   repeat with guy running through near people:
      now guy is awake.
Where I am, of course, assuming that you have already created a definition for "near", and so on.

This is fine if your game is simple enough that (a) waking people is the only effect of hitting the huge gong, and (b) hitting the huge gong is the only cause of waking all near people. But if you are aiming for a complex world model, this will often not be the case; and even more often, you will not be certain whether it is going to be the case.

Why is this a problem? Because you do not want your code to look like this:
Carry out hitting the huge gong:
   say "You hit the huge gong!";
   repeat with guy running through near people:
      now guy is awake;
   other stuff that happens;
   more stuff that happens.

Carry out pushing the alarm button:
   say "the alarm sounds!";
   repeat with guy running through near people:
      now guy is awake;
   other stuff that happens;
   more stuff that happens.

Every turn when having-a-screaming-fit is true:
   say "You continue screaming.";
   repeat with guy running through near people:
      now guy is awake;
   other stuff that happens;
   more stuff that happens.
Evil code duplication! Maintenance nightmare!

This is obviously better:
Carry out hitting the huge gong:
   say "You hit the huge gong!";
   have a loud noise event.

Carry out pushing the alarm button:
   say "the alarm sounds!";
   have a loud noise event.

Every turn when having-a-screaming-fit is true:
   say "You continue screaming.";
   have a loud noise event.

To have a loud noise event:
   repeat with guy running through near people:
      now guy is awake;
   other stuff that happens;
   more stuff that happens.
But that is still not ideal, because all code that relates to loud noises must be in the same place. If I code up a delicately balanced Cavendish experiment that will be unbalanced by loud noise (and believe me, it will), I want to have the code about the unbalancing right there with all the other code having to do with the Cavendish experiment. I want to be able to see what the experiment does and how it can be influenced at a single glance, not by looking through the entire code.

I would like to suggest that the natural way to think about this is the following. Loud noise is a kind of event. If object A can generate that that kind of event, this should be defined in the section of the code pertaining to object A. If object B is influenced by that kind of event, this should be defined in the section of code pertaining to object B. This gives us the cleanest, most readable code, that is easiest to maintain and extend.

How do we do that in Inform 7? By using rulebooks, of course:
The loud noise rules are a rulebook.

Carry out hitting the huge gong:
   say "You hit the huge gong!";
   consider the loud noise rules.

Carry out pushing the alarm button:
   say "the alarm sounds!";
   consider the loud noise rules.

Every turn when having-a-screaming-fit is true:
   say "You continue screaming.";
   consider the loud noise rules.

A loud noise rule (this is the noise wakes people rule):
   repeat with guy running through near people:
      now guy is awake.

A loud noise rule (this is the noise does other stuff rule):
   other stuff that happens.

A loud noise rule (this is the noise upsets the Cavendish experiment rule):
   upset the Cavendish experiment.
And all these snippets of code can be placed wherever they most naturally belong -- in the parts of the code pertaining to gongs, alarm buttons, screaming fits, sleeping, and the Cavendish experiment respectively.

But of course this means that, knowing that you are building a game with a complex world model, you should have coded that very first gong like this:
The loud noise rules are a rulebook.

Carry out hitting the huge gong:
   say "You hit the huge gong!";
   consider the loud noise rules.

A loud noise rule (this is the noise wakes people rule):
   repeat with guy running through near people:
      now guy is awake.
Which may seem exceedingly wordy at the time, but will pay off in the long run.

Today's lessons, then: learn to love rulebooks even more than you already do! Resist the temptation to implement special cases!

Saturday, October 01, 2011

[Results] The Interactive Fiction Top 50

The results of the Interactive Fiction Top 50 are in! No fewer than 35 participants cast a total of 437 votes on 183 different games. Of those games, 48 got three votes or more, and those are the games that will appear in the Top 50 below -- so it is actually a top 48. Games which have the same number of votes appear in the same spot, and will be listed in alphabetical order (ignoring "the", "a" and "an").


Does this mean we finally have proof that game X is better than game Y? Of course not. But I hope you will be inspired to try some of these games. Or perhaps you will be inspired to tell us about that game you think really deserves a spot in this list but hasn't received enough attention. Most of all, I would like you to click on the link above and read the reasons that people gave for choosing one game or another. After all, a reason close to your heart may be more important than a large number of votes.


Fuller results, including a list of games which got two or one votes, will follow; but now, without further ado, the top 48!


First place -- 17 votes

  • Spider and Web, Andrew Plotkin (1998)

Second place -- 14 votes

  • Lost Pig, Admiral Jota (2007)
  • Photopia, Adam Cadre (1998)

Fourth place -- 11 votes

  • Anchorhead, Michael Gentry (1998)

Fifth place -- 10 votes

  • A Mind Forever Voyaging, Steve Meretzky (1985)

Sixth place -- 8 votes

  • The Baron, Victor Gijsbers (2006)
  • Blue Lacuna, Aaron A. Reed (2008)

Eighth place -- 7 votes

  • Savoir-Faire, Emily Short (2002)
  • Shrapnel, Adam Cadre (2000)

Tenth place -- 6 votes

  • Shade, Andrew Plotkin (2000)
  • Slouching towards Bedlam, Star Foster and Daniel Ravipinto (2003)
  • Trinity, Brian Moriarty (1986)
  • Varicella, Adam Cadre (1999)
  • Vespers, Jason Devlin (2005)
  • Violet, Jeremy Freese (2008)

Sixteenth place -- 5 votes

  • Galatea, Emily Short (2000)
  • The Gostak, Carl Muckenhoupt (2001)
  • The King of Shreds and Patches, Jimmy Maher (2009)
  • LASH -- Local Asynchronous Satellite Hookup, Paul O'Brian (2000)
  • Make it Good, Jon Ingold (2009)
  • Rameses, Stephen Bond (2000)

Twenty-second place -- 4 votes

  • Ad Verbum, Nick Montfort (2000)
  • Aisle, Sam Barlow (1999)
  • All things devours, half sick of shadows (2004)
  • City of Secrets, Emily Short (2003)
  • Curses!, Graham Nelson (1994)
  • Fail-safe, Jon Ingold (2000)
  • Gun Mute, C. E. J. Pacian (2008)
  • Sunset over Savannah, Ivan Cockrum (1997)
  • Treasures of a Slaver's Kingdom, S. John Ross (2007)
  • Wishbringer, Brian Moriarty (1985)
  • Worlds Apart, Suzanne Britton (1999)
  • Zork I, Marc Blank and Dave Lebling (1980)

Thirty-fourth place -- 3 votes

  • 1893: A World's Fair Mystery, Peter Nepstad (2002)
  • Adventure, William Crowther and Donald Woods (1976)
  • Aotearoa, Matt Wigdahl (2010)
  • Arthur: the Quest for Excalibur, Bob Bates (1989)
  • Blue Chairs, Chris Klimas (2004)
  • Delightful Wallpaper, Andrew Plotkin (2006)
  • Eric the Unready, Bob Bates (1993)
  • Everybody Dies, Jim Munroe (2008)
  • The Guild of Thieves, Rob Steggles (1987)
  • Hoist Sail for the Heliopause and Home, Andrew Plotkin (2010)
  • Mentula Macanus: Apocolocyntosis, Adam Thornton (2011)
  • Planetfall, Steve Meretzky (1983)
  • So Far, Andrew Plotkin (1996)
  • Suveh Nux, David Fisher (2007)
  • The Warbler's Nest, Jason McIntosh (2010)

Discussion preferably on the forum.

IF Comp, doctorate

In a couple of hours, the IF Comp 2011 will start. Or at least, the deadline for uploading games will have passed; it might take a little longer before they actually become available. Since I will be participating, I won't be publishing reviews during the competition. In fact, I won't be saying anything at all about the competition, because I don't want to be disqualified.

So let me take this final opportunity and wish the best of luck to my fellow authors, the greatest of wisdom to the judges, and the finest of times to us all.

Also, although this is not a blog about my personal life, I cannot resist the temptation of sharing with you the elation I still feel about getting my doctorate two days ago. Impression of me with my two 'paranimfen': photo. Imagine a committee of 11 people to the left, and an auditorium full of friends, family and colleages behind the photographer. In the Netherlands -- this differs widely between countries -- the actual defence is a big ceremony. At that stage you can no longer fail, but it is still a very exciting day. And you do have to answer difficult questions about your thesis for 45 minutes while all your loved ones are watching (and wondering what you are talking about).

In case you are interested in a PhD thesis on philosophical theories of explanation, you can find it here.