Tic-Tac-Bot-Player

Just a Tic-Tac-Toe

These are not-a-new-thing python scripts for the game Tic Tac Toe

But, this edition has two modes to play the Tic-Tac-Toe game

One of them is a casual mode in which you can invite a friend over to play the game as your rival!

And the other one is where you have a bot-mode where a bot will be your rival this time

You could play the game untill you get tired of it just by running the script once

Oh and, you could also switch modes after the game has ended

Input for the program:

  • This part is a lil tricky but hey!, I have got some examples

  • You have to use co-ordinate system for a 3 X 3 matrix

  • For a matrix like this(which will also be our game board..),
    ———
    | _ _ _ |
    | _ _ _ |
    | _ _ _ |
    ———

  • If you want to take the top-right corner:

    • You have to enter: “1 space 3”
    • The input implies: 1st row’s 3rd box
  • If you want to take the middle box:

    • Enter: “2 space 2”
    • The input implies: 2nd row’s 2nd box

Some things:

  • Feel free to give any invalid inputs (I might have covered them all ;) )
  • If you could make the program run unexpectedly, be sure to let me know in the comments. Why? Well, we are all learners, aren’t we?
  • Feel free to suggest any ideas to improve it as well.. <3
  • Last but not least, this program doesn’t need any requirements. Just be sure to have them all in a single folder.

Source Code: main.py

import with_person
import bot


def choice_checker(choice):
    """This checks if the user has entered a valid choice"""

    global choices
    while choice not in choices:
        print("Enter a valid choice!")
        print("""Choose the mode of game.
        '1' to play with a friend,
        '2' to play with a bot (P.S: You might not win)
        '3' to quit this\n""")
        choice = input()
    return choice


# Giving the user a choice to select the mode of the game they want to play
choices = ['1', '2', '3']
print("""Choose the mode of game.
'1' to play with a friend,
'2' to play with a bot (P.S: You might not win)
'3' to quit this\n""")
choice = input()
choice = choice_checker(choice)

while True:
    if choice == choices[0]:
        with_person.script_with_person()
    elif choice == choices[1]:
        bot.script_with_bot()
    else:
        break

    print("Would you like to try again..?")
    print("""Choose the mode of game.
    '1' to play with a friend,
    '2' to play with a bot (P.S: You might not win)
    '3' to quit this\n""")
    choice = input()
    choice = choice_checker(choice)