@@ -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+
718736class RobotError (Exception ):
719737 """Raised for illegal robot inputs"""
720738 pass
0 commit comments