William Matheson (nova_one) wrote,
William Matheson
nova_one

Otto the Robot

I had a reasonably productive day yesterday. First, I took the car to a garage and got the heater switch replaced with something that works and that won’t burn one’s fingers. Apparently the wires behind the switch were rotten and arcing. In retrospect I could also have called around to various junkyards in search of a working climate control module, but I suspect that the A/C itself isn’t working, so it would be a deeper money pit to get all that stuff back up to spec.

At school we had our first programming class. In addition to going over the course outline and expectations, we tried out a “game” called Otto the Robot. If you’re running a Windows machine, you can download it and try it, too.

Basically, your job is to program the robot to respond to its environment – for instance, to get through a maze safely. Sometimes you know everything and sometimes you know less, so at the harder stages you can’t just say “step, turn, step, step, turn” like you would if you were giving somebody directions.

I got through the “easy” scenario on my first try, but the “normal” mode really got me for a while. I’d have the robot see if he’s touching something, then if it wasn’t the exit door, he’d turn (always turning right, the only turn he has), test again… if it was clear, he could then take a step.

Sounds good, right? Well, I came back from the hallway (I needed a quiet space to think) expecting that I had the problem licked, but when I ran the program the robot kept going back and forth over just a few squares!

When I got home I finally realized my problem – at any given “square” along the maze, there are two open routes. There’s the way forward, yes, but also the way you came! If your way forward is to the left of you at any point, my algorithm has you going back and forth in an infinite loop. And that’s pretty much what happened.

However, if you turn three times after every step, your problem is solved. It is a little bit inefficient because the way forward is often ahead of you or to your right. But with a robot that can only turn right, you need to start testing to your left – therefore, turn three times, then start your “am I touching something? –> turn if it’s a wall, step if it’s not” stuff.

But now writing this out, I realize I could have added a few more lines and made the robot’s progress much more efficient. He could also test (facing ahead), turn and test, then turn twice, then test. I think that was the professor’s solution, though I didn’t understand it at the time he was presenting it.

And lo and behold, writing things out is what Otto the Robot is actually about. If you just step up to the interface and begin plugging things in, you’re going to have a hard time of it. The scenario and the interface (it’s not exactly a top-flight IDE) conspire to make you draw out your plans (say, on paper) before you barge in. And as Dr. Scobey at Saint Mary’s puts it, “The sooner you start typing, the longer it’s going to take.”

A good lesson to learn. By the way, if you choose to try Otto yourself, don’t worry about the numbers next to the list of commands in the introduction. In the actual game, you will be able to just point-and-click – you won’t need to memorize those numbers. I assumed the worst and started writing down a list of commands before I saw that it’s not necessary.
Tags: nscc
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

  • 1 comment