[ Home Page ] [ Eiffel Archive ] [ Eiffel Applications ]

Arc de Triomphe clipart (2486 bytes)

The Weighing Game


Written by David Clark.

weigh.zip (14,317 bytes) - source code
http://willow.canberra.edu.au/~davidc/weigh.html (The Weighing Game home page)


By David Clark, University of Canberra.
davidc@ise.canberra.edu.au
September, 1998.

This application was written so that it can be played with a web based interface or a console based interface. A couple of design decisions flowed from this. Firstly the command pattern is used to decouple the human interaction component (hic) from the problem domain. The architecture is thus

HIC -- COMMANDS -- WEIGH_GAME

Two commands are used, one to apply weighings and the other to test the user's choice of fake coin and weight. Complementing this, there is an abstract HIC class from which HIC_CONSOLE and HIC_WEB inherit. The commands refer each refer to a HIC object rather than a HIC_WEB or HIC_CONSOLE object. This means that to generate a web [console] based application make HIC_WEB [HIC_CONSOLE] the root class in the Ace file.

Other decisions:

  1. A problem arises because of the nature of cgi scripts. Each presentation of a weighing and the final testing is a separate execution of the cgi script (ie the application). So how is the state of the game maintained? Two options are to store the game or to reconstruct it. The former requires that each game is given an id, and there is housekeeping in the form of setting write permissions in a directory on the server and discarding old games. The latter requires that the previous weighings have to be passed back and forth between the web browser and the cgi script. I have chosen this option, to reconstruct the game.
  2. Users can get it wrong! They are asked to enter letters between A and L and they enter an M. Even on the web where they choose they can still put 2 coins on one side of the scales and 3 on the other. Thus there will have to be edit checks and error messages. These features could be put into the WEIGH_GAME class or put in a separate class WEIGH_EDIT. I have chosen to write a separate class.
  3. My final decision was to be nasty, by penalising a player who makes a poor choice of coins to weigh. For instance, a first weighing of A against B would be a poor choice. But if I pre-determine the fake coin, 1/6 of the time it would be A or B and they wopuld get away with it. So therefore I don't choose the fake coin until I see their weighing. This makes the logic a little tricky.

Compiling the application(s)

  1. The applications have been tested with ISE 3.3.9 (Win95) and 3.3.7 (Sun)
  2. You will need the EiffelWeb toolkit either in a cluster (directory) mentioned in your Ace file or precompiled into your precompiled library.
  3. Put all of the eiffel source files and the Ace file in your project directory (the root cluster in your Ace file). This includes a HTML_TABLE class I wrote to supplement EiffelWeb, and which could also go in your EiffelWeb directory.
  4. Amend the Ace file to reflect your project directory and make HIC_WEB or HIC_CONSOLE the root class.
  5. Melt, freeze or finalize the application and put the executable (plus melted.eif unless you have finalized) into the cgi bin directory on your web server. Put the two htmml files in the web docs directory of your server.

[ Home Page ] [ Eiffel Archive ] [ Eiffel Applications ]