Lego Random Hit Machine

Introduction

This page is to help my godson Paul Murray (and his dad John!). Paul (with John's help) had built and programmed a Lego mindstorm machine which when activated, went through a series of operations, turning about its central axis to a cardinal position, then activating an outward movement to knock a man off his perch, then going on to the next position, for all four positions in turn. Here are some pictures - the machine in plan view, the machine in side view, and Paul with another machine he built.

Paul wanted to know how to change the program to choose positions at random rather than in order. It took me a while to get the time to think about this, but here is the result. I don't have a lego system myself, so I have simulated it in a web browser, using JavaScript.

Description

Note

I intentially didn't use an array for holding the 'done' flags, even though that would be my natural approach, and would simplify extending the simulation to more than 4 positions. This was to keep the code simpler to understand. Changing it to use an array and a machine with say six positions, is left as an exercise to the reader.

Author: Paul Hardy

Last modified: 3 January 2002