-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_board.py
175 lines (134 loc) · 5.07 KB
/
test_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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
from utils.location import Location
from utils.board import Board
from utils.pieces.grass_hopper import Grasshopper
from utils.pieces.spider import Spider
from utils.pieces.ant import Ant
from utils.pieces.queen import Queen
from utils.pieces.beetle import Beetle
def test_hive_broken():
print("---------------------Testing Hive breaking move--------------------")
board = Board()
locations = [
Location(0, 0), Location(2, 0), Location(1, 1),
Location(2, 2), Location(0, 2)
]
for location in locations:
insect = Grasshopper(location, 0)
board.add_object(insect)
if board.check_if_hive_valid(locations[0], Location(3, 3)):
print("Hive is valid after move")
else:
print("Invalid move will break hive")
def test_ant_movement():
print("---------------------testing ant movement---------------------------")
board = Board()
locations = [
Location(0, 0), Location(2, 0), Location(1, 1),
Location(2, 2), Location(0, 2)
]
queen = Queen(locations[0], 0)
board.add_object(queen)
for location in locations[1:]:
namla = Ant(location, 0)
board.add_object(namla)
print(board.get_object(locations[-1]).get_next_possible_locations(board))
def test_beetle_movement():
print("---------------------testing beetle movement---------------------------")
board = Board()
locations = [
Location(0, 0), Location(2, 0), Location(1, 1),
Location(2, 2), Location(0, 2)
]
queen = Queen(locations[0], 0)
board.add_object(queen)
for location in locations[1:]:
beetle = Beetle(location, 0)
board.add_object(beetle)
print("Possible locations for beetle:")
print(board.get_object(locations[-1]).get_next_possible_locations(board))
# Example Usage
# try:
# board = Board()
# loc1 = Location(5, 10)
# grasshopper1 = Grasshopper(loc1)
# loc2 = Location(15, 20)
# grasshopper2 = Grasshopper(loc2)
# # Add game objects to the board
# board.add_object(grasshopper1)
# board.add_object(grasshopper2)
# print(board)
# # Move a game object
# board.move_object(grasshopper1.get_location(), Location(2,1))
# print("\nAfter moving grasshopper1:")
# print(board)
# # Remove a game object
# board.remove_object(grasshopper2.get_location())
# print("\nAfter removing grasshopper2:")
# print(board)
# except (ValueError, KeyError) as e:
# print(e)
# Sherif testing
def get_moves_and_deploys(board):
combined_results = []
if board.check_win_condition_bool():
print("Game Over: Winning Condition Met")
return combined_results
team_number = 0 if board.turn() else 1
print(f"Team {team_number}'s turn")
available_pieces = board._hands[team_number]
print("Available pieces in hand:", available_pieces)
deploy_locations = board.getPossibleDeployLocations(team_number)
flag=1
if (board._turn_number == 7 and team_number == 0) or (board._turn_number == 8 and team_number == 1):
if available_pieces.get(Queen, 0) > 0: # If Queen is still in hand
flag=0
combined_results.append(('Queen', deploy_locations))
print(f"Queen is in hand. Deploy locations: {deploy_locations}")
if(flag):
for piece_type, count in available_pieces.items():
if count > 0:
for _ in range(count):
combined_results.append((piece_type.__name__, deploy_locations))
print(f"Deploying {piece_type.__name__} at {deploy_locations}")
team_pieces = board.filter_team_pieces()
for piece in team_pieces:
start_location = piece.get_location()
possible_destinations = piece.get_next_possible_locations(board)
print(f"Possible destinations for {piece}: {possible_destinations}")
for destination in possible_destinations:
combined_results.append((start_location, destination))
print("(deploys and moves):", combined_results)
return combined_results
try:
#test_hive_broken()
# test_ant_movement()
# test_beetle_movement()
board = Board(lambda x: x)
loc1 = Location(0, 0)
queen1 = Queen(loc1, 0)
loc7 = Location(1, 1)
Queen2 = Queen(loc7, 1)
loc8 = Location(2, 0)
Ant1 = Ant(loc8, 0)
loc9 = Location(3, 1)
grasshopper = Grasshopper(loc9, 0)
# Ant2 = Ant(loc9, team=2)
# board.initiate_game()
# Add game objects to the board
board.add_object(queen1)
board.add_object(Queen2)
board.add_object(Ant1)
board.add_object(grasshopper)
print("Board:", board)
# print(Queen2.get_next_possible_locations(board))
# print(board.get_object(Location(2, 0)))
# print(board)
# deploy1 = board.getPossibleDeployLocations(2)
# print("deploy for team 1",deploy1)
# print(board)
# Check possible moves
#queen2.getPossibleMoves(board)
# queen1.getPossibleMoves(board)
print(get_moves_for_team(board))
except (ValueError, KeyError) as e:
print(e)