-
Notifications
You must be signed in to change notification settings - Fork 1
/
two-thirds-win-state.py
74 lines (66 loc) · 1.44 KB
/
two-thirds-win-state.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#Global Variables
Row1 = ['-','-','-']
Row2 = ['-','-','-']
Row3 = ['-','-','-']
Board = [Row3,Row2,Row1]
Coloum = []
Xwin = ['X','X','X']
Ywin = ['X','X','X']
win = False
turnnum = 0
#Prints current board state
def printboard():
for rows in range(len(Board)):
print(Board[rows])
#Promted player input for human turn
def playerturn():
global turnnum
plrinput = input('\"X\" input position (1-9): ')
intinput = int(plrinput)
#Sets input to board space
if intinput>9:
print('Please choose a valid number.')
elif intinput<1:
print('Please choose a valid number.')
elif intinput < 7:
turnnum = turnnum+1
if intinput >3:
Row2[intinput-4] = 'X'
else:
Row1[intinput-1] = 'X'
else:
turnnum=turnnum+1
Row3[intinput - 7] = 'X'
#Checks game for win state
def winstate():
coloum = 0
global win
for row in Board:
if row == Xwin:
win = True
print('X wins!')
elif row == Ywin:
win = True
print('Y wins!')
while coloum<3:
Coloum.append(Row1[coloum])
Coloum.append(Row2[coloum])
Coloum.append(Row3[coloum])
if Coloum == Xwin:
win = True
print('X wins!')
elif Coloum == Ywin:
win = True
print('Y wins!')
Coloum.clear()
coloum = coloum + 1
#Plays game while not in win state
def boardplaystate():
global turnnum
global win
while win == False:
playerturn()
printboard()
winstate()
printboard()
boardplaystate()