Magic Square Breeding Game

The Magic Square Breeding Game is actually very simple. Your goal is to breed a perfect magic square of the 3x3 size using the methods evolutionary computing. Don't worry, it's not as complex as it sounds.

Setup and notation

You start the game on a field of 6x4 tiles. Each tile can contain up to one square filled with numbers (see below). As you progress through the game, older squares will automatically move upwards until they disappear off the upper edge ("die of old age"). The bold numbers to the left of the tile rows indicate the generation that the squares in the corresponding row were born into: the higher the generation number, the younger is the square. Only four generations can co-exist at the same time on the field.

At the beginning of the game, you get six 3x3 squares filled with random numbers from 1 to 9. They are imperfect (the chances of you randomly getting a perfect magic square in the first generation are very, very slim) but by applying an breeding strategy, you will eventually produce a perfect magic square out of their "genetic material". To make your task of identifying the squares closest to that goal (the "fittest individuals") easier, each one comes with auxiliary fields on the right and on the bottom that indicate how much the sum of the corresponding row and column deviates from that of a perfect magic square (the sum of each row or column in a 3x3 magic square is always 15). The larger the deviation, the further away the square is from the ideal. The bottom-right field additionally contains the sum of all deviations, thus, providing a single-number representation of the square's "fitness". For very unfit individuals, these numbers will be additionally highlighted in red; the ones that come close to the goal, in yellow; and when you breed a perfect magic square, it will become green.

Basic gameplay

Your primary interface tools are found directly underneath each square:

The checkbox preceded by the word "Kill", when checked, makes the game "kill off" the square prematurely (before it dies of old age). This function is necessary because out of up to 12 squares present on the field at any time, only 6 can survive to see the next generation. The killing happens all children you have specified (see below) are born.

The dropdown menu preceded by "Chld." indicates how many children this particular individual will produce for the next generation. Up to six children can be born in each new generation. The children are produced by randomly swapping ("mutating") two numbers of the parent's square, therefore fitter parents statistically produce fitter children. A child is never identical to its parent.

After you have selected the individuals to be killed and the ones to parent children, press the "Next generation" button for changes to take effect. The game will then apply all changes and display the updated field. That's pretty much it for the basic rules. The real challenge, however, lies in finding an efficient breeding strategy, as you will soon notice that blindly following the "survival-of-the-fittest" principle not always earns the best results...

Winning and losing

You win the game by producing a magic square with the total fitness equal to 0.

You lose the game if all of your squares either die of old age or are completely wiped out.

Saving and loading

To save the game, simply copy the current URL of the page (it is updated with every generation) and save it to your hard drive. Alternatively, you can just bookmark it.

To load a saved game, open the URL you stored earlier in your browser again. If you used a bookmark, just open it and continue playing where you left off.

All game-relevant data is stored in the URL. You may therefore try to cheat by manipulating the saved games. But seriously, what is the fun in that?