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.
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 a 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.
Trueller
classMake a directory for this project and copy all files from the
directory /homeemp/tvandrun/pub/235/truel
cp /homeemp/tvandrun/pub/235/truel/* .
Your task is to write a class that implements the interface Trueller
.
This means you have to write two methods:
public void enterGame(int number, TruelStatus game); public int shoot();
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 menthod is what implements whatever strategy you come up with. It must calculate which player to shoot at.
The interface TruelStatus
has the following methods:
public boolean isAlive(int truelerNumber); public double marksmanship(int truelerNumber); public boolean isFixedSequential(); public boolean isRandomSequential(); public boolean isSimultaneous();
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.
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
decided 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.
I recommend experimenting with various strategies. Write several trueler classes and see which onese work better. Remember, your goal is to increase the changes 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 /homeemp/tvandrun/pub/235/truelers
.
cp PercianteTrueler.class /homeemp/tvandrun/pub/235/truelers
The trueler classes in that directory will be used in a tournament in lab on tuesday. Things to note:
Hand in a hard copy as usual. This will be separate from the submissions to the directory.
DUE: Tues, Nov 7, at 5:00 PM.
Note: to be in the tournament, you must have your trueler(s) submitted by lab time on tuesday.