Skip to content

Commit 3b24af9

Browse files
Merge branch 'main' into public-release
2 parents db5c612 + e67b65f commit 3b24af9

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

battlecode25/engine/game/game.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,15 @@ 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
350359

351360
def set_paint(self, loc, paint, write_fb=True):
352361
idx = self.loc_to_index(loc)
@@ -423,6 +432,16 @@ def mark_tower_pattern(self, team, center, tower_type):
423432
'''
424433
self.mark_pattern(team, center, self.shape_from_tower_type(tower_type))
425434

435+
def is_pattern_obstructed(self, center):
436+
print("called this")
437+
offset = GameConstants.PATTERN_SIZE//2
438+
for dx in range(-offset, offset + 1):
439+
for dy in range(-offset, offset + 1):
440+
idx = (center.y + dy) * self.width + (center.x + dx)
441+
if self.ruins[idx] or self.walls[idx]:
442+
return True
443+
return False
444+
426445
def simple_check_pattern(self, center, shape, team):
427446
is_tower = not shape == Shape.RESOURCE
428447
primary = self.get_primary_paint(team)
@@ -492,6 +511,7 @@ def create_methods(self, rc: RobotController):
492511
'get_health': (rc.get_health, 1),
493512
'get_paint': (rc.get_paint, 1),
494513
'get_money': (rc.get_money, 1),
514+
'get_chips': (rc.get_chips, 1),
495515
'get_type': (rc.get_type, 1),
496516
'get_num_towers': (rc.get_num_towers, 5),
497517
'on_the_map': (rc.on_the_map, 5),

battlecode25/engine/game/robot_controller.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ 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):
64+
def get_num_towers(self) -> int:
6565
return self.game.get_num_towers(self.robot.team)
6666

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

8484
def get_money(self) -> int:
8585
return self.game.team_info.get_coins(self.robot.team)
86+
87+
def get_chips(self) -> int:
88+
return self.get_money()
8689

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

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

442447
def can_mark_tower_pattern(self, tower_type: UnitType, loc: MapLocation) -> bool:
443448
try:
@@ -511,6 +516,8 @@ def assert_can_complete_tower_pattern(self, tower_type: UnitType, loc: MapLocati
511516
raise RobotError(f"Cannot complete tower pattern at ({loc.x}, {loc.y}) because it is too close to the edge of the map")
512517
if self.game.get_robot(loc) is not None:
513518
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:
520+
raise RobotError(f"Cannot complete tower pattern at ({loc.x}, {loc.y}) because the team does not have enough money.")
514521
if not self.game.simple_check_pattern(loc, self.game.shape_from_tower_type(tower_type), self.robot.team):
515522
raise RobotError(f"Cannot complete tower pattern at ({loc.x}, {loc.y}) because the paint pattern is wrong")
516523
if self.game.get_num_towers(self.robot.team) >= GameConstants.MAX_NUMBER_OF_TOWERS:

battlecode25/engine/game/unit_type.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ class RobotAttributes:
1919

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

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

30-
LEVEL_ONE_MONEY_TOWER = RobotAttributes(0, 25, 0, 1000, 1, 1000, 10, 9, 20, 10, 0, 10)
30+
LEVEL_ONE_MONEY_TOWER = RobotAttributes(0, 100, 0, 1000, 1, 1000, 10, 9, 20, 10, 0, 10)
3131
LEVEL_TWO_MONEY_TOWER = RobotAttributes(0, 250, 0, 1500, 2, 1000, 10, 9, 20, 10, 0, 15)
3232
LEVEL_THREE_MONEY_TOWER = RobotAttributes(0, 500, 0, 2000, 3, 1000, 10, 9, 20, 10, 0, 20)
3333

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

battlecode25/stubs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ def get_money() -> int:
9393
"""
9494
pass
9595

96+
def get_chips() -> int:
97+
"""
98+
Returns the amount of money that this robot's team has (equivalent to get_money())
99+
"""
100+
pass
101+
96102
def get_type() -> UnitType:
97103
"""
98104
Returns what type the robot is.

0 commit comments

Comments
 (0)