-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinear_board.py
52 lines (39 loc) · 1.42 KB
/
linear_board.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
from list_utils import find_streak
from settings import BOARD_LENGTH, VICTORY_STRIKE
class LinearBoard():
# CLASE QUE REPRESENTA UN TABLERO DE U NA SOLA COLUMNA
# X UN JUGADOR
# O OTRO JUGADOR
# None UN ESPACIO VACIO
@classmethod
def fromList(cls, list):
board = cls()
board._column = list
return board
def __init__(self):
# UNA LISTA DE None
self._column =[None for i in range(BOARD_LENGTH)]
def __eq__(self, other):
if not isinstance(other, self.__class__):
return False
else:
return self._column == other._column
def __hash__(self):
return hash(self._column)
def __repr__(self):
return f'<{self.__class__}: {self._column}>'
def add(self, char):
# JUEGA EN LA PRIMERA POSICION DESIPONIBLE
#SIEMPRE Y CUANDO NO ESTE LLENO ......
if not self.is_full():
#BUSCAMOS LA PRIMERA POSISCION DISPONIBLE(None)
i = self._column.index(None)
#LO SUSTIUIMIOS POR CAHR
self._column[i] = char
def is_full(self):
return self._column[-1] != None
def is_victory(self, char):
return find_streak(self._column, char, VICTORY_STRIKE)
def is_tie(self, char1, char2):
# NO HAY VISTORIA NI CHAR1 NI DE CHAR2
return (self.is_victory('x') == False) and (self.is_victory('o') == False)