-
Notifications
You must be signed in to change notification settings - Fork 0
/
tictactoe modifier.py
151 lines (86 loc) · 3.75 KB
/
tictactoe modifier.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
print(' Attention pls!!! \n In this game, all keywords are to be enclosed in quotes \n \n \n the game keywords are as follows\n\n')
print(" First line keywords: '1a','1b','1c' \n Second line keywords: '2a','2b','2c' \n Third line keywords: '3a','3b','3c'\n\n")
# this is a tic tac toe game
# basic python project
'''check your keywords carefully before you play'''
# assigning players their choice of letter
player1 = 'x'
player2 = 'o'
rows = ['_','_','_']
second_row = ['_','_','_']
third_row =['_','_','_']
print(rows)
print(second_row)
print(third_row)
# Game keywords
first_denotions = ['1a','1b','1c']
second_denotions = ['2a','2b','2c']
third_denotions =['3a','3b','3c']
# players choose
player1_choose = []
player2_choose = []
# winner list
winning_denotions = [['1a','1b','1c'],['2a','2b','2c'],['3a','3b','3c'],
['1a','2b','3c'],['1c','2b','3a'],['1a','2a','3a'],
['1c','2c','3c']]
while True:
# first row functionality
var = input('Player1,where do you want to place your choose: ')
while var not in first_denotions and var not in second_denotions and var not in third_denotions:
print(var + ' is not a game keyword')
var = input('Player1,where do you want to place your choose: ')
if var in first_denotions:
rows.pop(first_denotions.index(var))
rows.insert(first_denotions.index(var),player1)
print(first_denotions.index(var))
# second row functionality
if var in second_denotions:
second_row.pop(second_denotions.index(var))
second_row.insert(second_denotions.index(var),player1)
print(second_denotions.index(var))
# Third row functionality
if var in third_denotions:
third_row.pop(third_denotions.index(var))
third_row.insert(third_denotions.index(var),player1)
print(third_denotions.index(var))
print(rows)
print(second_row)
print(third_row)
player1_choose.append(var)
if player1_choose in winning_denotions:
print('PLAYER1 wins')
break
elif player2_choose in winning_denotions:
print('PLAYER2 WINS')
break
# second player
var2 = input('Player2,where do you want to place your choose: ')
while var2 not in first_denotions and var2 not in second_denotions and var2 not in third_denotions:
print(var2 + ' is not a game keyword')
var2 = input('Player2,where do you want to place your choose: ')
# first row functionality
if var2 in first_denotions:
rows.pop(first_denotions.index(var2))
rows.insert(first_denotions.index(var2),player2)
print(first_denotions.index(var2))
# second row functionality
if var2 in second_denotions:
second_row.pop(second_denotions.index(var2))
second_row.insert(second_denotions.index(var2),player2)
print(second_denotions.index(var2))
# third row functionality
if var2 in third_denotions:
third_row.pop(third_denotions.index(var2))
third_row.insert(third_denotions.index(var2),player2)
print(third_denotions.index(var2))
print(rows)
print(second_row)
print(third_row)
player2_choose.append(var2)
if player1_choose in winning_denotions:
print('PLAYER1 wins')
break
elif player2_choose in winning_denotions:
print('PLAYER2 WINS')
break
print('THANKS FOR PLAYING')