-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grid.py
88 lines (76 loc) · 3.15 KB
/
Grid.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
#Grid
#Authors Mario Carricato & Marco Amato
import os
#positions
LEFT = 4
CENTER = 5
RIGHT = 6
UP = 8
DOWN = 2
UP_LEFT_CORNER = 7
UP_RIGHT_CORNER = 9
DOWN_LEFT_CORNER = 1
DOWN_RIGHT_CORNER = 3
class Grid:
def __init__(self):
self.list = ["", str(DOWN_LEFT_CORNER), str(DOWN), str(DOWN_RIGHT_CORNER), str(LEFT), str(CENTER), str(RIGHT), str(UP_LEFT_CORNER), str(UP), str(UP_RIGHT_CORNER)]
def print_grid(self):
print (" | | ")
print (" " + self.list[UP_LEFT_CORNER] + " | " + self.list[UP] + " | " + self.list[UP_RIGHT_CORNER] + " ")
print (" | | ")
print ("-----------")
print (" | | ")
print (" " + self.list[LEFT] + " | " + self.list[CENTER] + " | " + self.list[RIGHT] + " ")
print (" | | ")
print ("-----------")
print (" | | ")
print (" " + self.list[DOWN_LEFT_CORNER] + " | " + self.list[DOWN] + " | " + self.list[DOWN_RIGHT_CORNER] + " ")
print (" | | ")
def draw_grid(self, list):
if len(list)>0:
print (" | | ")
print (" " + list[UP_LEFT_CORNER] + " | " + list[UP] + " | " + list[UP_RIGHT_CORNER] + " ")
print (" | | ")
print ("-----------")
print (" | | ")
print (" " + list[LEFT] + " | " + list[CENTER] + " | " + list[RIGHT] + " ")
print (" | | ")
print ("-----------")
print (" | | ")
print (" " + list[DOWN_LEFT_CORNER] + " | " + list[DOWN] + " | " + list[DOWN_RIGHT_CORNER] + " ")
print (" | | ")
return True
else:
False
def is_winner_player(self, type):
if self.list[DOWN_LEFT_CORNER] == type and self.list[DOWN] == type and self.list[DOWN_RIGHT_CORNER] == type:
return True
elif self.list[LEFT] == type and self.list[CENTER] == type and self.list[RIGHT] == type:
return True
if self.list[UP_LEFT_CORNER] == type and self.list[UP] == type and self.list[UP_RIGHT_CORNER] == type:
return True
if self.list[DOWN_LEFT_CORNER] == type and self.list[LEFT] == type and self.list[UP_LEFT_CORNER] == type:
return True
if self.list[DOWN] == type and self.list[CENTER] == type and self.list[UP] == type:
return True
if self.list[DOWN_RIGHT_CORNER] == type and self.list[RIGHT] == type and self.list[UP_RIGHT_CORNER] == type:
return True
if self.list[DOWN_RIGHT_CORNER] == type and self.list[CENTER] == type and self.list[UP_LEFT_CORNER] == type:
return True
if self.list[DOWN_LEFT_CORNER] == type and self.list[CENTER] == type and self.list[UP_RIGHT_CORNER] == type:
return True
return False
def is_grid_full(self, run):
if run == 9:
self.get_snapschoot()
print ("\n")
print ("\033[31;1mResult:\033[0m Draw! ")
print ("\n")
return True
else:
return False
def get_grid(self):
return self.list
def get_snapschoot(self):
os.system("clear")
self.print_grid()