Tic Tac
Basic python TicTacToe game
## How to Choose where you want to go
# | 1 | 2 | 3 |
# | 4 | 5 | 6 |
# | 7 | 8 | 9 |
##
# Defining functions
board = ["~", "~", "~", "~", "~", "~", "~", "~", "~"]
moves = 0
xs = []
os = []
XorO = 0
def playing():
global XorO, moves
choose = input("Please choose where you want to go: ")
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
sign = ""
if choose.isdigit() and int(choose) in numbers:
if "~" in board:
pass
else:
return
if XorO % 2 == 0:
sign = "X"
else:
sign = "O"
choose = int(choose) - 1
board[choose] = sign
print("------------")
print(board[0:3])
print(board[3:6])
print(board[6:9])
moves += 1
XorO += 1 # switch to the next player's turn
if moves == 9:
converter(board)
print("Maximum moves reached! The game is over.")
return
playing()
elif len(board) == 0: # Escape Key
return
elif len(board) == "^C": # Escape Key
return
else:
print("Please choose a valid input (1-9)")
playing()
def converter(x):
pos = 1
for i in x:
if i.lower() == "x":
xs.append(pos)
elif i.lower() == "o":
os.append(pos)
pos = pos + 1
return xs, os
def winner():
print("hello")
print("Hello! Please select your move.")
playing()
print(xs, os)