Lab 6: The Truel

This project requires you to write a component for a program that will interact with the rest of the program using the "message-passing" analogy for understanding methods.

Introduction

A truel is a fight involving three parties--- like a duel, but with three people instead of two. Imagine three people, each with a gun and the same number of bullets, shooting at each other until either (1) at most one is still survives, or (2) all survivors are out of bullets. The winner(s), if any, of the truel are those who survive til the end.

There are various ways truels can be set up. Here are the variables we will recognize in our definition of a truel are the following:

In each round, each player (called a trueller) must choose which other trueller to shoot at. (The trueller may choose to shoot at no one-- that is, fire into the air-- but it must shoot and use up a bullet at each turn.) The strategy is to choose a target that will increase its chance of survival.

Writing a Trueller class

Make a directory for this project and copy all files from this lab's directory:

mkdir lab5
cd lab5
cp /homes/tvandrun/Public/cs235/lab5/* .

Your task is to write a class using the following skeleton:

public class PutYourClassNameHere implements Trueller {

    public void enterGame(int number, TruelStatus game) {
                  // be notified that you have entered a truel/game

    }

    public int shoot() {

             // determine at whom to shoot

         return 0;     // delete this line

     }
}

(The implements Trueller part will be explained tomorrow in class; you don't need to know that it means today, but it needs to be there.)

When the method enterGame() is called, this indicates to an object of your class that a truel has started and your object is one of the truellers. The parameters tell your object what number trueller it is (0, 1 or 2), and it also gives your object a reference to another object of type TruelStatus which gives information about the current status of the truel. More on that later.

When the method shoot() is called, this means that it is your object's turn to shoot, and it must return a number indicating at which other player to shoot this round--- 0, 1, or 2. If you return a number other than 0-2, that will be interpreted as shooting into the air. Your object may choose to shoot itself, but this is not advisable. (An object never misses if it shoots at itself.)

Your shoot() method is what implements whatever strategy you come up with. It must calculate which player to shoot at.

The TruelStatus object has the following methods:

    public boolean isAlive(int truelerNumber);

    public double marksmanship(int truelerNumber);

    public boolean isFixedSequential();

    public boolean isRandomSequential();

    public boolean isSimultaneous();

    public boolean hasShotAt(int shooter, int target);

You can use this to find out if, at a given point in the game, another player is still alive. You can also use it to find out what the marksmanship level is of each and what the firing rules of the current game are. You can also find out if a certain trueler has shot at another certain trueler (for example, if someone has shot at you).

Use instance variables to keep track of information between method calls. For example, in the method enterGame(), you are given a TruelStatus. You are going to need that later, in shoot().

To test out your Trueler, run the java program Truel. This allows you to make up three players, pick which kind of trueler they will be (ie, what class to instantiate for them), pick which kind of truel, and choose the number of bullets. Each trueler will be given a marksmanship quotient at random, but you can decide whether that quotient is normally (ie, on a bell curve) or uniformly distributed. I have already provided three trueler classes: Hero, which always shoots at the opponent who is a better marksman; Bully, which always shoots at the worse marksman, and Crazy, which picks an opponent at random.

See Kilgour and Brams, "The Truel", Mathematics Magazine, vol 70, no 5, December 1997 for reference. It's available in the Brandt room.

3. Tournament

I recommend experimenting with various strategies. Write several trueler classes and see which ones work better. Remember, your goal is to increase the chances of survival. The best trueler won't always survive, but better truelers will survive more frequently.

Give your trueler class a name that includes your last name or some way to identify yourself as the author. Copy the classfile to the directory /homes/tvandrun/Public/cs235/truelers.

cp AwesomeBestTrueler.class /homes/tvandrun/Public/cs235/truelers

The trueler classes in that directory will be used in a tournament at the end of lab. Things to note:

4. Turn-in

Hand in a hard copy as usual. This will be separate from the submissions to the directory.


Thomas VanDrunen
Last modified: Mon Oct 13 17:20:40 CDT 2008