Skip to content

Commit 8669d8c

Browse files
Merge branch 'main' into public-release
2 parents ab434ca + 7091642 commit 8669d8c

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

battlecode25/engine/game/game.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,6 @@ def shape_from_tower_type(self, tower_type):
347347
if tower_type in {UnitType.LEVEL_ONE_MONEY_TOWER, UnitType.LEVEL_TWO_MONEY_TOWER, UnitType.LEVEL_THREE_MONEY_TOWER}:
348348
return Shape.MONEY_TOWER
349349
return None
350-
351-
def level_one_from_tower_type(self, tower_type):
352-
if tower_type in {UnitType.LEVEL_ONE_PAINT_TOWER, UnitType.LEVEL_TWO_PAINT_TOWER, UnitType.LEVEL_THREE_PAINT_TOWER}:
353-
return UnitType.LEVEL_ONE_PAINT_TOWER
354-
if tower_type in {UnitType.LEVEL_ONE_DEFENSE_TOWER, UnitType.LEVEL_TWO_DEFENSE_TOWER, UnitType.LEVEL_THREE_DEFENSE_TOWER}:
355-
return UnitType.LEVEL_ONE_DEFENSE_TOWER
356-
if tower_type in {UnitType.LEVEL_ONE_MONEY_TOWER, UnitType.LEVEL_TWO_MONEY_TOWER, UnitType.LEVEL_THREE_MONEY_TOWER}:
357-
return UnitType.LEVEL_ONE_MONEY_TOWER
358-
return None
359350

360351
def set_paint(self, loc, paint, write_fb=True):
361352
idx = self.loc_to_index(loc)
@@ -552,6 +543,7 @@ def create_methods(self, rc: RobotController):
552543
'attack': rc.attack,
553544
'can_mop_swing': (rc.can_mop_swing, 10),
554545
'mop_swing': rc.mop_swing,
546+
'can_paint': (rc.can_paint, 10),
555547
'can_send_message': (rc.can_send_message, 50),
556548
'send_message': (rc.send_message, 50),
557549
'read_messages': (rc.read_messages, 10),

battlecode25/engine/game/paint_type.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ def is_ally(self):
1111
return self in {PaintType.ALLY_PRIMARY, PaintType.ALLY_SECONDARY}
1212

1313
def is_secondary(self):
14-
return self in {PaintType.ALLY_SECONDARY, PaintType.ENEMY_SECONDARY}
14+
return self in {PaintType.ALLY_SECONDARY, PaintType.ENEMY_SECONDARY}
15+
16+
def is_enemy(self):
17+
return self in {PaintType.ENEMY_PRIMARY, PaintType.ENEMY_SECONDARY}

battlecode25/engine/game/robot_controller.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,21 @@ def mop_swing(self, dir: Direction) -> None:
420420
target_ids.append(0)
421421
self.game.game_fb.add_mop_action(target_ids[0], target_ids[1], target_ids[2])
422422

423+
def can_paint(self, loc: MapLocation) -> bool:
424+
self.assert_not_none(loc)
425+
if not self.game.on_the_map(loc):
426+
return False
427+
if self.robot.type.is_tower_type() or self.robot.type == UnitType.MOPPER:
428+
return False
429+
if self.robot.type == UnitType.SOLDIER:
430+
if loc.distance_squared_to(self.robot.loc) > UnitType.SOLDIER.action_radius_squared:
431+
return False
432+
return self.game.is_passable(loc) and self.game.team_from_paint(self.game.get_paint_num(loc)) != self.robot.team.opponent()
433+
else:
434+
if loc.distance_squared_to(self.robot.loc) > UnitType.SPLASHER.action_radius_squared:
435+
return False
436+
return self.game.is_passable(loc)
437+
423438
# MARKING FUNCTIONS
424439

425440
def assert_can_mark_pattern(self, loc: MapLocation) -> None:
@@ -516,7 +531,7 @@ def assert_can_complete_tower_pattern(self, tower_type: UnitType, loc: MapLocati
516531
raise RobotError(f"Cannot complete tower pattern at ({loc.x}, {loc.y}) because it is too close to the edge of the map")
517532
if self.game.get_robot(loc) is not None:
518533
raise RobotError(f"Cannot complete tower pattern at ({loc.x}, {loc.y}) because there is a robot at the center of the ruin")
519-
if self.game.team_info.get_coins(self.robot.team) < self.game.level_one_from_tower_type(tower_type).money_cost:
534+
if self.game.team_info.get_coins(self.robot.team) < tower_type.get_base_type().money_cost:
520535
raise RobotError(f"Cannot complete tower pattern at ({loc.x}, {loc.y}) because the team does not have enough money.")
521536
if not self.game.simple_check_pattern(loc, self.game.shape_from_tower_type(tower_type), self.robot.team):
522537
raise RobotError(f"Cannot complete tower pattern at ({loc.x}, {loc.y}) because the paint pattern is wrong")

battlecode25/engine/game/unit_type.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,13 @@ def get_next_level(self):
110110
elif self == UnitType.LEVEL_ONE_DEFENSE_TOWER:
111111
return UnitType.LEVEL_TWO_DEFENSE_TOWER
112112
elif self == UnitType.LEVEL_TWO_DEFENSE_TOWER:
113-
return UnitType.LEVEL_THREE_DEFENSE_TOWER
113+
return UnitType.LEVEL_THREE_DEFENSE_TOWER
114+
115+
def get_base_type(self) -> 'UnitType':
116+
if self in {UnitType.LEVEL_TWO_PAINT_TOWER, UnitType.LEVEL_THREE_PAINT_TOWER}:
117+
return UnitType.LEVEL_ONE_PAINT_TOWER
118+
if self in {UnitType.LEVEL_TWO_DEFENSE_TOWER, UnitType.LEVEL_THREE_DEFENSE_TOWER}:
119+
return UnitType.LEVEL_ONE_DEFENSE_TOWER
120+
if self in {UnitType.LEVEL_TWO_MONEY_TOWER, UnitType.LEVEL_THREE_MONEY_TOWER}:
121+
return UnitType.LEVEL_ONE_MONEY_TOWER
122+
return self

battlecode25/stubs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ def mop_swing(dir: Direction) -> None:
267267
"""
268268
pass
269269

270+
def can_paint(loc: MapLocation) -> bool:
271+
"""
272+
Checks whether an attack will be able to paint a tile according to the robot type and current paint on the tile
273+
"""
274+
pass
275+
270276
# MARKING FUNCTIONS
271277

272278
def can_mark_tower_pattern(tower_type: UnitType, loc: MapLocation) -> bool:

0 commit comments

Comments
 (0)