-
Notifications
You must be signed in to change notification settings - Fork 0
/
deck.py
73 lines (55 loc) · 2 KB
/
deck.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
"""The professor game solver."""
import tiles
import copy
class Edge:
"""Class describing one edge of a tile."""
def __init__(self, color, bdyprt):
"""Initialize a edge of a tile. A tile has four edges."""
self.color = color
self.bdyprt = bdyprt
class Tile:
"""Class description of a single tile."""
def __init__(self, edges):
"""Create a tile with four edges."""
if len(edges) != tiles.EDGE_NUM:
raise ValueError('The number of tile edges is incorrect')
self._edges = copy.deepcopy(edges)
self._original_edges = self._edges
self._in_use = False
def get_edge(self, i):
"""Get a tile edge. Labelled clockwise from North."""
return self._edges[i]
def get_edges(self):
"""Return all edges."""
return self._edges
def rotate_cw(self):
"""Rotate card clockwise."""
if not self._in_use:
raise RuntimeError('Tile not in use shall not be rotated')
self._edges = [self._edges[-1]] + self._edges[0:-1]
def set_in_use(self):
"""Tile is used in board."""
self._in_use = True
def clr_in_use(self):
"""Return to original rotation."""
self._edges = self._original_edges
self._in_use = False
def get_in_use(self):
"""Check if given tile is placed."""
return self._in_use
class Deck:
"""Contains the entire 16 tile player deck."""
def __init__(self, init_deck):
"""Create a deck of tiles."""
if len(init_deck) != tiles.TILES_NUM:
raise ValueError('The number of tile in deck is incorrect')
self.tiles = []
for tile in range(len(init_deck)):
edges = []
for edge in range(len(init_deck[0])):
edges.append(Edge(init_deck[tile][edge][0],
init_deck[tile][edge][1]))
self.tiles.append(Tile(edges))
def get_tile(self, i):
"""Get a tile."""
return self.tiles[i]