It’s Amazing What Some People Do For Fun

So look, if you’ve read this blog before you might be forgiven for thinking that the following statement is somewhat redundant, but here we go: I think about videogames a lot.

What I’ve been getting more and more into recently is thinking about how they are constructed, and this has lead to a gradual realization that my skills as a programmer are way inferior to where I think they would need to be to produce a game on my own. My brain doesn’t really occupy the same headspace as those who write serious code for a living.

… but that does make thought experiments on basic aspects of game construction very informative and revealing to me. So, let me tell you about this dream I had!

It would be an understatement to say that while in The Netherlands for beam time experiments I don’t sleep well. What with shifts going up to 20 hours, and the mental states that come with a high pressure environment, I don’t sleep a lot and when I do I have some very odd dreams. Most of them are just mumbo jumbo, but this week I dreamed I was dumped into a labyrinth and gradually turned into the Minotaur while trying to survive. I woke up and realized that it was an awesome idea for a game.

So, after hashing out in my head what the general mechanics would be, my mind turned to how one might put it together, and ran into an instant road block; I need a labyrinth. I have no idea how to make one of those in code. So, this evening, I found the Wikipedia page for Spanning Trees and thought I’d have a shot at building an algorithm.

A snippet of the code I wrote for this little project; it's the real meat of the program. Remember kids, always comment your code!

A snippet of the code I wrote for this little project; it’s the real meat of the program. Remember kids, always comment your code!

It was surprisingly easy, once I got my head around what I actually *wanted*, the code to make it happen is pretty straightforward, but I know that the obvious way isn’t usually the efficient way of doing it.

So thanks to pugnodeum on Twitter, I read this little set of lecture slides showing how an efficient algorithm will generate the same thing. It uses the idea of the “unity” of sets of numbers to do a much more comprehensive search than my algorithm in a much smaller set of commands, and it makes a lot of sense to implement an algorithm that way.

"Pseudocode is just a euphemism for code which won't compile" - Press, Teukolsky, Vetterling, and Flannery, from Numerical Recipes

“Pseudocode is just a euphemism for code which won’t compile” – Press, Teukolsky, Vetterling, and Flannery, from one of the single best books on computing I’ve ever read.

What did I learn by doing something badly? Well, I gained an appreciation for the way that thinking of things using slightly more abstract ideas can ultimately make your goal a lot easier to program, but I also learned a bit more about the available space of functions to use (the lecture notes I linked use find() and unity() which aren’t things which I was really aware existed until now). That awareness really helps to make me a better programmer in the long run! =]

It’s amazing what some people do for fun, right?


About stoove

A physicist, researcher, and gamesman. Likes to think about the mathematics and mechanics behind all sorts of different things, and writing up the thoughts for you to read. A competent programmer, enjoys public speaking and mechanical keyboards. Has opinions which might even change from time to time.
This entry was posted in General Science. Bookmark the permalink.

One Response to It’s Amazing What Some People Do For Fun

  1. Akoras says:

    I really enjoyed that article stoove 🙂
    Honestly I am not familiar with those functions myself and I doubt that I could have built it the way you did at first, so kudos 🙂
    Of course I only had one semester of programming (currently studying physics) but that suffices to get most ideas of codes when i read through it^^
    Anyway, keep up what you are doing you are great 🙂
    greetings from austria 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s