Skip to content

Commit db5c612

Browse files
Merge branch 'main' into public-release
2 parents b826ec2 + dea7a0c commit db5c612

File tree

7 files changed

+44
-9
lines changed

7 files changed

+44
-9
lines changed

battlecode25/engine/game/game.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ def mark_location(self, team: Team, loc: MapLocation, secondary: bool):
113113
markers = self.team_a_markers if team == Team.A else self.team_b_markers
114114
markers[loc.y * self.width + loc.x] = 2 if secondary else 1
115115

116+
def get_num_towers(self, team: Team):
117+
return [robot.team == team and robot.type.is_tower_type() for robot in self.id_to_robot.values()].count(True)
118+
116119
def get_map_info(self, team, loc):
117120
idx = self.loc_to_index(loc)
118121
paint = self.paint[idx]
@@ -194,8 +197,8 @@ def set_winner_if_more_area(self):
194197
return True
195198

196199
def set_winner_if_more_allied_towers(self):
197-
towers_a = [robot.team == Team.A and robot.type.is_tower_type() for robot in self.id_to_robot.values()].count(True)
198-
towers_b = [robot.team == Team.B and robot.type.is_tower_type() for robot in self.id_to_robot.values()].count(True)
200+
towers_a = self.get_num_towers(Team.A)
201+
towers_b = self.get_num_towers(Team.B)
199202
if towers_a == towers_b:
200203
return False
201204
self.set_winner(Team.A if towers_a > towers_b else Team.B, DominationFactor.MORE_TOWERS_ALIVE)
@@ -490,6 +493,7 @@ def create_methods(self, rc: RobotController):
490493
'get_paint': (rc.get_paint, 1),
491494
'get_money': (rc.get_money, 1),
492495
'get_type': (rc.get_type, 1),
496+
'get_num_towers': (rc.get_num_towers, 5),
493497
'on_the_map': (rc.on_the_map, 5),
494498
'can_sense_location': (rc.can_sense_location, 5),
495499
'is_location_occupied': (rc.is_location_occupied, 5),
@@ -536,6 +540,7 @@ def create_methods(self, rc: RobotController):
536540
'can_upgrade_tower': (rc.can_upgrade_tower, 2),
537541
'upgrade_tower': rc.upgrade_tower,
538542
'resign': rc.resign,
543+
'disintegrate': rc.disintegrate,
539544
'set_indicator_string': rc.set_indicator_string,
540545
'set_indicator_dot': rc.set_indicator_dot,
541546
'set_indicator_line': rc.set_indicator_line,

battlecode25/engine/game/robot_controller.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ def get_tower_pattern(self, tower_type: UnitType) -> List[List[bool]]:
6161
self.assert_is_tower_type(tower_type)
6262
return self.game.pattern[self.game.shape_from_tower_type(tower_type).value]
6363

64+
def get_num_towers(self):
65+
return self.game.get_num_towers(self.robot.team)
66+
6467
# ROBOT QUERY FUNCTIONS
6568

6669
def get_id(self) -> int:
@@ -266,6 +269,10 @@ def assert_can_attack(self, loc: MapLocation) -> None:
266269
self.assert_can_act_location(loc, self.robot.type.action_radius_squared)
267270
if self.robot.paint < self.robot.type.attack_cost:
268271
raise RobotError("Insufficient paint to perform attack.")
272+
if self.game.has_wall(loc) and self.robot.type != UnitType.SPLASHER:
273+
raise RobotError("Cannot attack a wall.")
274+
if self.game.has_ruin(loc) and self.robot.type == UnitType.MOPPER:
275+
raise RobotError("Moppers cannot mop towers or ruins.")
269276
else:
270277
if loc is not None:
271278
self.assert_can_act_location(loc, self.robot.type.action_radius_squared)
@@ -283,9 +290,9 @@ def can_attack(self, loc: MapLocation) -> bool:
283290

284291
def attack(self, loc: MapLocation, use_secondary_color: bool=False) -> None:
285292
self.assert_can_attack(loc)
286-
self.robot.add_action_cooldown()
287293

