Giter Club home page Giter Club logo

the-fastest-tictactoe-yet's Introduction

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

the-fastest-tictactoe-yet's People

Contributors

redbedhed avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.