21 Tic-Tac-Toe: Exploring state

 

One of my favorite movies is the 1983 release War Games starring Matthew Broderick, whose character, David, plays a young hacker who enjoys cracking into computer systems ranging from his school’s grade book to a Pentagon server that has the potential to launch intercontinental ballistic missiles. Central to the plot is the game of Tic-Tac-Toe, a game so simple that it usually ends in a draw between the two players.


In the movie, David engages Joshua, an artificial intelligence (AI) agent, who is capable of playing lots of nice games like chess. David would rather play the game Global Thermonuclear War with Joshua. Eventually David realizes that Joshua is using the simulation of a war game to trick the US military into initiating a nuclear first strike against the Soviet Union. Understanding the mutually assured destruction (MAD) doctrine, David asks Joshua to play himself at Tic-Tac-Toe so that he can explore the futility of games that can never result in victory. After hundreds or thousands of rounds all ending in draws, Joshua concludes that “the only winning move is not to play,” at which point Joshua stops trying to destroy the Earth and suggests instead that they could play “a nice game of chess.”

21.1 Writing tictactoe.py

21.1.1 Validating user input

21.1.2 Altering the board

21.1.3 Printing the board

21.1.4 Determining a winner

21.2 Solution

21.2.1 Validating the arguments and mutating the board

21.2.2 Formatting the board

21.2.3 Finding the winner

21.3 Going further

Summary