Skip to content

RedBedHed/The-Fastest-TicTacToe-Yet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unreasonably Fast Tic Tac Toe

Faster than lightning - Faster than Zenitsu in REM.

"Yes. It's been done before. In fact, it's been done to death. Let's dare to pick the project up one last time... And finish it."

queue the epic music...

Command Line Interface

 
        x | o | o
       ---+---+---
        - | x | -
       ---+---+---
        - | - | -
       I took 0.000001 seconds!
       Make a move (1-9)
       9 8 7
       6 5 4
       3 2 1
       >>_
 

Perfect Play

A perfect-play tic tac toe engine plays a game with no errors. The game will never yield a win for the user. A perfect-play engine is based on the classical Minimax algorithm. This engine is a perfect-play engine.

Compact Bit Board Representation

The game of tic tac toe is played on a board with nine squares. This conveniently allows us to represent the board with two 16-bit integers (four bytes). Marking and erasing a move on the board is accomplished with xor. Tie checking is accomplished with a simple equality check. Victory checking is a matter of mapping one layer of the board to a single bit in a magic table.

Unparalleled Speed (for now)

Due to its extremely small state-space, the full game tree of tic tac toe can be explored in a matter of microseconds. This speed allows for exploration of the entire "perfect-play" tree in well under a second. The perfect-play tree can be used to create a table of perfect moves. These perfect moves are precalculated at startup and stored in a 12288 byte table with an "open-address" hash scheme.

I think that the time and space complexity of the engine can be improved with minimal perfect hashing. However, I was unable to find an easy method (not enough time on my hands, unfortunately). If you can find a method, please let me know and I'll add you to the project!

Average Best Move Calculation Time

1 microsecond.

Table vs. Alpha-Beta (In seconds, from home position)

chart

Releases

No releases published

Packages

No packages published

Languages

  • C++ 70.3%
  • C 13.8%
  • CMake 9.5%
  • Makefile 6.4%