Skip to content

Commit 1f64022

Browse files
Merge branch 'main' into public-release
2 parents 6ccb793 + 7bfbab0 commit 1f64022

File tree

4 files changed

+47
-33
lines changed

4 files changed

+47
-33
lines changed

.github/workflows/release-engine.yml

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ jobs:
2525
id-token: write
2626

2727
steps:
28+
- uses: conda-incubator/setup-miniconda@v3
29+
with:
30+
python-version: 3.12
31+
2832
- name: Checkout branch
2933
uses: actions/checkout@v3
3034

@@ -45,31 +49,33 @@ jobs:
4549
- name: Set up Google Cloud SDK
4650
uses: 'google-github-actions/setup-gcloud@v1'
4751

48-
# TODO: private maps
49-
#- name: Clone private maps
50-
# if: ${{ env.IS_PUBLIC != 'YES' }}
51-
# uses: actions/checkout@v3
52-
# with:
53-
# repository: battlecode/private-maps
54-
# token: ${{ secrets.CI_REPOSITORY_CLONE_PAT }}
55-
# path: private-maps
56-
#
57-
#- name: Inject private maps
58-
# if: ${{ env.IS_PUBLIC != 'YES' }}
59-
# run: |
60-
# source="private-maps/$RELEASE_ARTIFACT_ID"
61-
# dest="engine/src/main/battlecode/world/resources"
62-
# if [ -d "$source" ]; then
63-
# cp -r -i "$source/." "$dest/" < /dev/null &> private-maps-copy-log
64-
# if [ -s "private-maps-copy-log" ]; then
65-
# echo "FAILED! Public and private maps should not intersect."
66-
# cat private-maps-copy-log
67-
# exit 1
68-
# fi
69-
# fi
52+
- name: Clone private maps
53+
if: ${{ env.IS_PUBLIC != 'YES' }}
54+
uses: actions/checkout@v3
55+
with:
56+
repository: battlecode/private-maps
57+
token: ${{ secrets.CI_REPOSITORY_CLONE_PAT }}
58+
path: private-maps
59+
60+
- name: Inject private maps
61+
if: ${{ env.IS_PUBLIC != 'YES' }}
62+
run: |
63+
source="private-maps/$RELEASE_ARTIFACT_ID"
64+
dest="battlecode25/maps"
65+
if [ -d "$source" ]; then
66+
cp -r -i "$source/." "$dest/" < /dev/null &> private-maps-copy-log
67+
if [ -s "private-maps-copy-log" ]; then
68+
echo "FAILED! Public and private maps should not intersect."
69+
cat private-maps-copy-log
70+
exit 1
71+
fi
72+
fi
7073
7174
- name: Build python package
75+
shell: bash -el {0} # Make sure conda is activated
7276
run: |
77+
conda info
78+
python --version
7379
pip install --upgrade build
7480
SETUPTOOLS_SCM_PRETEND_VERSION=${RELEASE_VERSION} python -m build
7581

battlecode25/engine/container/runner.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import traceback
33

44
from RestrictedPython import safe_builtins, limited_builtins, utility_builtins, Guards
5-
from threading import Thread, Event, Condition
5+
from threading import Thread, Event, Lock
66
from time import sleep
77
from .instrument import Instrument
88
from types import CodeType, MethodType
@@ -13,6 +13,9 @@
1313
import dis
1414
import inspect
1515

16+
class GameFinishedException(Exception):
17+
pass
18+
1619
class RobotThread(Thread):
1720
def __init__(self, runner):
1821
Thread.__init__(self)
@@ -30,17 +33,18 @@ def run(self):
3033
if not self.running:
3134
return
3235

36+
#print("bytecode before", self.runner.bytecode)
3337
if not self.runner.initialized:
3438
self.runner.init_robot()
35-
36-
# print("bytecode before", self.runner.bytecode)
3739
self.runner.do_turn()
38-
# print("bytecode after", self.runner.bytecode)
40+
#print("bytecode after", self.runner.bytecode)
3941

4042
self.run_event.clear()
4143
self.finished_event.set()
4244

4345
def wait(self):
46+
if not self.running:
47+
raise GameFinishedException
4448
self.paused = True
4549
self.finished_event.set() # External signal that we are finished for now
4650
self.pause_event.wait() # Wait for unpause
@@ -62,6 +66,7 @@ def __init__(self, code, game_methods, log_method, error_method, bytecode_limit,
6266
'__name__': '__main__'
6367
}
6468

69+
self.globals['__builtins__']['range'] = range
6570
self.globals['__builtins__']['__metaclass__'] = type
6671
self.globals['__builtins__']['instrument'] = self.instrument_call
6772
self.globals['__builtins__']['__multinstrument__'] = self.multinstrument_call
@@ -234,10 +239,9 @@ def do_turn(self):
234239
if 'turn' in self.locals and isinstance(self.locals['turn'], type(lambda: 1)):
235240
try:
236241
exec(self.locals['turn'].__code__, self.globals, self.locals)
237-
except:
238-
# print("in except block")
239-
# print(dis.dis(self.locals['turn'].__code__, show_caches=True, adaptive=False))
240-
self.error_method(traceback.format_exc(limit=5))
242+
except Exception as e:
243+
if not isinstance(e, GameFinishedException):
244+
self.error_method(traceback.format_exc(limit=5))
241245
else:
242246
self.error_method('Couldn\'t find turn function.')
243247

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

258262
def kill(self):
259263
self.thread.kill()
264+
self.thread.join()

battlecode25/engine/game/game.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ def mark_location(self, team: Team, loc: MapLocation, secondary: bool):
123123
markers = self.team_a_markers if team == Team.A else self.team_b_markers
124124
markers[loc.y * self.width + loc.x] = 2 if secondary else 1
125125

126+
def mark_location_int(self, team: Team, loc: MapLocation, val: int):
127+
markers = self.team_a_markers if team == Team.A else self.team_b_markers
128+
markers[loc.y * self.width + loc.x] = val
129+
126130
def get_num_towers(self, team: Team):
127131
return [robot.team == team and robot.type.is_tower_type() for robot in self.id_to_robot.values()].count(True)
128132

@@ -445,7 +449,6 @@ def mark_tower_pattern(self, team, center, tower_type):
445449
self.mark_pattern(team, center, self.shape_from_tower_type(tower_type))
446450

447451
def is_pattern_obstructed(self, center):
448-
print("called this")
449452
offset = GameConstants.PATTERN_SIZE//2
450453
for dx in range(-offset, offset + 1):
451454
for dy in range(-offset, offset + 1):

battlecode25/engine/game/robot_controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def can_remove_mark(self, loc: MapLocation) -> bool:
525525

526526
def remove_mark(self, loc: MapLocation) -> None:
527527
self.assert_can_remove_mark(loc)
528-
self.game.mark_location(self.robot.team, loc, 0)
528+
self.game.mark_location_int(self.robot.team, loc, 0)
529529
self.game.game_fb.add_unmark_action(loc)
530530

531531
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:
658658
target = self.game.get_robot(loc)
659659
target.message_buffer.add_message(message)
660660
self.robot.sent_message_count += 1
661-
self.game.game_fb.add_message_action(target.id, message_content)
661+
#self.game.game_fb.add_message_action(target.id, message_content)
662662

663663
def assert_can_broadcast_message(self):
664664
if self.robot.type.is_robot_type():

0 commit comments

Comments
 (0)