Pages, some stolen, some original

Saturday, December 18, 2010

Games, Part II

I tend towards puzzle games, probably for the same reason I ended up being a programmer.

Light Bot

This one was a programming job. Short, simple programs, but programming none the less. It was pretty straight-forward until I got to level ten ("Do you feel your mind getting numb yet?"), and then I came to a halt. At first glance it doesn't look any harder than any of the other problems, but when I tried to program it in a straight forward manner I ran out of space. There is only room for twelve instructions in the main program. However, there are two functions you can use, each of which has room for eight instructions.

Well, if there isn't enough room in the main program, perhaps we can just chain all three segments together. I did this by making the last step in the main program a call to the first function and the last step in the first function a call to the second function. This gave me 26 (11+7+8) steps, but it still wasn't enough.

Okay then. Can I find a sequence of steps that I can use in more than one place? I could, but they weren't long enough, or used often enough to help. So I stewed. And scribbled. And went away, and came back, and went away again. And then I finally came up with a solution.

The trick is that (in some cases) if the robot tries to execute an instruction, but for some reason can't, nothing happens. If you run into a step, you need a jump instruction to get up on the step. But if you have a walk instruction, the block is in your way, the robot can't walk, and he just stays there and goes on to the next instruction. However, a jump instruction will take you off of a block, even if it's seven stories tall, so you have to be careful.

Another trick is that the robot won't go off of the playing field. You can have him walk to the edge of the field and keep walking, but he will just stay in the same spot.

The solution I came up with is a function that consisted of three steps alternating with three jumps and with a turn at the end. I called this function like six times. It is a horrible example of how to write a program, as half of the instructions were wasted. On the other hand, you can't argue with success and it did succeed.

I was going to just put a link to the picture of my solution, but I can't get either Picasa or Google Docs to cooperate, so I've embedded it here. Hope it doesn't spoil anybody's fun.


No comments:

Post a Comment