diff --git a/.github/workflows/release-engine.yml b/.github/workflows/release-engine.yml index 91ac7d6..86dea38 100644 --- a/.github/workflows/release-engine.yml +++ b/.github/workflows/release-engine.yml @@ -25,6 +25,10 @@ jobs: id-token: write steps: + - uses: conda-incubator/setup-miniconda@v3 + with: + python-version: 3.12 + - name: Checkout branch uses: actions/checkout@v3 @@ -45,31 +49,33 @@ jobs: - name: Set up Google Cloud SDK uses: 'google-github-actions/setup-gcloud@v1' - # TODO: private maps - #- name: Clone private maps - # if: ${{ env.IS_PUBLIC != 'YES' }} - # uses: actions/checkout@v3 - # with: - # repository: battlecode/private-maps - # token: ${{ secrets.CI_REPOSITORY_CLONE_PAT }} - # path: private-maps - # - #- name: Inject private maps - # if: ${{ env.IS_PUBLIC != 'YES' }} - # run: | - # source="private-maps/$RELEASE_ARTIFACT_ID" - # dest="engine/src/main/battlecode/world/resources" - # if [ -d "$source" ]; then - # cp -r -i "$source/." "$dest/" < /dev/null &> private-maps-copy-log - # if [ -s "private-maps-copy-log" ]; then - # echo "FAILED! Public and private maps should not intersect." - # cat private-maps-copy-log - # exit 1 - # fi - # fi + - name: Clone private maps + if: ${{ env.IS_PUBLIC != 'YES' }} + uses: actions/checkout@v3 + with: + repository: battlecode/private-maps + token: ${{ secrets.CI_REPOSITORY_CLONE_PAT }} + path: private-maps + + - name: Inject private maps + if: ${{ env.IS_PUBLIC != 'YES' }} + run: | + source="private-maps/$RELEASE_ARTIFACT_ID" + dest="battlecode25/maps" + if [ -d "$source" ]; then + cp -r -i "$source/." "$dest/" < /dev/null &> private-maps-copy-log + if [ -s "private-maps-copy-log" ]; then + echo "FAILED! Public and private maps should not intersect." + cat private-maps-copy-log + exit 1 + fi + fi - name: Build python package + shell: bash -el {0} # Make sure conda is activated run: | + conda info + python --version pip install --upgrade build SETUPTOOLS_SCM_PRETEND_VERSION=${RELEASE_VERSION} python -m build diff --git a/battlecode25/engine/container/runner.py b/battlecode25/engine/container/runner.py index e2199bf..9330210 100644 --- a/battlecode25/engine/container/runner.py +++ b/battlecode25/engine/container/runner.py @@ -2,7 +2,7 @@ import traceback from RestrictedPython import safe_builtins, limited_builtins, utility_builtins, Guards -from threading import Thread, Event, Condition +from threading import Thread, Event, Lock from time import sleep from .instrument import Instrument from types import CodeType, MethodType @@ -13,6 +13,9 @@ import dis import inspect +class GameFinishedException(Exception): + pass + class RobotThread(Thread): def __init__(self, runner): Thread.__init__(self) @@ -30,17 +33,18 @@ def run(self): if not self.running: return + #print("bytecode before", self.runner.bytecode) if not self.runner.initialized: self.runner.init_robot() - - # print("bytecode before", self.runner.bytecode) self.runner.do_turn() - # print("bytecode after", self.runner.bytecode) + #print("bytecode after", self.runner.bytecode) self.run_event.clear() self.finished_event.set() def wait(self): + if not self.running: + raise GameFinishedException self.paused = True self.finished_event.set() # External signal that we are finished for now self.pause_event.wait() # Wait for unpause @@ -62,6 +66,7 @@ def __init__(self, code, game_methods, log_method, error_method, bytecode_limit, '__name__': '__main__' } + self.globals['__builtins__']['range'] = range self.globals['__builtins__']['__metaclass__'] = type self.globals['__builtins__']['instrument'] = self.instrument_call self.globals['__builtins__']['__multinstrument__'] = self.multinstrument_call @@ -234,10 +239,9 @@ def do_turn(self): if 'turn' in self.locals and isinstance(self.locals['turn'], type(lambda: 1)): try: exec(self.locals['turn'].__code__, self.globals, self.locals) - except: - # print("in except block") - # print(dis.dis(self.locals['turn'].__code__, show_caches=True, adaptive=False)) - self.error_method(traceback.format_exc(limit=5)) + except Exception as e: + if not isinstance(e, GameFinishedException): + self.error_method(traceback.format_exc(limit=5)) else: self.error_method('Couldn\'t find turn function.') @@ -257,3 +261,4 @@ def run(self): def kill(self): self.thread.kill() + self.thread.join() diff --git a/battlecode25/engine/game/game.py b/battlecode25/engine/game/game.py index 04eba7d..530ba0c 100644 --- a/battlecode25/engine/game/game.py +++ b/battlecode25/engine/game/game.py @@ -123,6 +123,10 @@ def mark_location(self, team: Team, loc: MapLocation, secondary: bool): markers = self.team_a_markers if team == Team.A else self.team_b_markers markers[loc.y * self.width + loc.x] = 2 if secondary else 1 + def mark_location_int(self, team: Team, loc: MapLocation, val: int): + markers = self.team_a_markers if team == Team.A else self.team_b_markers + markers[loc.y * self.width + loc.x] = val + def get_num_towers(self, team: Team): return [robot.team == team and robot.type.is_tower_type() for robot in self.id_to_robot.values()].count(True) @@ -445,7 +449,6 @@ 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): diff --git a/battlecode25/engine/game/robot_controller.py b/battlecode25/engine/game/robot_controller.py index f143ec7..091e348 100644 --- a/battlecode25/engine/game/robot_controller.py +++ b/battlecode25/engine/game/robot_controller.py @@ -525,7 +525,7 @@ def can_remove_mark(self, loc: MapLocation) -> bool: def remove_mark(self, loc: MapLocation) -> None: self.assert_can_remove_mark(loc) - self.game.mark_location(self.robot.team, loc, 0) + self.game.mark_location_int(self.robot.team, loc, 0) self.game.game_fb.add_unmark_action(loc) def assert_can_complete_tower_pattern(self, tower_type: UnitType, loc: MapLocation) -> None: @@ -658,7 +658,7 @@ def send_message(self, loc: MapLocation, message_content: int) -> None: target = self.game.get_robot(loc) target.message_buffer.add_message(message) self.robot.sent_message_count += 1 - self.game.game_fb.add_message_action(target.id, message_content) + #self.game.game_fb.add_message_action(target.id, message_content) def assert_can_broadcast_message(self): if self.robot.type.is_robot_type():