-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.py
54 lines (51 loc) · 1.45 KB
/
logic.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
## game logic
class Logic:
def __init__(self,player_name):
self.player=player_name
self.nums={
"00" : 0,
"01" : 1,
"02" : 2,
"10" : 3,
"11" : 4,
"12" : 5,
"20" : 6,
"21" : 7,
"22" : 8,
}
def check(self):
nums=self.nums
for i in range(3):
for j in range(3):
print(nums[f"{i}{j}"])
# row 0
if(nums["00"]==nums["01"]==nums["02"]):
return f"{self.player} Won!!"
# row 1
elif(nums["10"]==nums["11"]==nums["12"]):
return f"{self.player} Won!!"
# row 2
elif(nums["20"]==nums["21"]==nums["22"]):
return f"{self.player} Won!!"
# diagonal
elif(nums["00"]==nums["11"]==nums["22"]):
return f"{self.player} Won!!"
# diagonal
elif(nums["02"]==nums["11"]==nums["20"]):
return f"{self.player} Won!!"
# column 1
elif(nums["00"]==nums["11"]==nums["21"]):
return f"{self.player} Won!!"
# column 2
elif(nums["01"]==nums["11"]==nums["21"]):
return f"{self.player} Won!!"
# column 3
elif(nums["02"]==nums["12"]==nums["22"]):
return f"{self.player} Won!!"
## even more logic
##debugging
# ll=Logic("Shivansh")
# # ll.nums["00"]='x'
# # ll.nums["01"]='x'
# # ll.nums["02"]='x'
# print(ll.check())