I have played recently a great game on Android, called Alchemy, created by Andrey Zaikin. You start with four basic elements, Fire, Water, Air and Earth and you can combine them to get more and more elements. The game was so catching that after finishing it I decided to write my own version for Windows. I chose WPF because I wanted to learn it and because I realized the stuff I wanted to create was too hard to do in MFC. This is my first real application in WPF, and what you see is the result of 4 days of work; in MFC it could have been 4 months, I believe.

You start with the four basic elements: air, earth, fire and water. You can combine them by dragging onto each other on the central area of the window, “the desktop”. When new elements are created they are added to one of the two lists from the left area. The top list has elements that can be combined again. The bottom list contains terminal elements, i.e. elements that can no longer be combined. You can drag elements from the non-terminals list back to the desktop area, but not from the terminals list.

You can quickly bring onto the desktop the four basic elements by double clicking on an empty area of it. Double clicking on an element from the desktop creates a duplicate of it. You can remove an element from the desktop by dragging it over the trash can icon. You can remove all the elements from the desktop by double clicking on the trash can.

When the number of elements gets too big scrolling through the list might be cumbersome. You can use the search textbox to filter the elements in the list. As you type only the elements that contain the typed text are displayed. It you press the X button of the textbox or clear its content, the list displays again all the unlocked elements.

On the right area of the window you find a help pane. When you select an element from one of the two lists on the left side, you can see a list of all the unlocked combinations in which the elements appears (either as input or output).

There are also several buttons: Cheat, Wikipedia, Help and About. Button Cheat opens a new window that displays the list of all available elements. So if you get stuck and don’t know what elements are left to discover you can cheat and see the list.

Button Wikipedia starts a search on Wikipedia for the currently selected element. Buttons Help and About display information about the game.

Note that your game progress is saved when you close the game and loaded when you start again. The information is stored in a file with your Windows user name and extension .aus. Don’t delete the file or you lose your game progress.

Here is the alphabetical list of all the 210 elements available in version 1.0:


Air Cochineal Gunpowder Ozone Soldier
Airplane Coffin Hippopotamus Panda Star
Alcohol Combustion engine Hourglass Paper Starfish
Algae Computer House Pearl Steam
Arable Concrete Hunter Penguin Steam engine
Arm Continent Hut Penicillin Steamer
Ash Corpse Hydrogen Perfume Stone
Assassin Country Ice Petroleum Storm
Bacteria Darth Vader Jedi Pie Sulfur
Barbeque Desert Kerogen Pinocchio Sun
Beach Diamond Knife Pizza Swamp
Bear Dinosaur Lava Planet Tequila
Beast Dough Library Plankton The Beatles
Beer Dragon Lichen Plesiosaur Thunderstorm
Beetle Dragonfly Life Poison Tiger
Bicycle Dust Light Poisoned weapon Time
Bird Earth Lightbulb Polar Bear Tom and Jerry
Bitumen Egg Lightsaber Pressure Tool
Boat Electricity Lime Pterosaur Tornado
Boiler Energy Limestone Radar Tortoise
Book Fern Livestock Radio Transistor
Bread Fire Lizard Rain Tree
Brick Firearm Locomotive Rainbow Turtle
Butterfly Fish Man Sand Uncut diamond
Cactus Fisherman Manure Santa claus Universe
Car Flour Meat Scarab Vodka
Carbon dioxide Flower Metal Scientist Volcano
Carmine Flu Milk Scissors Wagon
Cat Fly Mite Scorpion Warrior
Caviar Fondue Mold Seed Water
Cement Forest Monkey Shark Watermelon
Cheese Fossil Moon Shell Whale
Chicken Fruit Moss Silicon Wheat
Chip Fugu Motorboat Sith Wheel
Christmas tree Galaxy Motorcycle Sky Wind
City Gasoline Mouse Skyscraper Wine
Clay Geyser Mud Snail Wood
Cloth Ghost Mushroom Snake Wooden ship
Clothing Glass Ocean Snow Wool
Cloud Grape Old man Snowman Worm
Coal Grass Omelette Soda water Yeast
Coca cola Grove Oxygen Solar system Yogurt

Note: In order to run the game you need .NET framework 3.5 SP1.

Stay tuned, updates with more elements are coming!

Update: Download the latest version from here.

, , Hits for this post: 23144 .

Two days ago I posted a simple implementation of a game of colors. Though it was intended only as an exercise, someone has criticizes the use of an int** to hold the grid information, mainly for two reasons:

  • the footprint on 64-bit platforms can get nasty
  • the explicitly allocated memory, instead of using a std::vector

So this is the code:

int** m_pCells; 

void Create()
{
   m_pCells = new int*[m_nSize];
   for(int i = 0; i < m_nSize; ++i)
      m_pCells[i] = new int[m_nSize];
}

Let’s see how much memory it takes. The total size should be:

totalsize = sizeof(m_pCells) + sizeof(m_pCells[0]) * m_nSize + m_nSize * m_nSize * sizeof(int);

On 32-bit platforms, the size of a pointer is the same with the size of int and is 4 bytes. For the maximum size allowed for my grid, which is 50, the total size in bytes for the grid is: 4 + 4*50 + 50*50*4 = 10204.

On 64-bit platforms, the size of a pointer is 8 bytes, but the size of int is still 4 bytes. So for a grid with 50 rows and columns it needs: 8 + 8*50 + 50*50*4 = 10408 bytes. That’s a 2% increase of required memory.

The memory footprint was the last thing I had in mind when I wrote this simple exercise. Well, of course there is a way to require only 4 more bytes on 64-bit platforms. And that is using an int* allocating m_nSize*m_nSize elements.

int* m_pCells;

void Create()
{
   m_pCells = new int[m_nSize * m_nSize];
}

void Destroy()
{
   delete [] m_pCells;
   m_pCells = NULL;
}

With this implementation, when you need to access the element at row i and column j, you have to use m_pCells[i * m_nSize + j].

As for the second argument, that explicitly using operator new[] to allocate memory instead of using a vector of vectors, well, what could I say? Sure, why not. Different people use different programming styles. As long as all implementation are correct and achieve the same goal with similar performance, I guess everyone is entitle to code as he/she wants. But if we go back to the memory footprint, I would also guess that the use of vectors would take more memory than pointers to int, because the size of a vector is several times the size of a pointer. But I wouldn’t say that’s an important issue here.

Anyway, these arguments remember me the joke (or maybe it’s serious) about the rules of optimization:

  1. Don’t optimize.
  2. Don’t optimize yet (for experts only).

(Of course there are super experts that can ignore these rules.)

, , , , Hits for this post: 6941 .

Colors Game

One of the games I like the most on my new phone is about covering a grid formed by cells of different colors with a single color within a limited number of moves. After playing it again and again for a week, I decided to write my own game for the PC.

The rules are:

  • the grid has an equal number of rows and columns, that can vary from 5 to 50
  • cells are colored with six colors
  • coloring the grid always starts from the top left cell
  • adjacent cells having the same color form a single shape; game ends when this shape covers the entire grid
  • to change the color of the growing shape, use the six buttons available on the right side of the grid
  • grid must be covered within a number of moves; if you exceed that number of moves you lose
  • when you win, you automatically get to the next level
  • you can change the size of the grid from the menu

Here are the available downloads: the sources, and the executable.

, Hits for this post: 5633 .