Skip to content

Commit

Permalink
Merge branch 'main' into public-release
Browse files Browse the repository at this point in the history
  • Loading branch information
TheApplePieGod committed Jan 23, 2025
2 parents 6ccb793 + 7bfbab0 commit 1f64022
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 33 deletions.
50 changes: 28 additions & 22 deletions .github/workflows/release-engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
21 changes: 13 additions & 8 deletions battlecode25/engine/container/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,6 +13,9 @@
import dis
import inspect

class GameFinishedException(Exception):
pass

class RobotThread(Thread):
def __init__(self, runner):
Thread.__init__(self)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.')

Expand All @@ -257,3 +261,4 @@ def run(self):

def kill(self):
self.thread.kill()
self.thread.join()
5 changes: 4 additions & 1 deletion battlecode25/engine/game/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions battlecode25/engine/game/robot_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 1f64022

Please sign in to comment.