Cluster: Technical stuff

Let's start with the layout. On the right you can see the segments that make up the control panel. There are eleven of them. Three are applets -- the ones highlighted with green.

So why not merely use a single applet to represent the whole thing? Well, I happen to like non-rectangular control panels. They counteract the stiff, computer-esque impression you sometimes get from Java applets. And applets don't have transparency, but GIF images do. In this case there wasn't any satisfactory way of containing all "interactive" parts in a single rectangle that didn't extend outside the curved border.

The 3D projection technique is fairly similar to the one in Rubik Unbound. I keep the cube fixed and let a mobile co-ordinate system follow the observer. Its "z" axis always points toward the origin and the "x" and "y" axes are kept perpendicular to "z" and each other. When the mouse cursor is dragged, horizontally or vertically, I give the mobile system a proportionate nudge along its corresponding "x" or "y" axis and then re-calculate so that "x" and "y" are once again perpendicular to the direction to the origin, with the right length and the observer has the same distance as before.

The screen co-ordinates of any point are then simply obtained as the scalar products of that point in space with the mobile x and y axes. But in this game I also scale them according to their distance from the viewer, hence the perspective. I scale the marbles as well, but not with exact mathematical precision -- I just use pick the most accurate one from set of pre-constructed bitmapped images with diameters ranging from 30 to 48 pixels, as shown below.

Note how the marbles the furthest away from the viewer are also darker, much like the lines of the grid. It's more subtle for the marbles, but nevertheless helps enhance the 3D feeling of the game.

The technique I use to calculate the computer's move is the standard MINMAX algorithm. You can find it in most textbooks about artificial intelligence (and on the web), so there's not much point in describing it here. Suffice to say, the "Skill" you select in the panel is the depth of the search tree. On the lowest skill level, the computer just looks one move ahead (its own). On the second, two moves ahead (its own and your anticipated response), and so on.