#################################################
# 15-112-n19 hw2-2
# Your Name:
# Your Andrew ID:
# Your Section:
#################################################

import math

#################################################
# Helper functions
#################################################

def almostEqual(d1, d2, epsilon=10**-7):
    return (abs(d2 - d1) < epsilon)

import decimal
def roundHalfUp(d):
    # Round to nearest with ties going away from zero.
    rounding = decimal.ROUND_HALF_UP
    # See other rounding options here:
    # https://docs.python.org/3/library/decimal.html#rounding-modes
    return int(decimal.Decimal(d).to_integral_value(rounding=rounding))

######################################################################
# hw2-2 problems
######################################################################

def areLegalValues(values):
    return 42

def isLegalRow(board, row):
    return 42

def isLegalCol(board, col):
    return 42

def isLegalBlock(board, block):
    return 42

def isLegalSudoku(board):
    return 42

def isKingsTour(board):
    return 42

def makeWordSearch(wordList, replaceEmpties):
    return 42

######################################################################
# ignore_rest: The autograder will ignore all code below here
######################################################################

from tkinter import *

def drawSudokuBoard(canvas, board, margin, canvasSize):
    canvas.create_text(canvasSize//2, canvasSize//2, 
        text="Implement drawSudokuBoard!", font="Arial 20 bold")

def drawStar(canvas, centerX, centerY, diameter, numPoints, color):
    canvas.create_text(centerX, centerY, text="Implement drawStar!", 
                                                    font="Arial 20 bold")

#################################################################
# hw2-2 tests
# Note: You must look at the output of these and confirm
# they work visually.
# Remember that you need to write your own test cases for the isLegalSudoku
# functions, as well as Kings Tour!
# You are not required to write tests for any helper functions
# you write for graphics problems
#################################################################

# add test functions here!

def runDrawStar(centerX, centerY, diameter, numPoints, color, 
                   winWidth=500, winHeight=500):
    root = Tk()
    canvas = Canvas(root, width=winWidth, height=winHeight)
    canvas.pack()

    drawStar(canvas, centerX, centerY, diameter, numPoints, color)

    root.mainloop()

def testDrawStar():
    print("Testing drawStar()...")
    print("Since this is graphics, this test is not interactive.")
    print("Inspect each of these results manually to verify them.")
    runDrawStar(250, 250, 500, 5, "gold")
    runDrawStar(300, 400, 100, 4, "blue")
    runDrawStar(300, 200, 300, 9, "red")
    print("Done!")

def getBoard0():
    return [
      [ 1, 2, 3, 4, 5, 6, 7, 8, 9],
      [ 5, 0, 8, 1, 3, 9, 6, 2, 4],
      [ 4, 9, 6, 8, 7, 2, 1, 5, 3],
      [ 9, 5, 2, 3, 8, 1, 4, 6, 7],
      [ 6, 4, 1, 2, 9, 7, 8, 3, 5],
      [ 3, 8, 7, 5, 6, 4, 0, 9, 1],
      [ 7, 1, 9, 6, 2, 3, 5, 4, 8],
      [ 8, 6, 4, 9, 1, 5, 3, 7, 2],
      [ 2, 3, 5, 7, 4, 8, 9, 1, 6]
    ]

def getBoard1():
    return [
        [1,2,3,4],
        [3,4,5,6],
        [7,8,9,10],
        [11,12,13,14]
    ]


def runSudoku(board, canvasSize=400):
    root = Tk()
    canvas = Canvas(root, width=canvasSize, height=canvasSize)
    canvas.pack()
    margin = 10
    drawSudokuBoard(canvas, board, margin, canvasSize)
    root.mainloop()

def testRunSudoku():
    print("Testing runSudoku()...")
    print("Since this is graphics, this test is not interactive.")
    print("Inspect each of these results manually to verify them.")
    runSudoku(getBoard0(), 400)
    runSudoku(getBoard1(), 500)
    print("Done!")

def testAll():
    # remember to call the extra test functions you write here!
    testDrawStar()
    testRunSudoku()
    # also remember to test out the bonus problem if you attempt it

def main():
    testAll()


if __name__ == '__main__':
    main()