11
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).
can we use 0 and 11 to represent S and B respectively? – Leaky Nun – 2016-06-26T23:17:00.403
@LeakyNun no, that would make it too easy to rank them. – Maltysen – 2016-06-26T23:18:46.653
1I knew about the reversal of ranks (1s used to be best, beaten only by attacking spies, 8s were miners, and 9s were worst), but I never heard of the spotter rank or guess-and-you-win rule. But that's just me babbling. Of actual interest here: What about flags? – msh210 – 2016-06-27T15:33:53.257
1@msh210 I was considering having an output of
"Victory!"
for them, but didn't want to complicate things too much – Maltysen – 2016-06-27T19:00:00.187Doesn't a Spy win any battle (if the one attacking), with the exception of a Bomb, and lose all defenses? And what set of Stratego rules is this from? Spotters (Scouts) would be
2
s, and there were no1
s in my Stratego game... (or are they just modified for the purpose of the challenge?) – mbomb007 – 2016-06-29T20:30:19.297@mbomb007 idk, its the one I have in my house.
2
s are still scouts, but don't have any special rule for attacking. And yeah, I don't know if all the games have special rules for1
's , but mine did. – Maltysen – 2016-06-29T20:37:24.1632
s could move like Rooks in mine. – mbomb007 – 2016-06-29T20:38:48.700@mbomb007 they do in mine also, but the attacking mechanics are the same. – Maltysen – 2016-06-29T20:39:24.600