Towers of Benoi

Quickjump to: -Source Code- -Rules- -Controls- -Revision History- -Contact-


Background

This is a little game I made while tying to learn how to develop for the BeOS. I played around with the Drag&Drop-features of the OS and with the messaging stuff this implies.
As I saw that nobody released a 'Tower of Hanoi'-game, I chose to release mine.


Source Code

After I added quite some features, found and removed some bugs and did a lot of cleaning up, I decided to publish the source code including the R4 x86 project file from V1.6 on.
I commented a lot and it took me four hours to do that. Every newcomer developer is invited to have a look at the source code. Perhaps he may find something usefull. I put notes to some facts that I found remarkable. Mostly, these are facts, that I stumbled across and that cost my a lot of debugging time.
Developers, please feel free to drop me a line by eMail (marco.zinn@gmx.de).
When you're interested in the code, start reading with Towers.h.
Note on V 1.6: The code parts which spawn and control the solver thread are not commmented too much. See the corresponding chapters in the BeBook for same good explanation.


Rules

In case you're unfamiliar with it... (if you know the rules, read about the controls).
You see a tower made of 'discs' of different sizes on the left side of the so-called 'tower window'. (In my original game, these are wooden discs, but as we are looking at a 2D-tower from the side, they will look a bit like bars to you. Just take a quik look at the screenshot below.)
The goal is to move the discs and to pile all of them up to a form tower at the (now empty) location to the right, which is named 'C'. (Remark: as for V 1.7, the game will also let you win, when you build the tower onto 'B' instead of 'C')

There are two rules:

  1. You can only move the discs one by one
  2. You cannot stack a larger disc on a smaller one.

A screenshot from within the game might make things a bit clearer:

Screenshot in Play
You see three piles, each consisting of two discs at the moment. The largest disc (named '5' and '6') are lying on the left pile. This pile is named tower 'A', as indicated by the'A' above the discs (unbelievable, I know). tower 'B', the pile in the center, contains discs 2 and 3, while the rightmost pile, tower 'C' has discs 1 and 4 on it.

You'll notice that the discs on each tower are ordered by size (and number, which only displays the size): the biggest disc with the highest number always is 'at the buttom' of the tower, while the smallest is on top.

From this position with the game, you might try the follwing moves:

  1. Move disc '5' from tower 'A' to tower 'B' or 'C'. This is not allowed, as disc 5 is bigger than disc 2 or disc 1 (correspondingly)
  2. Move disc '2' from tower 'B' to tower 'A'. This is a valid move. Just drag disc '2' from tower 'B' to tower 'A' and drop it there.
  3. Move disc '2' from 'B' to 'C'. The move is not allowed, as disc 2 is bigger than disc 1.
  4. Move disc '1' from 'C' to 'A' or 'B'. Both of these moves would be all right.

Controls

What follow is a documentation of the control items of the game one by one.

As all controls are quite straight forward, you might just skip this and fiddle around with the game a bit. I tried to make the UI intutive and user-friendly. It's not perfect, but it should not present any surprises to you (as long as you know how to bring up a window, which you have accidentially hidden).

Tower Window

Moving discs

You move the discs by just dragging them from one tower and dropping them onto another. When dragging, you will get the uppermost disc of the tower, which always will be the smallest on that tower. When dropping, the disc will be stacked on top of the tower or will start a new tower, if there was not a single disc on that tower (well, just try it, you'll see what i mean). Don't forget, that you are not allowed to put a bigger disc on a smaller one.

Resetting the game

The menus in the tower window let you perfom some more or less spectacular action:

  • The game menu allows you to reset the game to its starting position. This means, that all discs are ordered and stacked onto tower 'A', while 'B' and 'C' will be empty.
    When you like to reset the game, you may simply keep the number of discs and have another try at the same difficulty level or select any number of discs from 2 trough 10.
    Keep in mind that the game will get more and more difficult with more discs. If you choose to have a try with all ten discs, prepare to make at least 1023 moves!
  • The next menu item, 'Start Auto-Solve' begins the Auto-Solve-Routine, which is covered later.
  • The menu item 'Quit' will delete all source, header and executable files from your beos disc and format any other disc volumes found on your system.
    Just kidding....

[Reset Submenu]

  • The help menu lets you take a deep look into the documentation of the game. This will probably be nothing new to you as you are reading that documentation right now.
  • In Addition to that documentation you can find out something about the game in short. This will mainly bring up the version number of the executable and my eMail adress.
[Help Menu]

Control Window

Auto Solving

If you don't believe the task can be done at all, you may watch the game solve itself. Just press the friendly button named 'Start Auto-Solve' or select the corresponding item in the game menu.
This will start solving the game from the given position. While watching, you can speed up or slow down things a bit with the slider. You may also just stop (or pause) the solving process with that same button in the window, which will change to 'Stop Auto-Solve'.
BTW: Auto Solve will need 15 moves with the 4 discs, so you now know what to aim at.
Another BTW: This is not linear! With 5 discs, you will need 31 moves. Guess the rest.....
[Control Window]

History Window

The history window sadly doesn't let you control anything usefull, but I'll tell you a bit about it anyway.
The idea is to provide information about the moves that have been made up to now. This is done in the list, which scrolls down and shows the latest move at the top.
The number of moves is noted and displayed in the first line. This should be useful for competetive reasons.
The number of discs in play and the minimum number of moves (in order to solve the game with that number of discs) is shown in the second text line.
When you have solved a game and the number of 'moves done' is equal to the minimum number shown in the second line, you have done a very good job!
Additionally to that, the history window will mark moves that undo a previously made move by printing it in braces. The undone move will be 'embraced', too.
[History Window]

Revision History


Contact and Website

Please contact me, if you have some thoughts about this game, which you would like to share with me.

You can reach me by eMail to marco.zinn@gmx.de or via ICQ. My UIN is 1158139 (Nickname Merlin). Feel free to send me a message or chat with me, if you find me online.

The latest version of this game can be found at the BeOS section of my private homepage (http://www.marco-zinn.de/beos/beos.htm)