#

# TicTacToe.py

#  Written by Coty R Miller on 29Jan18.

#

board0 = [" ", " ", " ", \

          " ", " ", " ", \

          " ", " ", " ", ]

board1 = [" ", " ", " ", \

          " ", " ", " ", \

          " ", " ", " ", ]

board2 = [" ", " ", " ", \

          " ", " ", " ", \

          " ", " ", " ", ]

game = 1

player = "x"


def printGameBoard():

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

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

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

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

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


def checkBoard0():

    # Check horizontal wins

    if(board[0] == board[1] and board[1] == board0[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


def checkBoard1():

    # 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


def checkBoard2():

    # 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



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!")



# print the winning game board.

printGameBoard()