from tkinter import *

def get_column(prompt):
    while True:
        s = input(prompt)
        if s == "quit":
            return "quit"
        if s == "0":
            return 0
        if s == "1":
            return 1
        if s == "2":
            return 2
        if s == "3":
            return 3
        if s == "4":
            return 4
        if s == "5":
            return 5
        if s == "6":
            return 6
        print("TRY AGAIN: Input 0-6 or quit")

def play():
    # create a window with a blue background
    window = Tk()
    c = Canvas(window, width=700, height=600)
    c.pack()
    c.create_rectangle(0, 0, 700, 600, fill="blue", outline="blue")

    # initialize and draw a blank board
    board = new_board()
    display_board(c, board)
    c.update()
    player = 1

    for i in range(42):
        prompt = "Player " + str(player) + ": Which column (0-6, quit)? "
        row = None

        # Keep on asking for an input until the user gives a
        # column number onto which a disc can be placed.
        # Place the disc at the correct row in that column.
        while row == None:
            column = get_column(prompt)
            if column == "quit":
                return board   # when user quits, return final game board
            row = add_piece(board, player, column)
            if row == None:
                print("Warning: column " + str(column) + " already full")
        display_board(c, board)
        c.update()
        if check_win(board, row, column):
            print("Player " + str(player) + " won!")
            return board
        player = player % 2 + 1
    print("The game ended in a tie.")
    return board

def check_win(board, row, column):
    if check_win_vertical(board, row, column):
        return True
    if check_win_horizontal(board, row, column):
        return True
    if check_win_diagonal1(board, row, column):
        return True
    if check_win_diagonal2(board, row, column):
        return True
    return False

# INSTRUCTIONS:
# DO NOT CHANGE ANY CODE GIVEN ABOVE.
# Complete the required functions below based on the
# information given in the assignment.
# Remove the code stub we give you and replace it with
# the required code based on the assignment description.
# Do NOT remove more than one stub at a time. 
# Test each function you write before you move on to the 
# next function.
# After you complete each test in the assignment, make
# a copy as your next version and don't change the copy.
# If you get stuck or lost, go back to a previous version,
# copy it back to connect4.py, and try again.

def new_board():
    return None    # stub: remove this line when you write this function

def display_board(c, board):
    return None    # stub: remove this line when you write this function

def add_piece(board, player, column):
    return None    # stub: remove this line when you write this function

def check_win_vertical(board, row, column):
    return False   # stub: remove this line when you write this function

def check_win_horizontal(board, row, column):
    return False  # stub: remove this line when you write this function

def check_win_diagonal1(board, row, column):
    return False  # stub: remove this line when you write this function

def check_win_diagonal2(board, row, column):
    return False  # stub: remove this line when you write this function
