#Tic-Tac-Toe #Noam Stanislawski import turtle, sys t = turtle.Turtle() wn = turtle.Screen() def setup(): ######################## #####START BOARD######## ######################## t.speed(0) t.hideturtle() t.up() t.pensize(5) t.goto(-100,250) #still facing right t.right(90) #facing down t.down() t.fd(400) #length of t.up() t.goto(-115,130) t.write(1) t.goto(40,130) t.write(2) t.goto(60,130) t.write(3) t.goto(-115,-20) t.write(4) t.goto(40,-20) t.write(5) t.goto(60,-20) t.write(6) t.goto(-115,-150) t.write(7) t.goto(40,-150) t.write(8) t.goto(60,-150) t.write(9) #Done with number asssignment t.goto(-200,125) t.left(90) t.down() #exterminate jewcity jewcify jewciness = yes t.fd(350) t.up() t.goto(50,250) t.right(90) #facing down t.down() t.fd(400) t.up() t.goto(-200,-25) t.left(90) t.down() t.fd(350) ######################## #####COMPLETE BOARD##### ######################## class draw: def Xs(x,y,turt): #turt.speed(2) turt.color('blue') turt.up() turt.goto(x,y) turt.seth(120) #will start at bottom right of x turt.down() turt.fd(100) turt.up() turt.goto(x-40,y) turt.seth(70) turt.down() turt.fd(100) def Os(x,y,turt): #turt.speed(2) turt.color('violet') turt.up() turt.goto(x + 20,y + 10) turt.down() turt.circle(55) def begin(): turn = 0 movelist = ['_','_','_','_','_','_','_','_','_'] while checkwin(movelist) == False: if turn == 9: print('exiting') wn.exitonclick sys.exit() move = int(input('Which space do you want to go in?(Give a number)')) if move == 1: t.up() if turn % 2 == 0: draw.Xs(-140,160,t) turn += 1 movelist[move-1] = 1 continue elif turn % 2 == 1: draw.Os(-140,160,t) turn += 1 movelist[move-1] = 0 continue elif move == 2: t.up() if turn % 2 == 0: draw.Xs(0,160,t) turn += 1 movelist[move-1] = 1 continue if turn % 2 == 1: draw.Os(0,160,t) turn += 1 movelist[move-1] = 0 continue elif move == 3: t.up() if turn % 2 == 0: draw.Xs(130,160,t) turn += 1 movelist[move-1] = 1 continue elif turn % 2 == 1: draw.Os(130,160,t) turn += 1 movelist[move-1] = 0 continue elif move == 4: t.up() if turn % 2 == 0: draw.Xs(-140,5,t) turn += 1 movelist[move-1] = 1 continue elif turn % 2 == 1: draw.Os(-140,5,t) turn += 1 movelist[move-1] = 0 continue elif move == 5: t.up() if turn % 2 == 0: draw.Xs(0,8,t) turn += 1 movelist[move-1] = 1 continue elif turn % 2 == 1: draw.Os(0,8,t) turn += 1 movelist[move-1] = 0 continue elif move == 6: # t.up() if turn % 2 == 0: draw.Xs(140,8,t) turn += 1 movelist[move-1] = 1 continue elif turn % 2 == 1: draw.Os(140,8,t) turn += 1 movelist[move-1] = 0 continue elif move == 7: t.up() if turn % 2 == 0: draw.Xs(-140,-140,t) turn += 1 movelist[move-1] = 1 continue elif turn % 2 == 1: draw.Os(-140,-140,t) turn += 1 movelist[move-1] = 0 continue elif move == 8: t.up() if turn % 2 == 0: draw.Xs(0,-140,t) turn += 1 movelist[move-1] = 1 continue elif turn % 2 == 1: draw.Os(0,-140,t) turn += 1 movelist[move-1] = 0 continue elif move == 9: t.up() if turn % 2 == 0: draw.Xs(140,-140,t) turn += 1 movelist[move-1] = 1 continue elif turn % 2 == 1: draw.Os(140,-140,t) turn += 1 movelist[move-1] = 0 continue if checkwin(movelist) == True: if movelist.count(1) > movelist.count('_') and movelist.count(1) > movelist.count(0): print("3 X in a row!") sys.exit wn.exitonclick() elif movelist.count(0) > movelist.count(1) and movelist.count(0) > movelist.count('_'): print("3 Os in a row!") sys.exit wn.exitonclick() def checkwin(lst): for i in range(6): if lst[i] != '_': if lst[i] == lst[i+1] and lst[i] == lst[i+2]: return True elif lst[i] == lst[i+3] and lst[i] == lst[i+6]: return True elif lst[6] == lst[7] and lst[6] == lst[8]: return True return False def run(): setup() begin() run()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question