24
6
- Alice (A) and Bob (B) decided to have a battle.
- Each combatant has 10 health.
- They take turns to roll a 6 sided die for damage.
- That damage is removed from their opponent's health.
- In the end either Alice or Bob, will vanquish their foe.
Show me how the battle went. Outputting these codes for the actions which have taken place.
Attack
B a A
^ Combatant
^ Action (attack)
^ Target
Roll
B r 4
^ Combatant
^ Action (roll)
^ Value
Health change
A h 6
^ Combatant
^ Attribute (health)
^ Value
Win
A w
^ Combatant
^ Action (win)
Example output:
A a B
A r 4
B h 6
B a A
B r 6
A h 4
A a B
A r 6
B h 0
A w
Here are the rules:
- Write in any language.
- A single roll of the die should have an equal chance of resulting in any one of the numbers 1, 2, 3, 4, 5, or 6.
- Alice always starts (Bob is chivalrous, in an old-fashioned way).
- Output an action for each turn.
- You must report the attack, roll, damage and win actions.
- Combatants are upper case, actions are lower case.
- It must not consistently produce the same result.
- There must be at least one whitespace character between an output combatant, action and value.
- The win action takes place when the opponent has zero or less health.
- All parts of an action must be on the same line.
- There should be one action per line.
- Fewest bytes wins.
Have at it!
2Are you sure that "It must not consistently produce the same result" is what you want? I can just hardcode two possible outputs and randomly pick one of them. – user202729 – 2018-03-22T10:37:04.173
1@user202729 Curious point, it'd still have to produce the a valid output with the actions described. I'm not sure it'd be all that much shorter than writing the code. – AJFaraday – 2018-03-22T10:38:01.970
1You could specify that the number rolled each time must be uniformly distributed to a reasonable margin between 1 and 6. – HyperNeutrino – 2018-03-22T10:38:35.377
@HyperNeutrino It's virtually impossible to verify, tho. – AJFaraday – 2018-03-22T10:39:22.900
@user202729 "The distribution of dice rolls must look all-right to me" ;) – AJFaraday – 2018-03-22T10:45:59.850
9The names Alice (A) and Bob (B) are giving me flashbacks to network security class. Actor Alice (A) sends a packet to Bob (B) with key... etc... – Magic Octopus Urn – 2018-03-22T12:45:02.350
21@MagicOctopusUrn that’s them. They’re usually trying to communicate. Sadly conflict often ensues when communication breaks down. – AJFaraday – 2018-03-22T12:48:15.553
7I miss the days when we were trying to figure out how to hide our secrets from Mallory... those were simpler times... – Bob – 2018-03-22T13:36:21.683
4@Bob Mallory is something of a distraction, really. It's Eve you need to watch out for. – AJFaraday – 2018-03-22T13:37:13.070
@AJFaraday when they're locked in a *you* cage, I guess fighting would be the only option then. – Magic Octopus Urn – 2018-03-22T14:20:40.537
It can be hard to verify, but at least it prevents people from hardcoding the values and claiming it has 1/0/0/0/0/0 distribution (though that would probably be dealt with by DV+VTD or a mod anyway) – HyperNeutrino – 2018-03-22T14:29:49.790
@HyperNeutrino In the end I made it pretty prescriptive. Equal chances of each. – AJFaraday – 2018-03-22T14:31:06.117
I don't understand why your first line is AaB. A is attacking B before a roll? Your spec says a roll must be first to determine how much the attack will accomplish. – msh210 – 2018-03-22T16:46:20.307
3@msh210 well, the important detail in code golf is that everyone takes the same challenge, but here’s the logic: - if you were playing Dungeons and Dragons, you’d say “I’m going to kick the goblin”, then you’d roll for effectiveness, then implement the result of the roll. A roll is meaningless if nobody knows what you’re rolling for. – AJFaraday – 2018-03-22T16:52:53.760
I'm not surprised their relationship isnt going well. They've been having communication issues for years. – Robert Fraser – 2018-06-04T10:19:49.073
I want to note that Alice wins 66% of the time because she goes first. Increasing the starting health will reduces the advantage, but player 1 still wins more often. Don't play as Bob. :) – Ben – 2018-06-04T16:08:08.053
1@Ben First rule of all RPG combat, be the protagonist. – AJFaraday – 2018-06-04T16:08:58.493