code-battles 1.7.8 → 1.7.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +13 -0
- package/dist/code_battles/battles.py +12 -1
- package/dist/esm/index.js +13 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -5987,6 +5987,19 @@ function requirePrismLineNumbers () {
|
|
|
5987
5987
|
requirePrismLineNumbers();
|
|
5988
5988
|
|
|
5989
5989
|
const initialize = () => {
|
|
5990
|
+
// Load the packed Python file of the project, on the main thread and on a web worker.
|
|
5991
|
+
const mainThreadScript = document.createElement("script");
|
|
5992
|
+
mainThreadScript.type = "py";
|
|
5993
|
+
mainThreadScript.src = "/scripts/packed.py";
|
|
5994
|
+
mainThreadScript.setAttribute("config", "/config.json");
|
|
5995
|
+
document.body.appendChild(mainThreadScript);
|
|
5996
|
+
const workerScript = document.createElement("script");
|
|
5997
|
+
workerScript.type = "py";
|
|
5998
|
+
workerScript.src = "/scripts/packed.py";
|
|
5999
|
+
workerScript.setAttribute("config", "/config.json");
|
|
6000
|
+
workerScript.toggleAttribute("worker", true);
|
|
6001
|
+
workerScript.setAttribute("name", "worker");
|
|
6002
|
+
document.body.appendChild(workerScript);
|
|
5990
6003
|
// @ts-ignore
|
|
5991
6004
|
window.showAlert = (title, alert, color, icon, limitTime, isCode) => {
|
|
5992
6005
|
var _a;
|
|
@@ -45,6 +45,7 @@ class Simulation:
|
|
|
45
45
|
version: str
|
|
46
46
|
timestamp: datetime.datetime
|
|
47
47
|
logs: list
|
|
48
|
+
alerts: list
|
|
48
49
|
decisions: List[bytes]
|
|
49
50
|
seed: int
|
|
50
51
|
|
|
@@ -59,6 +60,7 @@ class Simulation:
|
|
|
59
60
|
"version": self.version,
|
|
60
61
|
"timestamp": self.timestamp.isoformat(),
|
|
61
62
|
"logs": self.logs,
|
|
63
|
+
"alerts": self.alerts,
|
|
62
64
|
"decisions": [
|
|
63
65
|
base64.b64encode(decision).decode()
|
|
64
66
|
for decision in self.decisions
|
|
@@ -81,6 +83,7 @@ class Simulation:
|
|
|
81
83
|
contents["version"],
|
|
82
84
|
datetime.datetime.fromisoformat(contents["timestamp"]),
|
|
83
85
|
contents["logs"],
|
|
86
|
+
contents["alerts"],
|
|
84
87
|
[base64.b64decode(decision) for decision in contents["decisions"]],
|
|
85
88
|
contents["seed"],
|
|
86
89
|
)
|
|
@@ -627,7 +630,8 @@ class CodeBattles(
|
|
|
627
630
|
if command == "simulate":
|
|
628
631
|
seed = None if sys.argv[2] == "None" else int(sys.argv[2])
|
|
629
632
|
output_file = None if sys.argv[3] == "None" else sys.argv[3]
|
|
630
|
-
self.
|
|
633
|
+
self.parameters = json.loads(sys.argv[4])
|
|
634
|
+
self.map = self.parameters.get("map")
|
|
631
635
|
self.player_names = sys.argv[5].split("-")
|
|
632
636
|
player_codes = []
|
|
633
637
|
for filename in sys.argv[6:]:
|
|
@@ -652,15 +656,19 @@ class CodeBattles(
|
|
|
652
656
|
self._initialize_simulation(player_codes, seed)
|
|
653
657
|
|
|
654
658
|
all_logs = []
|
|
659
|
+
all_alerts = []
|
|
655
660
|
while not self.over:
|
|
656
661
|
print("__CODE_BATTLES_ADVANCE_STEP")
|
|
657
662
|
if len(decisions) != 0:
|
|
658
663
|
self.apply_decisions(decisions.pop(0))
|
|
659
664
|
else:
|
|
660
665
|
self._logs = []
|
|
666
|
+
self._alerts = []
|
|
661
667
|
_decisions = self._make_decisions()
|
|
662
668
|
all_logs.append(self._logs)
|
|
669
|
+
all_alerts.append(self._alerts)
|
|
663
670
|
self._logs = []
|
|
671
|
+
self._alerts = []
|
|
664
672
|
if output_file is not None:
|
|
665
673
|
self._decisions.append(_decisions)
|
|
666
674
|
self.apply_decisions(_decisions)
|
|
@@ -668,6 +676,7 @@ class CodeBattles(
|
|
|
668
676
|
if not self.over:
|
|
669
677
|
self.step += 1
|
|
670
678
|
self._logs = all_logs
|
|
679
|
+
self._alerts = all_alerts
|
|
671
680
|
|
|
672
681
|
print("--- SIMULATION FINISHED ---")
|
|
673
682
|
print(
|
|
@@ -741,6 +750,7 @@ class CodeBattles(
|
|
|
741
750
|
)
|
|
742
751
|
self._decisions = simulation.decisions
|
|
743
752
|
self._logs = simulation.logs
|
|
753
|
+
self._alerts = simulation.alerts
|
|
744
754
|
self.canvas = GameCanvas(
|
|
745
755
|
document.getElementById("simulation"),
|
|
746
756
|
self.configure_board_count(),
|
|
@@ -852,6 +862,7 @@ class CodeBattles(
|
|
|
852
862
|
self.configure_version(),
|
|
853
863
|
datetime.datetime.now(),
|
|
854
864
|
self._logs,
|
|
865
|
+
self._alerts,
|
|
855
866
|
self._decisions,
|
|
856
867
|
self._seed,
|
|
857
868
|
)
|
package/dist/esm/index.js
CHANGED
|
@@ -5985,6 +5985,19 @@ function requirePrismLineNumbers () {
|
|
|
5985
5985
|
requirePrismLineNumbers();
|
|
5986
5986
|
|
|
5987
5987
|
const initialize = () => {
|
|
5988
|
+
// Load the packed Python file of the project, on the main thread and on a web worker.
|
|
5989
|
+
const mainThreadScript = document.createElement("script");
|
|
5990
|
+
mainThreadScript.type = "py";
|
|
5991
|
+
mainThreadScript.src = "/scripts/packed.py";
|
|
5992
|
+
mainThreadScript.setAttribute("config", "/config.json");
|
|
5993
|
+
document.body.appendChild(mainThreadScript);
|
|
5994
|
+
const workerScript = document.createElement("script");
|
|
5995
|
+
workerScript.type = "py";
|
|
5996
|
+
workerScript.src = "/scripts/packed.py";
|
|
5997
|
+
workerScript.setAttribute("config", "/config.json");
|
|
5998
|
+
workerScript.toggleAttribute("worker", true);
|
|
5999
|
+
workerScript.setAttribute("name", "worker");
|
|
6000
|
+
document.body.appendChild(workerScript);
|
|
5988
6001
|
// @ts-ignore
|
|
5989
6002
|
window.showAlert = (title, alert, color, icon, limitTime, isCode) => {
|
|
5990
6003
|
var _a;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "code-battles",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.10",
|
|
4
4
|
"description": "A library for building interactive competitive coding battles",
|
|
5
5
|
"repository": "https://github.com/noamzaks/code-battles",
|
|
6
6
|
"homepage": "https://code-battles.readthedocs.org",
|