Code from the Mind Sports Olympiad XVII Programming event, August 2013.
This is verbatim the code I wrote during the event, which this year was nominally a 3 hour blitz to solve a number of coding problems. However, the scoring system used the time of completion as the tie-breaker; not knowing how long my opponents might take provided a strong incentive to get the right solutions and then submit asap. This code won me the gold medal - in the end I submitted an hour ahead of my nearest rival who also had a completely working solution, so I could have taken more time; a single bug would have changed the result. I was the only one to spot that the final game is isomorphic to tictactoe, whose strategy is completely known! (As a result of my speed, 2014 will be harder...)
THIS IS NOT INTENDED TO BE PRODUCTION QUALITY CODE - please do not assume I write like this in my day job! The aim is to get through the problems as fast as you can. It obviously wouldn't be much of a test if it was easy to produce elegant bug-free code!
There's no restriction on the language used - other contestants have used Python, Java, PHP and C++ - but no internet access.