diff --git a/battlecode25/engine/game/robot.py b/battlecode25/engine/game/robot.py index 87daff0..fcf6fa4 100644 --- a/battlecode25/engine/game/robot.py +++ b/battlecode25/engine/game/robot.py @@ -119,9 +119,9 @@ def process_end_of_turn(self): paint_penalty += 2 * len(adjacent_allies) self.add_paint(-paint_penalty) - if self.type.name == "TOWER": + if self.type.is_tower_type(): self.add_paint(self.type.paint_per_turn) - self.game.team_info.add_coins(self.type.money_per_turn) + self.game.team_info.add_coins(self.team, self.type.money_per_turn) self.has_tower_area_attacked = False self.has_tower_single_attacked = False diff --git a/battlecode25/engine/game/robot_controller.py b/battlecode25/engine/game/robot_controller.py index 7cb29f9..62332de 100644 --- a/battlecode25/engine/game/robot_controller.py +++ b/battlecode25/engine/game/robot_controller.py @@ -276,6 +276,7 @@ def assert_can_attack(self, loc: MapLocation) -> None: raise RobotError("Tower cannot use single tile attack more than once per turn.") def can_attack(self, loc: MapLocation) -> bool: + # self.assert_can_attack(loc) try: self.assert_can_attack(loc) return True diff --git a/players/davidbot/bot.py b/players/davidbot/bot.py new file mode 100644 index 0000000..9b8a3d7 --- /dev/null +++ b/players/davidbot/bot.py @@ -0,0 +1,65 @@ +import random + +from battlecode25.stubs import * + +# This is an example bot written by the developers! +# Use this to help write your own code, or run it against your bot to see how well you can do! + +directions = [ + Direction.NORTH, + Direction.EAST, + Direction.SOUTH, + Direction.WEST, + Direction.NORTHEAST, + Direction.NORTHWEST, + Direction.SOUTHEAST, + Direction.SOUTHWEST +] + +paint_towers = [UnitType.LEVEL_ONE_PAINT_TOWER, UnitType.LEVEL_TWO_PAINT_TOWER, UnitType.LEVEL_THREE_PAINT_TOWER] + +def turn(): + loc = get_location() + + if can_upgrade_tower(loc): + upgrade_tower(loc) + + if get_type().is_tower_type(): + spawn_loc = loc.add(directions[random.randint(0, 3)]) + if can_build_robot(UnitType.SPLASHER, spawn_loc): + build_robot(UnitType.SPLASHER, spawn_loc) + + danger = sense_nearby_robots() + # log("danger is") + # log([(r.get_location().x, r.get_location().y) for r in danger]) + # log() + for robot in danger: + if can_attack(robot.get_location()): + # log("BOOM") + attack(robot.get_location()) + + else: + dir = directions[random.randint(0, 3)] + if can_move(dir): + move(dir) + attack_loc = get_location().add(dir) + if can_attack(attack_loc): + attack(attack_loc) + + + + + + # loc = get_location() + # log("Location is") + # log(loc) + # for i in range(9, 14): + # for j in range(9, 14): + # log(can_sense_location(MapLocation(i, j))) + # # log(can_sense_location(MapLocation(-1, -2))) + # # log(can_sense_location(MapLocation(-1, 20))) + # # log(can_sense_location(MapLocation(15, -2))) + # # log(can_sense_location(MapLocation(35, 35))) + # # log(can_sense_location(MapLocation(30, 29))) + # # log(can_sense_location(MapLocation(29, 25))) + # log() diff --git a/players/examplefuncsplayer/bot.py b/players/examplefuncsplayer/bot.py index 1a07aed..3bb647b 100644 --- a/players/examplefuncsplayer/bot.py +++ b/players/examplefuncsplayer/bot.py @@ -15,20 +15,55 @@ Direction.WEST, ] +# def turn(): +# global turn_count +# turn_count += 1 +# robot_type = random.randint(0, 2) +# spawn_loc = get_location().add(directions[random.randint(0, 3)]) +# if robot_type == 0 and can_spawn(RobotType.MOPPER, spawn_loc): +# spawn(RobotType.MOPPER, spawn_loc) +# if robot_type == 1 and can_spawn(RobotType.SPLASHER, spawn_loc): +# spawn(RobotType.SPLASHER, spawn_loc) +# if robot_type == 2 and can_spawn(RobotType.SOLDIER, spawn_loc): +# spawn(RobotType.SOLDIER, spawn_loc) +# att_dir = get_location().add(directions[random.randint(0, 3)]) +# if can_attack(att_dir): +# attack(att_dir, use_secondary_color=False) +# dir = directions[random.randint(0, 3)] +# if can_move(dir): +# move(dir) + def turn(): + + """ + MUST be defined for robot to run + This function will be called at the beginning of every turn and should contain the bulk of your robot commands + """ + # direction = directions[random.randint(0, 3)] + # if can_move(direction): + # move(direction) + + # loc = get_location() + # log(loc) + + # pass + + # if can_move(Direction.NORTH): + # move(Direction.NORTH) + global turn_count turn_count += 1 robot_type = random.randint(0, 2) spawn_loc = get_location().add(directions[random.randint(0, 3)]) - if robot_type == 0 and can_build_robot(RobotType.MOPPER, spawn_loc): - build_robot(RobotType.MOPPER, spawn_loc) - if robot_type == 1 and can_build_robot(RobotType.SPLASHER, spawn_loc): - build_robot(RobotType.SPLASHER, spawn_loc) - if robot_type == 2 and can_build_robot(RobotType.SOLDIER, spawn_loc): - build_robot(RobotType.SOLDIER, spawn_loc) - att_dir = get_location().add(directions[random.randint(0, 3)]) - if can_attack(att_dir): - attack(att_dir, use_secondary_color=False) + # if robot_type == 0 and can_spawn(RobotType.MOPPER, spawn_loc): + # spawn(RobotType.MOPPER, spawn_loc) + # if robot_type == 1 and can_spawn(RobotType.SPLASHER, spawn_loc): + # spawn(RobotType.SPLASHER, spawn_loc) + # if robot_type == 2 and can_spawn(RobotType.SOLDIER, spawn_loc): + # spawn(RobotType.SOLDIER, spawn_loc) + # att_dir = get_location().add(directions[random.randint(0, 3)]) + # if can_attack(att_dir): + # attack(att_dir, use_secondary_color=False) dir = directions[random.randint(0, 3)] if can_move(dir): move(dir) @@ -43,10 +78,7 @@ def turn(): # # if can_move(direction): # # move(direction) -# loc = get_location() -# log(loc) -# log(loc.add(Direction.NORTH)) +# # loc = get_location() +# # log(loc) -# # log(get_round_num()) -# # if can_move(Direction.NORTH): -# # move(Direction.NORTH) \ No newline at end of file +# move(Direction.NORTH) \ No newline at end of file