# Fight Battle 21

Based off a very, very well-known puzzle

The new RPG, Fight Battle 21, is now here! Now with the same three characters as the previous 20 editions!

Knight: 6 HP, 60% chance to deal 3 damage

Archer: 4 HP, 100% chance to deal 2 damage

Mage: 2 HP, 80% chance to deal 4 damage

When you choose your character, you'll be put into an arena with the other two characters in a turn-based combat battle!!

The turn order starts with you, then goes Knight, Archer, Mage (starting with you, so if you choose Archer, Mage is next)

On your turn, you must make an attack. You have a certain chance of dealing a certain number of damage, which reduces your target's HP. Your HP, chance and damage are noted in your character sheet above.

You know, however, how the game's AI will attack.

The AI will attack the target with the highest health. If two or more targets have the same health, the AI will attack the target with the highest starting health.

Alright, cool! Now all you need to do is find a way to win... at least 80% of the time.

What, you thought this would be easy? Start grinding. You'll need the XP.

I'd

pick the Archer, then shoot the Knight, bringing him down to 4

Then

the mage would shoot the Knight (highest starting value) and 80% of the time, kill him.

Then

its my turn again and I'd shoot the mage, killing him and winning.

So

This would give me at least an 80% chance of winning and actually it would be a lot higher using this strategy:

If the mage misses, it's the knight's turn. He will attack me. 60% of the time he will reduce me to 1. Then my turn, I'll reduce the knight to 2. The mage will have another 80% chance to kill the knight. (Adding 9.6% to my winning chances because I'll kill the mage next turn). If he misses, the knight will attack the mage and kill him 60% of the time. (Adding 1.44% to my winning chances because I'll kill the knight next turn). If the knight misses, then I'll kill the mage and 40% of the time the knight will miss me next turn and I'll win (Adding .384% to my winning chances)

If the knight misses his first attack against me, then I'll kill the mage and the knight must hit me twice in a row to win (36%) meaning I'll win 64% of the time adding 5.12% to my chances of winning

This brings my chances of success to over 96.5%!

• I was expecting this to go quick, but not this quick. Nice job! – Excited Raichu Nov 29 '18 at 18:17

I took a programming approach to this puzzle. You can review my code and run it yourself at this link.

The code, starting with the Knight, rolls a random number between 0 and 99. If it's less than 60, then the Knight attacks the highest HP user (or the Archer if they're equal). Then the Archer attacks, then the Mage rolls a random number between 0 and 99, and rolls if it's less than 80. This is repeated 100 times. The console then outputs the number of wins for each battler over the 100 battles.

This same process is repeated twice more, with the Archer and Mage as their respective leads.

The code gives this approximate win percentage data:

- Archer: 91-95%
- Knight: 3-5%
- Mage: 1-3%

- Archer: 90-95%
- Knight: 3-5%
- Mage: 1-3%

- Mage: 58-68%
- Archer: 30-40%
- Knight: 0-2%

Therefore, if you want to win 80% of the time,

you should choose the Archer.

EDIT: Based on Sconibulus's comment, I've done a run of code that would have the Knight attack itself on the first turn, in order to avoid being attacked by the Mage on turn 1. Here is the updated code.

The results of the Knight attacking itself on the first turn

increase its win percentage to around 4-10%. Better, but not nearly good enough to give it a chance in this puzzle.

• This is based solely on how the AI would attack, as the Knight, I think you might be best off attacking yourself first so the mage kills the archer. – Sconibulus Nov 30 '18 at 15:57
• @Sconibulus I've added code to the end of the post that tests your idea. – Meerkat Nov 30 '18 at 16:18
• Nice, I got around 30%, (.6*.8*.6 for the everything hits win, plus small percentage points elsewhere), but yeah, Archer is clearly the best choice. – Sconibulus Nov 30 '18 at 16:42

I decided to see what happens if the computer played itself. I tested until the first death.

Remember, the rules are:

• Knight: 6 HP, 60% chance to deal 3 damage
• Archer: 4 HP, 100% chance to deal 2 damage
• Mage: 2 HP, 80% chance to deal 4 damage

Knight first

Knight attacks Archer - 60% (6,1,2) 40% (6,4,2)

Archer attacks Knight - 60% (4,1,2) 40% (4,4,2)

Mage attacks Knight - 48% (0,1,2) 12% (4,1,2) 32% (0,4,2) 8% (4,4,2)

Archer first

Archer attacks Knight - 100% (4,4,2)

Mage attacks Knight - 80% (0,4,2) 20% (4,4,2)

Mage first

Mage attacks Knight - 80% (2,4,2) 20% (6,4,2)

Knight attacks Archer - 48% (2,1,2) 32% (2,4,2) 12% (6,1,2) 8% (6,4,2)

Archer attacks Knight - 48% (0,1,2) 32% (0,4,2) 12% (4,1,2) 8% (6,4,2)

So the Archer has the quickest 80% kill rate (two turns), and it's always the Knight that dies.