When I was a child, I used to play this game a lot.
There are two players (let's call them A and B), and each player uses his hands as guns. There are three possible moves:
Hands up to load ammunition to your gun.
Each gun starts empty. Loading increases the ammunition by one.
Hands pointing to the other player to shoot.
This decreases the ammunition by one. You must have at least one unit of ammo to shoot.
Crossed arms to protect yourself from a shot.
Both players move simultaneously. If both players shoot at the same time, the bullets hit each other, and the game continues. The game ends when one player shoots while the other is loading ammunition.
Shooting and empty gun is considered cheating. If a player cheats while the other one performs a legal action, the cheater loses immediately. If both players cheat at the same time, the game continues.
Cheating attempts do not decrease ammunition, so it can never be negative.
Given the moves made by players A and B, output which player won the game:
1 for player A,
-1 for player B, and
0 for a draw. You can use any other triple of return values, but you need to state in your answer which ones you use.
The game may:
- end without having to process all moves;
- not end with the given moves, and thus it is considered a draw.
The input can be taken:
- as strings
- as arrays/lists of integers
- in any other way that does not pre-process the input
Full program or functions allowed. Since this is code-golf, the shortest answer in bytes wins!
A: "123331123" B: "131122332" -----^ Player B shoots player A and wins. Output: -1
A: "111322213312" B: "131332221133" -------^ Player B cheats and loses. Output: 1
A: "1333211232221" B: "1213211322221" ----------^^ Both players cheat at the same time. The game continues. Output: 0
A: "12333213112222212" B: "13122213312232211" | || ^---- Player A shoots player B and wins. ^-------^^------ Both players cheat at the same time. The game continues. Output: 1