How to code Tic-Tac-Toe (and a Lua implementation)

1 · Evan Hahn · Aug. 10, 2011, 5 a.m.
After installing Lua, I had to write Tic-Tac-Toe in Lua for a job interview awhile ago. It seems like a trivial technical problem, but it's not actually that easy. Here's how I did it (which is not the only method): The board is represented by a 2D table of spaces. They are empty to start (nil in Lua's case). When you play, you put an "x" or an "o" into the table. The board is used to keep track of piece locations and to display them. It does not calculate wins. The board also has "regions." A r...