From 83d85c6cd08d0ca758d4a2402a6f8dd55063e7e3 Mon Sep 17 00:00:00 2001 From: David Wei Date: Thu, 2 Jan 2025 14:19:14 -0500 Subject: [PATCH 1/6] basic stuff --- players/examplefuncsplayer/bot.py | 57 ++++++++++++++++--------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/players/examplefuncsplayer/bot.py b/players/examplefuncsplayer/bot.py index f33ecf3..59083f0 100644 --- a/players/examplefuncsplayer/bot.py +++ b/players/examplefuncsplayer/bot.py @@ -15,35 +15,36 @@ 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(): +# 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) + """ + 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) + # loc = get_location() + # log(loc) -# move(Direction.NORTH) \ No newline at end of file + if can_move(Direction.NORTH): + move(Direction.NORTH) \ No newline at end of file From ee7380cabb087aa3b97b4660e3d2f76744c65e59 Mon Sep 17 00:00:00 2001 From: David Wei Date: Thu, 2 Jan 2025 14:26:01 -0500 Subject: [PATCH 2/6] nothing --- players/examplefuncsplayer/bot.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/players/examplefuncsplayer/bot.py b/players/examplefuncsplayer/bot.py index 59083f0..6ae2db9 100644 --- a/players/examplefuncsplayer/bot.py +++ b/players/examplefuncsplayer/bot.py @@ -46,5 +46,7 @@ def turn(): # loc = get_location() # log(loc) - if can_move(Direction.NORTH): - move(Direction.NORTH) \ No newline at end of file + pass + + # if can_move(Direction.NORTH): + # move(Direction.NORTH) \ No newline at end of file From f6ea664b16dfd67c9e1e1debe307b7b28a21659a Mon Sep 17 00:00:00 2001 From: David Wei Date: Fri, 3 Jan 2025 11:20:21 -0500 Subject: [PATCH 3/6] stuff --- players/examplefuncsplayer/bot.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/players/examplefuncsplayer/bot.py b/players/examplefuncsplayer/bot.py index 6ae2db9..1b7f73e 100644 --- a/players/examplefuncsplayer/bot.py +++ b/players/examplefuncsplayer/bot.py @@ -46,7 +46,24 @@ def turn(): # loc = get_location() # log(loc) - pass + # pass # if can_move(Direction.NORTH): - # move(Direction.NORTH) \ No newline at end of file + # 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_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) \ No newline at end of file From 470f74ed4ee2a7f84183b8b54e491c53354c5304 Mon Sep 17 00:00:00 2001 From: David Wei Date: Sun, 5 Jan 2025 20:41:05 -0500 Subject: [PATCH 4/6] stuff --- battlecode25/engine/game/robot_controller.py | 2 + players/davidbot/bot.py | 60 ++++++++++++++++++++ players/examplefuncsplayer/bot.py | 18 +++--- 3 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 players/davidbot/bot.py diff --git a/battlecode25/engine/game/robot_controller.py b/battlecode25/engine/game/robot_controller.py index e114648..b52b2ef 100644 --- a/battlecode25/engine/game/robot_controller.py +++ b/battlecode25/engine/game/robot_controller.py @@ -146,6 +146,8 @@ def sense_nearby_robots(self, center: MapLocation=None, radius_squared: int=Game result = [] for loc in sensed_locs: sensed_robot = self.game.get_robot(loc) + if sensed_robot is None: + continue if sensed_robot == self.robot: continue if not self.can_sense_location(sensed_robot.loc): diff --git a/players/davidbot/bot.py b/players/davidbot/bot.py new file mode 100644 index 0000000..24ce932 --- /dev/null +++ b/players/davidbot/bot.py @@ -0,0 +1,60 @@ +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 = [RobotType.LEVEL_ONE_PAINT_TOWER, RobotType.LEVEL_TWO_PAINT_TOWER, RobotType.LEVEL_THREE_PAINT_TOWER] + +def turn(): + 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() + + + # 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(RobotType.SPLASHER, spawn_loc): + # build_robot(RobotType.SPLASHER, spawn_loc) + + # danger = sense_nearby_robots() + # log("Nearby robots") + # log(danger) + # for robot in danger: + # if can_attack(robot.get_location()): + # 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) diff --git a/players/examplefuncsplayer/bot.py b/players/examplefuncsplayer/bot.py index 45e74d0..3bb647b 100644 --- a/players/examplefuncsplayer/bot.py +++ b/players/examplefuncsplayer/bot.py @@ -55,15 +55,15 @@ def turn(): 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) + # 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) From 2c0538026d30601b29e5b431e0cd2e02b04285c3 Mon Sep 17 00:00:00 2001 From: David Wei Date: Mon, 6 Jan 2025 00:21:07 -0500 Subject: [PATCH 5/6] fix --- battlecode25/engine/game/robot_controller.py | 2 + players/davidbot/bot.py | 67 ++++++++++---------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/battlecode25/engine/game/robot_controller.py b/battlecode25/engine/game/robot_controller.py index f36a407..ffc54fa 100644 --- a/battlecode25/engine/game/robot_controller.py +++ b/battlecode25/engine/game/robot_controller.py @@ -143,6 +143,8 @@ def sense_nearby_robots(self, center: MapLocation=None, radius_squared: int=Game result = [] for loc in sensed_locs: sensed_robot = self.game.get_robot(loc) + if not sensed_robot: + continue if sensed_robot == self.robot: continue if not self.can_sense_location(sensed_robot.loc): diff --git a/players/davidbot/bot.py b/players/davidbot/bot.py index 102cb38..ec59991 100644 --- a/players/davidbot/bot.py +++ b/players/davidbot/bot.py @@ -20,41 +20,42 @@ def turn(): 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() + if can_upgrade_tower(loc): + upgrade_tower(loc) - # loc = get_location() + 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) - # if can_upgrade_tower(loc): - # upgrade_tower(loc) + danger = sense_nearby_robots() + for robot in danger: + if can_attack(robot.get_location()): + 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) - # if get_type().is_tower_type(): - # spawn_loc = loc.add(directions[random.randint(0, 3)]) - # if can_build_robot(RobotType.SPLASHER, spawn_loc): - # build_robot(RobotType.SPLASHER, spawn_loc) - # danger = sense_nearby_robots() - # log("Nearby robots") - # log(danger) - # for robot in danger: - # if can_attack(robot.get_location()): - # 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() From 71e165cc94a5d52d722ab896b4f35be967f83427 Mon Sep 17 00:00:00 2001 From: David Wei Date: Mon, 6 Jan 2025 14:38:15 -0500 Subject: [PATCH 6/6] tower fixes --- battlecode25/engine/game/robot.py | 4 ++-- battlecode25/engine/game/robot_controller.py | 1 + players/davidbot/bot.py | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) 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 index ec59991..9b8a3d7 100644 --- a/players/davidbot/bot.py +++ b/players/davidbot/bot.py @@ -30,8 +30,12 @@ def turn(): 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: