forked from ArNayyeri/SearchProject_SortIt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPipe.py
48 lines (40 loc) · 1.21 KB
/
Pipe.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
class Pipe:
def __init__(self, stack: list, limit: int):
self.stack = stack
self.limit = limit
def is_one_color(self) -> bool: # this function checks that all balls are the same color
for i in range(1, len(self.stack)):
if self.stack[i] != self.stack[i - 1]:
return False
return True
def add_ball(self, color):
self.stack.append(color)
def remove_ball(self):
return self.stack.pop()
def is_full(self):
if len(self.stack) == self.limit:
return True
return False
def is_empty(self):
if len(self.stack) == 0:
return True
return False
def print_pipe(self):
print('{', end=' ')
for i in self.stack:
print(i, end=' ')
print('}')
def get_pipe_for_gui(self):
# p1=RGB,p2=RBR,p3=GBR,p4=GGG,p5=E,p6=E,p7=E,p8=E
out = ""
if len(self.stack) == 0:
out += 'E'
return out
for i in self.stack:
out += (str(i[0]).upper())
return out
def __hash__(self):
hash_string = ''
for i in self.stack:
hash_string += str(i)
return hash_string