Each cell in the grid is either empty or has a color. A colored cell can move to an empty slot or stays where it is. Each color has a list of preferences for what it wants to be next to, so if there are 7 colors, this list has 8 elements, the first one indicating the preference for being next to an empty cell and the other 7 of how much it likes to be next to each of the colors:
When you load the page a random set of preferences is generated and the hash of the page is set to encode that preference. This makes it possible to keep track of interesting configurations.
Nanny Ogg quite liked cooking, provided there were other people around to do things like chop up the vegetables and wash the dishes afterwards.