Game Pigeon Tic Tac Toe

The best way to learn python is by doing projects. So hello python lovers today we develop Tic Tac Toe Game in Python. Mini projects are best practice for beginners to get more interest in coding. So let’s code a tic tac toe game in python.

What we gonna do?

Play a retro version of tic-tac-toe (noughts and crosses, tres en raya) against the computer or with two players. Tic-Tac-Toe - 3×3, 5×5, 7×7. The game has 3 options - the standard tic-tac-toe(3×3), 5×5 and 7×7, where you have to place 4 consecutive X to win. You can play against the computer or against someone next to you. Contact email: Follow us on Twitter Facebook. Tic Tac Toe Games; HOW TO PLAY. Use the MOUSE to play. Tic Tac Toe Paper Note 👍 91% 🕹️ 4224. Dora Tic Tac Toe 👍 78% 🕹️ 1759. Water Mist Tic Tac Toe 👍 70% 🕹️ 1253. Water Mist Tic Tac Toe 👍 0% 🕹️ 787. Tic Tac Toe 2 👍 79% 🕹️ 4972. Bikini Bottom Tic Tac Toe.

Two players will play the tic tac toe game. First, we ask the user to enter their name. Initially, we print the empty board and then we’ll take the user input and we’ll check for the winning condition and if the whole board gets filled and no one wins, we’ll declare the result as “Tie” and ask users if they want to restart the game.

Which python concepts are covered?

  • List
  • If-else
  • for loop
  • functions
  • break statement

How does the game work?

The board is similar to the number keyboard. So, players only need to enter a position number to put their character (X or O).

Let’s code Tic Tac Toe Game in Python

First, we are using python List to create a tic tac toe board. We’ll create a list of length 9. Initially, all elements are filled with a blank character (” “). Each place of the list will represent a block in the board and its corresponding value will represent the move made by a player. We’ll create a function draw_board() which we can use every time we want to print the updated board in the game.

Initially board will look like this,

Google Tic Tac Toe

As the game start, we ask players to enter their names. And we’ll store names in and player2 variable. So, character X and O assign to player1 and player2 respectively.

Now, in the main logic, we’ll take the input from the first player and check if the input is a valid move or not. If the block that player requests to move to is valid, we’ll fill that block else we’ll ask the user to choose another block.

Now, to check the winning condition, we’ll check a total of 8 conditions and whichever player has made the last move, we’ll declare that player as a winner. And if no one wins, we’ll declare “Tie”.

Inside every condition, we call another function declare_winner(). If the condition will become true mean player wins the game and this function will be called.

And once a for loop condition will become false or game is over then we ask the user to play again.

Your tic tac toe in python is ready now.

2 Player Tic Tac Toe

The full code

Output

reference: The Classic Tic-Tac-Toe Game in Python 3

Hope you enjoyed it. Now It’s your turn to make your own tic tac toe game in python with some modifications. Share it with your friends.

Play Tic Tac Toe Free

Pigeon

Free Tic Tac Toe Online

More python games,