[Home] [Puzzles & Projects] [Delphi Techniques] [Math topics] [Library] [Utilities]
This program solves the 4 cube, 4 color version of the Instant Insanity puzzle. It was developed by Frank Armbruster and the commercial version is still available from http://www.gamepuzzles.com/prpuzzls.htm .
Background & Techniques
Instant Insanity is a variation of an older cube arrangement puzzle and one
of a large family of similar puzzles. In this one, we have four cubes with one
of four colors on each face of each cube. The objective is to stack the
cubes so each column of faces has all four colors.
Non-programmers are welcome to read on, but may want to jump to bottom of this page to download the executable program now.
This program was about the right size to provide a moderately challenging problem that could be solved (and coded) in 3 or 4 days of spare time programming.
When the Search button is clicked we set up cube definitions, Cubes to be modified as we search from the OrigCubes definition.. Each cube is defined by a 6 character string representing the faces in a particular order. I chose the 6 characters to represent the colors of the Top, Left, Front, Right, Back, and Bottom faces in that order. Cube sets are defined as TCubes type is defined as an array [0..3], of string types.
SearchBtnClick calls recursive depth-first search procedure CheckNext to place the next cube in all of its orientations. CheckNext creates the next orientation for cube N and calls itself to check cube N+1. When the 4th cube has been placed, function CheckSolved is called to test if this arrangement could be a solution. If each of the four visible face directions contains all four color across the 4 cubes, this looks like a solution. Function IsUniqueSolution is called just to make sure that we have not already encountered this solution. IsUniqueSolution may not be smart enough yet to catch all duplicate solutions, but it will catch the case where the same colors appear on opposite faces for two different adjacent faces. (For example GRGR colors on the Left, Front, Right, and Back faces could produce two apparently duplicate solutions when the cube is rotated 180 degrees.)
For efficiency a doubly indexed array, Targets, indexes the face numbers to move to top of cube (position 1 in the cube string). TFace type defines a 6 integer array to specify the target positions for each face of the source cube. So, for example, Targets is a TFace array which specifies the target locations for each of the 6 faces when face 2 is rotated to the top of the cube. Values are initialized by the InitFaceTargets procedure which applies successive rotations to fill in the target positions for each of the faces 2 through 6 is to be moved to position 1 (the top face). Within CheckNext , calls are made to MoveFaceToTop for each face 2 through 6 to run through the Targets array and efficiently rotate the faces. For each face on top it calls RotateCubeRight to rotate each of the visible faces to each of the 4 visible positions.
Suggestions for Further Explorations
Copyright © 2000-2018, Gary Darby All rights reserved.