Tic-tac-toe in python with source code

Tic-tac-toe in python with source code


Tic-Tac-Toe is a simple paper and pencil game for two players played, making the spaces in 3×3 square grid. It is also called noughts and crosses. X and O are used as a player.

Tic-Tac-Toe is basically an AI (Artificial Intelligence) game playing against a computer or between two persons. The game is playing from first century. An AI is a stimulation that emphasizes the development of machine intelligence to think and work like humans. The machine learns and predicts like being a human.

AI is a very interesting topic. Tic-Tac-Toe is similar to an AI game where the computer plays against humans. Game board consists of a square grid box. The first player to make three marks in a horizontal, diagonal and vertical row is a winner. If there does not appear any row of same marks the game is a tie.

The example below is simple tic-tac-toe.


The above image is a simple tic-tac-toe image. This project uses Python programming language. It is written in a very simple way and is easy to understand. The project does not include any complicated functions. It is an open-source project and also available on the internet too. It is very effective for beginners to enhance their skills. Tic-Tac-Toe uses an AI algorithm. An algorithm is a set of necessary instruction for generating a result. A simple program can generate different algorithms for different functions used.

Tic-Tac-Toe libraries

The project uses Python libraries like NumPy and random. This library provides for random input for the computer. The computer places its input on the board using these functions. Different functions are used in this project.  Some sets of strings are stored in a variable named board which is for drawing the board. The user must choose the 1-9 number for marking on the board while playing the game. It is a console game. Web browsers are not necessary. The outcomes of the game win, lose or tie.

How to use the game project?

  • Download the project.
  • Open the source code in any code editor.
  • Compile and Run.
  • Play the game.


  • Python must be installed.
  • Interpreter must be chosen for compiling and executing the project.
  • Code editor or IDE like Pycharm, sublime text, Atom…etc, is required.

Click the download button below to get the project.