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 db5c612 + e67b65f commit 3b24af9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
20 changes: 20 additions & 0 deletions battlecode25/engine/game/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ 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 @@ -423,6 +432,16 @@ def mark_tower_pattern(self, team, center, tower_type):
'''
self.mark_pattern(team, center, self.shape_from_tower_type(tower_type))

def is_pattern_obstructed(self, center):
print("called this")
offset = GameConstants.PATTERN_SIZE//2
for dx in range(-offset, offset + 1):
for dy in range(-offset, offset + 1):
idx = (center.y + dy) * self.width + (center.x + dx)
if self.ruins[idx] or self.walls[idx]:
return True
return False

def simple_check_pattern(self, center, shape, team):
is_tower = not shape == Shape.RESOURCE
primary = self.get_primary_paint(team)
Expand Down Expand Up @@ -492,6 +511,7 @@ def create_methods(self, rc: RobotController):
'get_health': (rc.get_health, 1),
'get_paint': (rc.get_paint, 1),
'get_money': (rc.get_money, 1),
'get_chips': (rc.get_chips, 1),
'get_type': (rc.get_type, 1),
'get_num_towers': (rc.get_num_towers, 5),
'on_the_map': (rc.on_the_map, 5),
Expand Down
9 changes: 8 additions & 1 deletion battlecode25/engine/game/robot_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_tower_pattern(self, tower_type: UnitType) -> List[List[bool]]:
self.assert_is_tower_type(tower_type)
return self.game.pattern[self.game.shape_from_tower_type(tower_type).value]

def get_num_towers(self):
def get_num_towers(self) -> int:
return self.game.get_num_towers(self.robot.team)

# ROBOT QUERY FUNCTIONS
Expand All @@ -83,6 +83,9 @@ def get_health(self) -> int:

def get_money(self) -> int:
return self.game.team_info.get_coins(self.robot.team)

def get_chips(self) -> int:
return self.get_money()

def get_type(self) -> UnitType:
return self.robot.type
Expand Down Expand Up @@ -438,6 +441,8 @@ def assert_can_mark_tower_pattern(self, tower_type: UnitType, loc: MapLocation)

def assert_can_mark_resource_pattern(self, loc: MapLocation) -> None:
self.assert_can_mark_pattern(loc)
if self.game.is_pattern_obstructed(loc):
raise RobotError("Cannot mark resource pattern because there is a wall or ruin in the way.")

def can_mark_tower_pattern(self, tower_type: UnitType, loc: MapLocation) -> bool:
try:
Expand Down Expand Up @@ -511,6 +516,8 @@ 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:
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")
if self.game.get_num_towers(self.robot.team) >= GameConstants.MAX_NUMBER_OF_TOWERS:
Expand Down
10 changes: 5 additions & 5 deletions battlecode25/engine/game/unit_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ class RobotAttributes:

class UnitType(Enum):
# Define enum members with RobotAttributes dataclass
SOLDIER = RobotAttributes(200, 250, 5, 250, -1, 200, 10, 20, 20, -1, 0, 0)
SPLASHER = RobotAttributes(300, 400, 50, 150, -1, 300, 50, 9, -1, 50, 0, 0)
SOLDIER = RobotAttributes(200, 250, 5, 250, -1, 200, 10, 9, 20, -1, 0, 0)
SPLASHER = RobotAttributes(300, 400, 50, 150, -1, 300, 50, 8, -1, 50, 0, 0)
MOPPER = RobotAttributes(100, 300, 0, 50, -1, 100, 30, 2, -1, -1, 0, 0)

LEVEL_ONE_PAINT_TOWER = RobotAttributes(0, 25, 0, 1000, 1, 1000, 10, 9, 20, 10, 5, 0)
LEVEL_ONE_PAINT_TOWER = RobotAttributes(0, 100, 0, 1000, 1, 1000, 10, 9, 20, 10, 5, 0)
LEVEL_TWO_PAINT_TOWER = RobotAttributes(0, 250, 0, 1500, 2, 1000, 10, 9, 20, 10, 10, 0)
LEVEL_THREE_PAINT_TOWER = RobotAttributes(0, 500, 0, 2000, 3, 1000, 10, 9, 20, 10, 15, 0)

LEVEL_ONE_MONEY_TOWER = RobotAttributes(0, 25, 0, 1000, 1, 1000, 10, 9, 20, 10, 0, 10)
LEVEL_ONE_MONEY_TOWER = RobotAttributes(0, 100, 0, 1000, 1, 1000, 10, 9, 20, 10, 0, 10)
LEVEL_TWO_MONEY_TOWER = RobotAttributes(0, 250, 0, 1500, 2, 1000, 10, 9, 20, 10, 0, 15)
LEVEL_THREE_MONEY_TOWER = RobotAttributes(0, 500, 0, 2000, 3, 1000, 10, 9, 20, 10, 0, 20)

LEVEL_ONE_DEFENSE_TOWER = RobotAttributes(0, 25, 0, 2500, 1, 1000, 10, 20, 60, 30, 0, 0)
LEVEL_ONE_DEFENSE_TOWER = RobotAttributes(0, 100, 0, 2500, 1, 1000, 10, 20, 60, 30, 0, 0)
LEVEL_TWO_DEFENSE_TOWER = RobotAttributes(0, 250, 0, 3000, 2, 1000, 10, 20, 65, 35, 0, 0)
LEVEL_THREE_DEFENSE_TOWER = RobotAttributes(0, 500, 0, 3500, 3, 1000, 10, 20, 70, 40, 0, 0)

Expand Down
6 changes: 6 additions & 0 deletions battlecode25/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ def get_money() -> int:
"""
pass

def get_chips() -> int:
"""
Returns the amount of money that this robot's team has (equivalent to get_money())
"""
pass

def get_type() -> UnitType:
"""
Returns what type the robot is.
Expand Down

0 comments on commit 3b24af9

Please sign in to comment.