Ultra Dome

http://peopleoflancaster.com/wp-content/uploads/2015/11/thunderdome.jpg

The Simulation

The Ultra Dome is a huge arena littered with items: weapons, shield skins, and medicine bowls. An Ultra Dome gladiator randomly selects an opponent or an item. If an opponent is selected (i.e., the partner), the gladiator attacks the opponent by delivering a strike. The opponent defends against the strike. The opponent's health is decremented. The health of a gladiator is always an integer between 0 and 100, inclusive. If a gladiator's health reaches zero, he/she dies.

If a weapon is selected, then the gladiator discards his current weapon and picks up the new one. (Discarded weapons cannot be reused.) The available weapons include swords, wands, poisons, and flame throwers. These produce strikes of type iron, magic, chemical, and fire, respectively. (Add more if you wish.)

If a shield skin is selected, then the gladiator stretches the skin over his shield. Thus, a shield may have many layers of skins. Different types of skins can reduce the damage caused by different types of strikes.

If a medicine bowl is selected, then the gladiator drinks from the bowl until the bowl is empty or the gladiator's strength is restored to 100%.

A strike has a type, description, and strength. The strength of the strike is a percentage of the attacker's health. As a strike passes through the skins of the defender's shield, its strength is reduced by fixed percentages. For example, each flame-resistant skin a fireball from a flamethrower passes through diminishes its strength by a fixed percentage. Thus, the more fire-resistant skins a gladiator stretches over his shield, the weaker the strike becomes and therefore the less damage it will cause. Of course fire-resistant skins do not reduce the strengths of other types of strikes.

Ultra Dome Implementation

Ultra Dome customizes the agency platform:

Ultra Dome agents are gladiators and the Ultra Dome itself is the facilitator. A gladiator owns a weapon and a shield. Weapons produce strikes, while shields reduce the damage that a strike inflicts. Initially, the weapon is a sword and the shield is a basic shield with no skins. (Such a shield reduces the strengths of all types of blows by a small fixed percentage.)

The Ultra Dome maintains a list of random weapons, a list of random shield skins, and a fixed quantity of medicine. During a gladiator's update cycle a random integer below 100 called luck is generated. If 0 <= luck < 10, then the gladiator drinks enough medicine to restore his health to 100% or until the available medicine is gone. If 10 <= luck < 20, then the gladiator selects a new weapon, assuming any weapons remain. If 20 < luck <= 30, then the gladiator selects a shield skin and strengthens his shield with it, assuming any shield skins remain. Otherwise, the gladiator requests a partner from the facilitator and attacks him During the attack the attacker uses his weapon to generate a strike. The victim defends himself by using his shield to reduce the strength of the strike before his health is decremented.

void attack() {
   facilitator.setPartner();
   if (partner != null) {
      Gladiator opponent = (Gladiator)partner;
      System.out.println(this.name + " is attacking " + opponent.getName());
      opponent.defend(weapon.makeStrike());
   }
}

Weapons as Strategies

We can think of a weapon as a strategy or abstract factory for creating strikes:

Notes:

·       The damage caused by a strike is a random number less than the weapon owner's health and the maximum damage the weapon is capable of inflicting. (You may decide this value for yourself.)

Shield Skins as Decorators

The Decorator Design Pattern (similar to the Proxy Pattern) allows us to enhance the services of a component by nesting it inside concentric layers of decorators that add pre- and post-processing features to select services:

                                                                                            

Each decorator implements the same interface as the basic component, and so is indistinguishable from it. Here's the design:

A gladiator strengthens his shield by stretching the skin over it:

ss.peer = shield;
shield = ss;

The ShieldSkin implementation of reduceStrike(s) is simply to delegate to its peer:

peer.reduceStrike(s);

A concrete decorator such as IronSkin reduces the damage of an iron strike, then delegates to its peer:

if (s instancOf IronStrike) s.damage = Math.round(s.damage * reductionFactor);
super.reduceStrike(s);

Assume a gladiator has stretched two iron skins and a fire skin over his shield, then attempts to defend himself against an iron strike (from a sword). Here's the interaction:

Notes:

·       Skin3 does nothing to reduce the damage of the strike.

·       Basic reduces the damage by a little bit.

The Ultra Dome

UltraDome may wish to override the start method so that it halts when only one gladiator remains. Perhaps at this point it prints a congratulatory message to the winner.

Alternatively, perhaps the Facilitator could provide abstract methods for deciding when to halt the simulation and what should happen when the simulation ends.

UltraDome should provide synchronized methods for getting a weapon, shield skin, and medicine. If weapons run out, then getWeapon could return null and the gladiator continues with the weapon she currently owns.

Program Output

In this lab we are only implementing the back end of Ultra Dome. There is no user interface. Instead, we use colorful diagnostic messages to test the code. Here's a typical output produced by an early version of Ultra Dome:

tournament.txt

The Assignment

Complete the implementation of Ultra Dome following the above description. Do not alter the agency platform.