-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilder.py
48 lines (42 loc) · 1.8 KB
/
builder.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 Builder:
# affiliation -> 0 should be for human, 1 should be for AI in general
def __init__(self, affiliation, coordinates, board_state, id):
self.affiliation = affiliation
self.id = id
self.previous_value_of_cell = 0
self.coordinates = coordinates
board_state[coordinates[0]][coordinates[1]] = id
def __str__(self):
return f"{self.affiliation}"
# move to new coordinates and return the value of old cell on board
def move_to(self, new_coordinates, board_object):
"""
:param new_coordinates: Coordinates to which builder is being moved
:param board_object: Board object
:return: None
"""
board_state = board_object.board_state
board_state[self.coordinates[0]][self.coordinates[1]] = self.previous_value_of_cell
self.coordinates = new_coordinates
self.previous_value_of_cell = board_state[self.coordinates[0]][self.coordinates[1]]
board_state[self.coordinates[0]][self.coordinates[1]] = self.id
if self.previous_value_of_cell == 3:
board_object.game_over = True
def __build(self, build_coords, board_object):
"""
:param build_coords: Coordinates on which builder is building
:param board_object: Board object
:return: None
"""
x = build_coords[0]
y = build_coords[1]
board_object.board_state[x][y] += 1
def move_and_build(self, move_coords, build_coords, board_object):
"""
:param move_coords: Coordinates to which builder is being moved
:param build_coords: Coordinates on which builder is building
:param board_object: Board object
:return:
"""
self.move_to(move_coords, board_object)
self.__build(build_coords, board_object)