Some of you may have heard of the Wargame series of computer based real time strategy game. These games pit teams of players with primarily cold war era units to see how a hot cold war would have played out. The goal of this challenge is to simulate a tank battle in these games.
Input
- Two "tanks" (one red and one blue) will be entered into your program or function. Each tank is classified by a rate of fire, accuracy, armor value, and attack power value.
Challenge
From the inputs above, simulate the two tanks fighting. You will do this by having each tank fire according to its rate of fire. If it hits (randomly determined by accuracy), a tank will do damage according to the armor value of its target and its own attack power. The formula for damage is floor[(attackpower - armor)/2]
. Therefore a tank with 10 attack power against a tank with 5 armor would do 2 damage.
Tank crews also have morale, which follows the following rule
- There are four possible morale values; calm, worried, scared, and panicked. Tanks always start calm. These names do not need to be in your code, in the sample below I've used calm = 1, worried = 2, etc.
- Each morale value reduces the accuracy as follows: Calm -> 100% (no change), worried -> 75%, scared -> 50%, panicked -> 25%. Therefore a panicked tank which normally has 60% accuracy now has 0.25 * 0.6 = 15% accuracy
- Each hit by the opposing tank degrades morale by one level, each miss upgrades the morale by one level.
For example:
morale: calm | worried | calm | worried | scared
hit: hit miss hit hit
Rules:
- Input should be two parameters to repesent each tank (I've used two tuples in the example below). Inputs may be provided in any order, just be sure to state which one is which. Input may be provided by user input via STDIN, read from a file, or parameters passed to a function call.
- Each tank starts with 10 health.
- Rate of fire will either be 8.5, 7.5, 6.5, 6, 5, or 3 seconds between shots.
- Tanks start loaded, so each fires at time = 0. Because Communists are sneaky, red fires first.
- Accuracy must be randomly rolled.
- Ineffective hits (hits which do no damage) have an effect on morale! (because it probably sounds terrifying)
- Naturally since we want to see the action, output will be an update after each shot. The update will contain the time of the shot, whom it was made by (red or blue), health of both tanks, and the morale of both tank crews. Output maybe be presented in any format so long as it contains all of the required information in a human readable fashion (items must be delimited in some way). Similar to input, please describe your output format in the answer.
- Engagements are limited to 100 seconds. If you play the game you know this is because a plane has swooped in by then. For our purposes if both tanks are alive at this point, it is a draw.
- After one tank reaches 0 health (or after 100 seconds), print which tank is victorious (
"Red"
or"Blue"
) or"Draw"
if appropriate. I don't care about trailing whitespace or newlines. - Printing output may be printing to STDOUT or writing to a file
- Shortest answer in bytes wins
This is a little sample I worked up to demonstrate some of the methodology. It takes the two tanks as tuples to the main()
function, then outputs a nice little table. Your output does not need to be so fancy. For the curious, it's 1,930 bytes. You can do better.
Sample Tanks:
Some tanks to use for you, the numbers are ROF, accuracy, armor, and power.
- T-72A: 8.5, 45%, 12, 16
- T-72BU: 8.5, 55%, 22, 23
- T-80: 7.5, 40%, 14, 16
- T-80U: 7.5, 60%, 20, 23
- M1 Abrams: 7.5, 55%, 16, 18
- M1A2 Abrams: 7.5, 60%, 22, 24
- Leclerc: 6, 65%, 20, 20
- STRV-103D: 5, 60%, 18, 16
- Zhalo (I know, not a tank): 3, 60%, 2, 18