[Accepted] Swift
\nclass Solution {\n    func stoneGameIX(_ stones: [Int]) -> Bool {\n        \n        let counts = stones.reduce(into: [0, 0, 0]) { $0[$1 % 3] += 1 }\n\n      
```\nclass Solution {\n    func stoneGameIX(_ stones: [Int]) -> Bool {\n        \n        let counts = stones.reduce(into: [0, 0, 0]) { $0[$1 % 3] += 1 }\n\n        guard counts[1] + counts[2] > 0 else { return false }\n\n        func play(_ start: Int) -> Bool {\n            var counts = counts\n            var res: Int\n\n            if start == 1 {\n                if counts[1] == 0 { return false }\n                res = 1\n                counts[1] -= 1\n            }\n            else {\n                if counts[2] == 0 { return false }\n                res = 2\n                counts[2] -= 1\n            }\n\n            for i in 0..<counts[1] + counts[2] {\n\n                if res == 1 {\n                    if counts[1] == 0 {\n                        return (i + counts[0]) % 2 == 0\n                    }\n                    else {\n                        counts[1] -= 1\n                        res = 2\n                    }\n                }\n                else {\n                    if counts[2] == 0 {\n                        return (i + counts[0]) % 2 == 0\n                    }\n                    else {\n                        counts[2] -= 1\n                        res = 1\n                    }\n                }\n            }\n\n            return false\n        }\n\n        return play(1) || play(2)\n    }\n}\n```
['Swift']