Giter Site home page Giter Site logo

minmax_tictactoe's Introduction

MinMax Algorithm With Tic Tac Toe

The following code is an attempt at using C++ to code up a bot which plays the game of Tic-Tac-Toe with a player using the MinMax algorithm. This attempt was mostly made to practice my C++ skills.

This attempt was made with the exclusion of help from any external sources.

Tic Tac Toe Game

Some Things To Note

Tic Tac Toe is a solved game. Meaning that if both players play the optimal set of moves, the game will always close to a draw. This means that the bot can never lose and only draw or win.

The Algorithm

The MinMax Algorithm is an algorithm that employs backtracking to select the optimal decision/move to make in a turn-based game with n players. In this case, Tic Tac Toe is a simple turn based game with n=2 players.

The algorithm recursively travels down a tree of the different possible moves and selects the move which maximises its own score and minimises the score of the other player, effectively Maximising itself and Minimizing the other player(s) hence being the... MiniMax Algorithm. The Coding Train Channel on Youtube does an excellent demonstration of this: https://www.youtube.com/watch?v=trKjYdBASyQ&ab_channel=TheCodingTrain

Algorithm

How To Play With The Bot

Clone the repository and compile game.cpp with a suitable compiler. Upon finishing this, you should run the .exe file that is produced from compilation and run.

The player who goes first will always be randomly generated by the algorithm, however this can be manually changed through going to the main function and editing the line:

int turn = (rand() % 2) + 1; // Generate who's turn it is, either 1 or 2 (To manually set who goes first, set turn to either constant PLAYER or BOT)

Have Fun! /^-^/

minmax_tictactoe's People

Contributors

ilaylow 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.