Skip to content

Commit

Permalink
Merge branch 'main' into public-release
Browse files Browse the repository at this point in the history
  • Loading branch information
TheApplePieGod committed Jan 8, 2025
2 parents ab434ca + 7091642 commit 8669d8c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
10 changes: 1 addition & 9 deletions battlecode25/engine/game/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,6 @@ def shape_from_tower_type(self, tower_type):
if tower_type in {UnitType.LEVEL_ONE_MONEY_TOWER, UnitType.LEVEL_TWO_MONEY_TOWER, UnitType.LEVEL_THREE_MONEY_TOWER}:
return Shape.MONEY_TOWER
return None

def level_one_from_tower_type(self, tower_type):
if tower_type in {UnitType.LEVEL_ONE_PAINT_TOWER, UnitType.LEVEL_TWO_PAINT_TOWER, UnitType.LEVEL_THREE_PAINT_TOWER}:
return UnitType.LEVEL_ONE_PAINT_TOWER
if tower_type in {UnitType.LEVEL_ONE_DEFENSE_TOWER, UnitType.LEVEL_TWO_DEFENSE_TOWER, UnitType.LEVEL_THREE_DEFENSE_TOWER}:
return UnitType.LEVEL_ONE_DEFENSE_TOWER
if tower_type in {UnitType.LEVEL_ONE_MONEY_TOWER, UnitType.LEVEL_TWO_MONEY_TOWER, UnitType.LEVEL_THREE_MONEY_TOWER}:
return UnitType.LEVEL_ONE_MONEY_TOWER
return None

def set_paint(self, loc, paint, write_fb=True):
idx = self.loc_to_index(loc)
Expand Down Expand Up @@ -552,6 +543,7 @@ def create_methods(self, rc: RobotController):
'attack': rc.attack,
'can_mop_swing': (rc.can_mop_swing, 10),
'mop_swing': rc.mop_swing,
'can_paint': (rc.can_paint, 10),
'can_send_message': (rc.can_send_message, 50),
'send_message': (rc.send_message, 50),
'read_messages': (rc.read_messages, 10),
Expand Down
5 changes: 4 additions & 1 deletion battlecode25/engine/game/paint_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ def is_ally(self):
return self in {PaintType.ALLY_PRIMARY, PaintType.ALLY_SECONDARY}

def is_secondary(self):
return self in {PaintType.ALLY_SECONDARY, PaintType.ENEMY_SECONDARY}
return self in {PaintType.ALLY_SECONDARY, PaintType.ENEMY_SECONDARY}

def is_enemy(self):
return self in {PaintType.ENEMY_PRIMARY, PaintType.ENEMY_SECONDARY}
17 changes: 16 additions & 1 deletion battlecode25/engine/game/robot_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,21 @@ def mop_swing(self, dir: Direction) -> None:
target_ids.append(0)
self.game.game_fb.add_mop_action(target_ids[0], target_ids[1], target_ids[2])

def can_paint(self, loc: MapLocation) -> bool:
self.assert_not_none(loc)
if not self.game.on_the_map(loc):
return False
if self.robot.type.is_tower_type() or self.robot.type == UnitType.MOPPER:
return False
if self.robot.type == UnitType.SOLDIER:
if loc.distance_squared_to(self.robot.loc) > UnitType.SOLDIER.action_radius_squared:
return False
return self.game.is_passable(loc) and self.game.team_from_paint(self.game.get_paint_num(loc)) != self.robot.team.opponent()
else:
if loc.distance_squared_to(self.robot.loc) > UnitType.SPLASHER.action_radius_squared:
return False
return self.game.is_passable(loc)

# MARKING FUNCTIONS

def assert_can_mark_pattern(self, loc: MapLocation) -> None:
Expand Down Expand Up @@ -516,7 +531,7 @@ def assert_can_complete_tower_pattern(self, tower_type: UnitType, loc: MapLocati
raise RobotError(f"Cannot complete tower pattern at ({loc.x}, {loc.y}) because it is too close to the edge of the map")
if self.game.get_robot(loc) is not None:
raise RobotError(f"Cannot complete tower pattern at ({loc.x}, {loc.y}) because there is a robot at the center of the ruin")
if self.game.team_info.get_coins(self.robot.team) < self.game.level_one_from_tower_type(tower_type).money_cost:
if self.game.team_info.get_coins(self.robot.team) < tower_type.get_base_type().money_cost:
raise RobotError(f"Cannot complete tower pattern at ({loc.x}, {loc.y}) because the team does not have enough money.")
if not self.game.simple_check_pattern(loc, self.game.shape_from_tower_type(tower_type), self.robot.team):
raise RobotError(f"Cannot complete tower pattern at ({loc.x}, {loc.y}) because the paint pattern is wrong")
Expand Down
11 changes: 10 additions & 1 deletion battlecode25/engine/game/unit_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,13 @@ def get_next_level(self):
elif self == UnitType.LEVEL_ONE_DEFENSE_TOWER:
return UnitType.LEVEL_TWO_DEFENSE_TOWER
elif self == UnitType.LEVEL_TWO_DEFENSE_TOWER:
return UnitType.LEVEL_THREE_DEFENSE_TOWER
return UnitType.LEVEL_THREE_DEFENSE_TOWER

def get_base_type(self) -> 'UnitType':
if self in {UnitType.LEVEL_TWO_PAINT_TOWER, UnitType.LEVEL_THREE_PAINT_TOWER}:
return UnitType.LEVEL_ONE_PAINT_TOWER
if self in {UnitType.LEVEL_TWO_DEFENSE_TOWER, UnitType.LEVEL_THREE_DEFENSE_TOWER}:
return UnitType.LEVEL_ONE_DEFENSE_TOWER
if self in {UnitType.LEVEL_TWO_MONEY_TOWER, UnitType.LEVEL_THREE_MONEY_TOWER}:
return UnitType.LEVEL_ONE_MONEY_TOWER
return self
6 changes: 6 additions & 0 deletions battlecode25/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ def mop_swing(dir: Direction) -> None:
"""
pass

def can_paint(loc: MapLocation) -> bool:
"""
Checks whether an attack will be able to paint a tile according to the robot type and current paint on the tile
"""
pass

# MARKING FUNCTIONS

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

0 comments on commit 8669d8c

Please sign in to comment.