#

# TicTacToe.py

#  Written by Coty R Miller on 29Jan18.

#

board = [" ", " ", " ", \

" ", " ", " ", \

" ", " ", " ", ]

game = 1

player = "x"


def printGameBoard():

print(board[0], " | ", board[1], " | ", board[2])

print("-------------")

print(board[3], " | ", board[4], " | ", board[5])

print("-------------")

print(board[6], " | ", board[7], " | ", board[8])


while(game == 1):

printGameBoard()

print("Player", player, "select a square 1-9")

# Lazy... whatever I'm doing... haha...

a = input(":")

b = int(a)

if b < 9 and b > 0:

b = b - 1

else:

print("ERROR! please enter a valid number (1-9)")

if(player == "x"):

if board[b] == " ":

board[b] = player

player = "o"

else:

print("ERROR! Square already in use!")

else:

if board[b] == " ":

board[b] = player

player = "x"

else:

print("ERROR! Square already in use!")

# Check horizontal wins

if(board[0] == board[1] and board[1] == board[2]):

if(board[0]!=" "):

print("Player", board[0], "wins!")

game = 0

if(board[3] == board[4] and board[4] == board[5]):

if(board[3]!=" "):

print("Player", board[3], "wins!")

game = 0

if(board[6] == board[7] and board[7] == board[8]):

if(board[6]!=" "):

print("Player", board[6], "wins!")

game = 0

# Check verticle wins

if(board[0] == board[3] and board[3] == board[6]):

if(board[0]!=" "):

print("Player", board[0], "wins!")

game = 0

if(board[1] == board[4] and board[4] == board[7]):

if(board[1]!=" "):

print("Player", board[1], "wins!")

game = 0

if(board[2] == board[5] and board[5] == board[8]):

if(board[2]!=" "):

print("Player", board[2], "wins!")

game = 0

# Check cris cross wins

if(board[0] == board[4] and board[4] == board[8]):

if(board[0]!=" "):

print("Player", board[0], "wins!")

game = 0

if(board[2] == board[4] and board[4] == board[6]):

if(board[2]!=" "):

print("Player", board[0], "wins!")

game = 0


# print the winning game board.

printGameBoard()