Thursday, April 12, 2012

Ever wondered how many possible games of Tic-Tac-Toe there are?

Well, probably you haven't. But, I'm that kind of geek. And, it's a game with simple rules, so I've long thought it should be a simple thing to write a program to figure it out.

Well, I did just that a few nights ago. Here's (part of) its output:


 | |  
-+-+- 
 | |  
-+-+- 
 | |  
      
1 game states

X| |   |X|   | |  
-+-+- -+-+- -+-+- 
 | |   | |   |X|  
-+-+- -+-+- -+-+- 
 | |   | |   | |  
                  
3 game states

{...}
(it get's more interesting really quickly; after the 6th move, there are 204 game states, not counting states that are reflections or rotations of another game state). Here is the python source code, along with the full output showing all game states possible, without duplication by rotation or reflection. Enjoy!

No comments:

Post a Comment