288294
if self.robot.type == UnitType.SOLDIER:
295+
self.robot.add_action_cooldown()
289296
paint_type = (
290297
self.game.get_secondary_paint(self.robot.team)
291298
if use_secondary_color
@@ -302,6 +309,7 @@ def attack(self, loc: MapLocation, use_secondary_color: bool=False) -> None:
302309
self.game.set_paint(loc, paint_type)
303310

304311
elif self.robot.type == UnitType.SPLASHER:
312+
self.robot.add_action_cooldown()
305313
paint_type = (
306314
self.game.get_secondary_paint(self.robot.team)
307315
if use_secondary_color
@@ -324,6 +332,7 @@ def attack(self, loc: MapLocation, use_secondary_color: bool=False) -> None:
324332
self.game.game_fb.add_splash_action(loc)
325333

326334
elif self.robot.type == UnitType.MOPPER:
335+
self.robot.add_action_cooldown()
327336
if loc is None:
328337
self.mop_swing()
329338
else:
@@ -504,6 +513,8 @@ def assert_can_complete_tower_pattern(self, tower_type: UnitType, loc: MapLocati
504513
raise RobotError(f"Cannot complete tower pattern at ({loc.x}, {loc.y}) because there is a robot at the center of the ruin")
505514
if not self.game.simple_check_pattern(loc, self.game.shape_from_tower_type(tower_type), self.robot.team):
506515
raise RobotError(f"Cannot complete tower pattern at ({loc.x}, {loc.y}) because the paint pattern is wrong")
516+
if self.game.get_num_towers(self.robot.team) >= GameConstants.MAX_NUMBER_OF_TOWERS:
517+
raise RobotError(f"Cannot complete tower pattern at ({loc.x}, {loc.y}) because the maximum number of towers was reached.")
507518

508519
def can_complete_tower_pattern(self, tower_type: UnitType, loc: MapLocation) -> bool:
509520
try:
@@ -700,11 +711,15 @@ def set_indicator_string(self, string: str) -> None:
700711

701712
def set_indicator_dot(self, loc: MapLocation, red: int, green: int, blue: int) -> None:
702713
self.assert_not_none(loc)
714+
if not self.game.on_the_map(loc):
715+
raise RobotError("Cannot place an indicator dot outside the map.")
703716
self.game.game_fb.add_indicator_dot(loc, red, green, blue)
704717

705718
def set_indicator_line(self, start_loc: MapLocation, end_loc: MapLocation, red: int, green: int, blue: int) -> None:
706719
self.assert_not_none(start_loc)
707720
self.assert_not_none(end_loc)
721+
if not self.game.on_the_map(start_loc) or not self.game.on_the_map(end_loc):
722+
raise RobotError("Cannot place indicator line outside the map.")
708723
self.game.game_fb.add_indicator_line(start_loc, end_loc, red, green, blue)
709724

710725
def set_timeline_marker(self, label: str, red: int, green: int, blue: int) -> None:
@@ -714,7 +729,10 @@ def set_timeline_marker(self, label: str, red: int, green: int, blue: int) -> No
714729

715730
def resign(self) -> None:
716731
self.game.set_winner(self.robot.team.opponent(), DominationFactor.RESIGNATION)
717-
732+
733+
def disintegrate(self) -> None:
734+
self.game.destroy_robot(self.robot.id)
735+
718736
class RobotError(Exception):
719737
"""Raised for illegal robot inputs"""
720738
pass
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

battlecode25/stubs.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ def get_tower_pattern(tower_type: UnitType) -> List[List[bool]]:
4949
"""
5050
pass
5151

52+
def get_num_towers(self) -> int:
53+
"""
54+
Returns the current number of allied towers on the map.
55+
"""
56+
pass
57+
5258
# ROBOT QUERY FUNCTIONS
5359

5460
def get_id() -> int:
@@ -232,8 +238,8 @@ def move(direction: Direction) -> None:
232238

233239
def can_attack(loc: MapLocation) -> bool:
234240
"""
235-
Tests whether this robot can attack the given location. Types of attacks for specific units determine whether
236-
or not towers, other robots, or empty tiles can be attacked.
241+
Tests whether this robot can attack the given location. In most cases, if you are close enough, you can attack a location.
242+
Units excluding splashers are not allowed to attack walls, and moppers are not allowed to mop towers or ruins.
237243
"""
238244
pass
239245

@@ -378,8 +384,8 @@ def read_messages(round=-1) -> List[Message]:
378384
def can_transfer_paint(target_location: MapLocation, amount: int) -> bool:
379385
"""
380386
Tests whether you can transfer paint to a given robot/tower. You can give paint to an allied robot if you are a mopper
381-
and can act at the given location. You can give/take paint from allied towers regardless of type, if you can act at the
382-
location.
387+
and can act at the given location. You can take paint from allied towers regardless of type if you can act at the
388+
location. Pass a positive amount to give paint to another robot, and pass a negative amount to take paint.
383389
"""
384390
pass
385391

@@ -436,3 +442,9 @@ def resign() -> None:
436442
Causes your team to lose the game. It's like typing "gg."
437443
"""
438444
pass
445+
446+
def disintegrate() -> None:
447+
"""
448+
Destroys this robot.
449+
"""
450+
pass

run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
out_dir="matches",
2626
out_name=None,
2727
show_indicators=True,
28-
debug=False,
28+
debug=True,
2929
instrument=True
3030
)
3131

0 commit comments

Comments
 (0)