simulation solution
This question is down voted heavily because many can\'t solve it and top rated solutions answer it by constructing complex rules. This make it a brain teaser.\n
This question is down voted heavily because many can\'t solve it and top rated solutions answer it by constructing complex rules. This make it a brain teaser.\n\nThe key insights are few\n\n* Convert each stone to mod 3 results: 0, 1, or 2.\n* If there\'s no "0", after alice choose 1 or 2, each player\'s decision is determined. They must pick 2 if current sum is mod 2 or pick 1 if current sum is mod 1. Then the sum switch between mod 1 and mod 2.\n* If the number of zero is even, it\'s as if there\'s no "0", because whoever for all Alice\'s winning play, if Bob pick one zero to divert the game from the plan, Alice can pick another zero to move it back.\n* If the numer of zero is odd, it\'s as if there\'s only one "0". Whenever that zero is picked, Alick and Bob switch position. Then Alice\'s winning play must assume it is picked because Bob can choose to pick it or not.\n\n```python\nclass Solution:\n    def stoneGameIX(self, stones: List[int]) -> bool:\n        count = [0] * 3\n        for v in stones:\n            count[v % 3] += 1\n        flip = count[0] % 2 == 1\n        \n        print(count)\n        \n        def switch(who):\n            return \'alice\' if who == \'bob\' else \'bob\'\n        \n        def alice_win(who, status, one, two):\n            if one + two == 0:\n                return False\n            #print(who, status, one, two)\n            assert status in (1, 2)\n            if status == 1:\n                if one == 0:\n                    return who == \'bob\'\n                return alice_win(switch(who), 2, one-1, two)\n            if status == 2:\n                if two == 0:\n                    return who == \'bob\'\n                return alice_win(switch(who), 1, one, two-1)\n            \n        if count[1] > 0:\n            if not flip and alice_win(\'bob\', 1, count[1]-1, count[2]):\n                return True\n            if flip and alice_win(\'alice\', 1, count[1]-1, count[2]):\n                return True\n\n        if count[2] > 0:\n            if not flip and alice_win(\'bob\', 2, count[1], count[2]-1):\n                return True\n            if flip and alice_win(\'alice\', 2, count[1], count[2]-1):\n                return True\n            \n        return False   \n```
[]