In the game Stratego, the main game mechanic is when you attack an opponent's piece with yours. In this challenge, you job is to simulate one of these battles and say who survives.
Specs
You will get as input a pair of string representing Stratego pieces. The pieces are one of "S 1 2 3 4 5 6 7 8 9 10 B"
(S
is the Spy, and B
are bombs). The first of the pair will be the attacker, and the second the attacked.
Here are the rules for determining the results of a battle:
- The higher number beats the lower number:
["4", "6"] -> ["6"]
. - If both are the same, then both die:
["7", "7"] -> []
. - Spies are at the bottom, underneath even
1
:["S", "2"] -> ["2"]
. - However, if a spy attacks the
10
, then the spy wins:["S", "10"] -> ["S"]
. - But the normal rules still apply if the
10
is the one attacking:["10", "S"] -> ["10"]
. - If anything attacks a bomb, the bomb wins:
["5", "B"] -> ["B"]
. - However, a miner (a
3
), can defuse a bomb:["3", "B"] -> ["3"]
. - A bomb will never be the attacker.
- A spotter (a
1
), can attack using the normal mechanism, but they can also try to "guess" the rank of the other player, which can be denoted with any sane notation. - If they guess correctly, the other piece dies:
["1(5)", "5"] -> ["1"]
. - If they guess wrong, nothing happens:
["1(3)", "5"] -> ["1", "5"]
. - Spotters can spot bombs:
["1(B)", "B"] -> ["1"]
.
This is code-golf, so shortest code in bytes wins!
(You can use the examples up there as test-cases, because I'm too lazy to put them all together in one list).
"Victory!"
for them, but didn't want to complicate things too much \$\endgroup\$2
s, and there were no1
s in my Stratego game... (or are they just modified for the purpose of the challenge?) \$\endgroup\$