Coder Social home page Coder Social logo

ducthang-vu / tic-tac-tow-with-ai Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 8 KB

This is a python implementation of Tic-Tac-Toe.

Python 100.00%
game py python3 python opponent tic-tac-toe tictactoe tic-tac-toe-game minimax-algorithm difficulty-level

tic-tac-tow-with-ai's Introduction

Tic Tac Tow with AI

This is a python implementation of the paper-and-pencil game from childhood: Tic-Tac-Toe, also known as Noughts and crosses or Xs and Os.

This project is from the Jetbrain Academy (https://www.jetbrains.com/academy/).

Features

It is possible to play the game with the AI, with three levels.

The "easy" level will make random moves.

The "medium" level difficulty makes a move using the following process:

1. If it can win in one move (if it has two in a row), it places a third to get three in a row and win.
2. If the opponent can win in one move, it plays the third itself to block the opponent to win.
3. Otherwise, it makes a random move. 

The "hard" level difficulty implements the minimax algorithm, which is the brute force algorithm that maximizes the value of the own position and minimizes the value of the opponent's position. Basically, it can see all possible outcomes till the end of the game and choose the best of them considering his opponent also would play perfectly. So, it does not rely on the blunders of the opponent, it plays perfectly regardless of the opponent's skill.

Usage

Download the repository and run tic-tac-tow.py.

The main menu accepts two commands: "start" and "exit". The "start" command takes two parameters: four parameters are possible: "user" to play as a human, and "easy", "medium" and "hard" to play as an easy level AI. The command "exit" should simply terminate the program.

The first player uses the "X" symbol, the second "O".

If any of the player is human, the user should input 2 numbers that represent the cell on which user wants to make his "X" or "O". The coordinate (1 1) is the bottom left cell.

Input command: > start user hard
---------
|       |
|       |
|       |
---------

Enter the coordinates: (x y) > 2 3
---------
|   X   |
|       |
|       |
---------

Making move level "hard"
---------
| O X   |
|       |
|       |
---------

Enter the coordinates: (x y) > 

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

tic-tac-tow-with-ai's People

Contributors

ducthang-vu avatar

Stargazers

 avatar

Watchers

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