Dienstag, 28. Juni 2011

An Ook! interpreter in Python

A recent geocache introduced me to an esoteric language named "Ook!", which was designed for Orang-Utans to communicate without arousing human suspicion.

It's pretty simple, as the language consists of only three syntax elements:
  1. Ook.
  2. Ook!
  3. Ook?
That's it. To make the language a little more powerful, elements are grouped into pairs, e.g. "Ook. Ook!" or "Ook? Ook.". So we have nine possible pairs and thus nine distinct commands, only eight of which are actually used ("Ook? Ook?" has been supplied with no deeper meaning ... maybe it's left for the Orang-Utan to express "WTF are you talking about?!").

When I felt an itch to implement an Ook! interpreter, I discovered that Ook! is all but identical to the well-known Brainfuck, since both languages have eight commands, and there exists a one-to-one mapping between them.

Furthermore, since Brainfuck is already a "minimal" language in that any command consists of one character only, I started off with the BF interpreter.

(Ok, to be totally honest, I started off implementing the Ook! interpreter, which eventually had bugs I wasn't able to track down anymore ... :) only then I realized what a stupid plan it was to begin with the Ook! part and started all over again, this time implementing the BF part first)

After finishing that, the remaining task was to implement a preprocessor which would turn an Ook! listing into a BF listing, and I was done.

If you're curious about the result, grab the code from github.

(It's my first project on github btw, and I absolutely recommend the github for mac application)

Montag, 9. Mai 2011

The marriage of Inform7 and geocaching

Recently I stumbled across a terrific idea ... it all began in 1981. Really, it did. Because that was when my wife was born, inevitably determining her turning 30 in 2011.

So, faced with the upcoming event, I considered my options as to what I might give her for her anniversary. Thinking medium-hard for some time I came up with a medium-brilliant thought: I'd place her her very own geocache! She's pretty fanatical about that stuff, so that was a safe bet. I planned to build her a multi-staged cache.

Nothing too clever so far. Caches like this exist in the hundred-thousands.

... BUT ...

Two weeks before the actual event, a co-worker of mine introduced me en passant to something terrific: Inform7.

Inform7 deserves to be called a programming language. In a way, at least, as its declarative style combined with predicate logic reminds me of my Prolog days. On the other hand, its prose-like appearance gives it a fuzzy, yet natural touch. In a nutshell, it allows you to describe an entire world with all its objects, locations, people, as well as all the rules that apply in it, without making you feel too geeky.

And as soon as you're done, Inform compiles your description, and you get ... AN INTERACTIVE TEXT ADVENTURE! (All ye nerds scream "Yaaaaaaaaay" ...).

So, for instance, your source text might be

 
 Living-room is a room. 
 Kitchen is a room. 
 Kitchen is south of living-room.   


and after compiling you're ready to play. Ok, not much adventure to experience yet, but add some pizza to the kitchen and a computer to the living-room, and it's not so far from some people's actual existence. ;-)

So when my colleague told me about that, I suddenly knew what I had to do: A hybrid of an old-school text adventure and a geocache - that was it! Ideas started flooding my mind as soon as the connection of the two concepts was established ... so many, indeed, that it was hard to keep track of all of them. In the same instant it was sort of exhausting to think of all the stuff I wouldn't be able to implement since first of all I wasn't in the least "fluent" in Inform7, and then there was the time issue: Two weeks only - how many ideas would have to remain unborn? :-)

The game map, as generated by Inform based on the relative positions of the rooms.


In the end I managed to build a small world consisting of 29 rooms, about half of which correspond to "real" places that the players needs to visit in order to collect clues there. Check out this snippet from the game, played entirely inside the browser:



Some of the clues were material, some purely virtual. It was a satisfying result after all. There are monsters in it (trolls, dragons ... standard RPG company), hidden places, keys and locks, hilarious jokes, of course, magic barriers and the like. Adventure veterans would certainly criticize its being a little too simple. Beginners will possibly claim the opposite. Who knows ... judge for yourself, but don't get frustrated! You cannot get past the dragons, as you need a "real" clue for that, so there's no chance you'll finish the game successfully. You'll have to enter the nonvirtual realm for that. :-)

The cache was a nice surprise for my unsuspecting wife, and - as of 9th of May - it is published and available under the name "Wandrin' Duck". I'm excited what kind of feedback I'll get from the geocachers' guild.

Still there's a lament in the back of my mind of all those ideas I left out ... maybe some other day.

Mittwoch, 20. April 2011

__init__

So I have my own blog now. Looking forward to writing again ...

Most of it will definitely be related to programming. My language of choice right now is Python, which I've been cherishing ever since I got my first job, where I applied as a Java programmer but ended up hacking Python instead. In retrospect, I'm pretty happy about how things turned out. Only recently I decided to get back to Java for a while, to have a "major" language under my belt, and boy it felt cumbersome after those pythonic years. But that's gonna be acceptable.

Still, I think it's time to try something new, and so I've been considering alternatives to my beloved reptilian language. In particular, I've grown interested in functional programming and iOS programming.

Hopefully I'll be able to speak about my favourite instrument, the guitar. I'm not sure yet what a blog post about an instrument might look like. Anyway, as I've been playing around with Garage Band lately, and I also have a piano available, there might be some experience or other that the other nerd/musician hybrids out there might appreciate hearing about.