This is a simple tic tac toe game that runs in the command line.

Overview

Tic Tac Toe Game

This is a simple tic tac toe game that runs in the command line.

Game Description:

  • The game is made up of a square grid with 9 portions. Each portion represents a slot on which a symbol can be place, either an X or an O.

The game rules are simple; A player wins when his/her symbol is placed in a manner in which a straight line can be drawn to cross over the three symbols.


This game should allow two players to compete. In a later time, we will allow the computer to make decisions.


  • My game design

    • The game contains a list of 3 lists. This is so as to form a square array with 3 rows and 3 columns, each intersection of row and column having a special index number ranging from 1-9.

    • The gameplay is done in turns. When player 1 has played, it is player 2's turn.

    • Player 1 is automatically "X" as symbol while player 2 is assigned the "O".

    • The player's entry is a number between 1 & 9, the slot where his/her symbol is placed.

    • If a slot is empty, then it is represented a "_".

    • The game ends when either of the following happens;

      • A player wins
      • There is no possibility of winning
      • The program crashes, is interrupted or closed.

How do we know if a player has won ?

The has_player_won() function returns a boolean or a string. It returns a boolean enforced to False if there is no player who has won yet. On the other hand, it will return the winning player if a player has won.

# checks if a player has won
    # we are going to use the condition above
    # we will check the leading diagonals and a cross manner
    # we will know if a player (and which player) has won if
    # we can form a straight line with 3 consecutive symbols on the grid
    # if at a certain point, a symbol fails to be the same,
    # we stop checking and move on

    # How do we know a vertical or a horizontal is formed ?
    # This is pretty tricky
    # After thinking a little, I came up with the idea that
    # If we have 3 points whose _i_ value is the same, then it forms a horizontal line -> a win
    # In the case of 3 points with equal _j_ values, then it forms a vertical line -> still a win
    # For diagonals, it is much trickier

    # chech if player won along diagonals
    # the winning slot coordinates are
    # - [(0,0), (1,1), (2,2)] or [(0,2), (1,1), (2, 0)]

    # checking along the first diagonal

Plans

My future plan are to

  • Add the computer as a second player in case you have no friend to play it with
  • Create an online web-based multiplayer tic-tac-toe game with a leaderboard.
  • Train an unbeatable Tic Tac Toe AI ;)
You might also like...
A Python tic tac toe game
A Python tic tac toe game

Tic Tac Toe A Python tic tac toe game To start the game, run python3 main.py First, you have to select the game level. Today, it has three levels In a

Tic-Tac-Toe Game in python3 Tkinter
Tic-Tac-Toe Game in python3 Tkinter

Tic Tac Toe Tic-Tac-Toe Game in python3 Tkinter About: Tic Tac Toe or Noughts and Crosses as called in British is a pencil and paper game for two play

Tic Tac Toe Game build with Python
Tic Tac Toe Game build with Python

Tic Tac Toe Game Description two players who take turns marking the spaces in a three-by-three grid with X or O. The player who succeeds in placing th

Open source Board Games Like Tic Tac Toe, Connect 4, Ludo, Snakes and Ladder etc...

Board-Games What to do... Add Board games like Tic Tac Toe, Connect 4, Ludo, Snakes and Ladder etc... How to do... Fork the repo Clone the repo git cl

Tictactoe py tkinter canvas - Tic Tac Toe written in Python 3 with tkinter mainly using canvas

Python 3 Tic Tac Toe with tkinter This is a tkinter version of my Tic Tac Toe ga

A DDQN that learned to play tic tac toe by playing against itself
A DDQN that learned to play tic tac toe by playing against itself

TicTacToeAI A DDQN that learned to play tic tac toe by playing against itself Cu

Command-line Hangman game

Hang-_an-game-python-build Hangman C command-line Hangman game. Compilation Navigate to the root of the repository from your Terminal and run make to

Blender Game Engine Game Type Templates Logic Bricks (and Python script) based Game Templates for Blender

Blender-Game-Engine-Templates Blender Game Engine Game Type Templates Logic Bric

A set of functions compatible with the TIC-80 platform
A set of functions compatible with the TIC-80 platform

Pygame-80 A set of functions from TIC-80 tiny computer platform ported to Pygame 2.0.1. Many of them are designed to work with the NumPy library to im

Owner
Josias Aurel
Self-taught hobbyist developer. Coding for fun. Making things 😜
Josias Aurel
This is a simple Tic-Tac-Toe game.

Tic-Tac-Toe Nosso famoso e tradicional Jogo da Velha, mas agora em Python. Development setup Para rodar o programa, basta instalar python em sua maqui

João Assalim 1 Oct 10, 2022
Just a simple Tic Tac Toe game, built with Python

TicTacToe Author: Gabriel Lima Table of Contents About Getting Started Linux Windows About This is one of the first projects I built when I first star

null 1 Nov 28, 2021
This is a simple Tic Tac Toe game built with Python.

This is a simple Tic Tac Toe game built with Python.

⚝αикιт кυмαя⚝ 6 Sep 1, 2022
Rudimentary CMD based implementation of the Tic Tac Toe game

Packages used: questionary random os (Requires Python >3.8 as walrus operators are used in the script) Contains the .py file (tictactoe.py) and an exe

Ashwin 1 Oct 15, 2021
Input-based tic tac toe game made in only python.

Tic Tac Toe Tic Tac Toe is a game in which two players seek in alternate turns to complete a row, a column, or a diagonal with either three O's or thr

Ayza 5 Jun 26, 2022
Tic tac toe game developed by naman in python

TIC TAC TOE GAME DEVELOPED BY NAMAN IN PYTHON . IT USES MINMAX ALGORITHM TO COMPETE IN DIFFICULTY MODE

Naman  Anand 4 Jun 24, 2022
Tic Tac Toe game developed in python; have 2 difficulty levels

Tic Tac Toe Game This is a code for Tic Tac Toe game in python. Game has 2 difficulty levels. Easy Hard To play the game, use this command in a LINUX

Akshat Mittal 1 Jun 25, 2022
An old time game Tic-Tac-toe

A Tic Tac Toe Bot This is the code repository for my article on Medium - Playing Games with Python - Tic Tac Toe, where I have tried to take the famou

Jigyanshu 0 Feb 25, 2022
Quantum version of the game Tic Tac Toe.

QTicTacToe Quantum version of the game Tic Tac Toe. This game was inspired by the game at this site. Installation The game requires the qiskit python

null 1 Jan 5, 2022
Tic Tac Toe Python Game GUI

Tic Tac Toe is one of the most played games and is the best time killer game that you can play anywhere with just a pen and paper.

Astitva Veer Garg 1 Jan 11, 2022