GithubHelp home page GithubHelp logo

ai's Introduction

My tic-tac-toe game uses the minimax algorithm. It is capable of using the multiplayer
formulation described in the textbook, with a vector of utilities at each node. It is slow
to start up because it generates the entire game tree at the beginning. This allows gameplay
to be smooth. Theoretically, this code could use more than two players or more than 3x3
boards. However, memory usage and CPU time limitations make that pretty impractical. For the
simple 3x3 case, this program takes about 5 seconds to start on my machine and uses about 26MB
of RAM. I have not gotten it to successfully generate the tree for a 4x4 game yet - it requires
multiple gigabytes of RAM and multiple minutes of time at least.

One thing that I added to the minimax algorithm was the concept of "distance" - how many turns
will be required to reach a state. By including this information, it is possible to prefer
paths that more quickly result in an endgame. I added this when I observed the AI making
unintuitive moves when it could always win but when one win state would take more moves
to get to than the other win state. It should prefer the one with fewer moves (for example,
if it can win on the next move), but it was sometimes choosing the longer path. While this
property could be interpreted as being "sadistic" and therefore possibly a desireable trait
for an adversarial AI to have, I thought that it should try to favor fast games.

I did not separate the AI algorithm kernels out of the rest of the game code, so in that sense
it might not be as general as it could be. However, the algorithms are sufficiently simple
that I don't think there would be much value to that. As I've said before, the algorithm
can be used with any board size and any number of players. I thought about supporting non-square
boards, but I ultimately decided against it. I don't think it would be very difficult to support
though - the main difference would be that there are no diagonals.

This code also implements all of the optimizations having to do with equivalent rotations
and reflections of the game board. This allows the game tree to be as small as possible. It
also stops expanding the game tree when a win or tie is encountered.

Gameplay is simple - just enter your move by entering the coordinates. The game will figure
it out, as long as there are two numbers in your input somewhere.

As a bonus, you can also play this game by sshing to [email protected], password threeinarow.

Again, this was written using Python 3.2.

:)

ai's People

Contributors

atrigent avatar

Watchers

 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.