code-battles 1.5.5 → 1.5.6
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 +4 -1
- package/dist/code_battles/battles.py +9 -10
- package/dist/esm/index.js +4 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -462,7 +462,10 @@ const useLocalStorage = ({ key, defaultValue, }) => {
|
|
|
462
462
|
}
|
|
463
463
|
if (newValue) {
|
|
464
464
|
localStorage.setItem(key, JSON.stringify(newValue));
|
|
465
|
-
window.dispatchEvent(new StorageEvent("storage", {
|
|
465
|
+
window.dispatchEvent(new StorageEvent("storage", {
|
|
466
|
+
key,
|
|
467
|
+
newValue: JSON.stringify(newValue),
|
|
468
|
+
}));
|
|
466
469
|
}
|
|
467
470
|
};
|
|
468
471
|
return [value, userSetValue];
|
|
@@ -466,8 +466,6 @@ class CodeBattles(
|
|
|
466
466
|
if step_element is not None:
|
|
467
467
|
step_element.onclick = create_proxy(lambda _: self._step())
|
|
468
468
|
|
|
469
|
-
self._initialized = True
|
|
470
|
-
|
|
471
469
|
def _initialize_simulation(
|
|
472
470
|
self, player_codes: List[str], seed: Optional[int] = None
|
|
473
471
|
):
|
|
@@ -558,18 +556,23 @@ class CodeBattles(
|
|
|
558
556
|
self.verbose = False
|
|
559
557
|
self._initialize_simulation(player_codes, seed)
|
|
560
558
|
|
|
559
|
+
all_logs = []
|
|
561
560
|
while not self.over:
|
|
562
561
|
print("__CODE_BATTLES_ADVANCE_STEP")
|
|
563
562
|
if len(decisions) != 0:
|
|
564
563
|
self.apply_decisions(decisions.pop(0))
|
|
565
564
|
else:
|
|
565
|
+
self._logs = []
|
|
566
566
|
_decisions = self.make_decisions()
|
|
567
|
+
all_logs.append(self._logs)
|
|
568
|
+
self._logs = []
|
|
567
569
|
if output_file is not None:
|
|
568
570
|
self._decisions.append(_decisions)
|
|
569
571
|
self.apply_decisions(_decisions)
|
|
570
572
|
|
|
571
573
|
if not self.over:
|
|
572
574
|
self.step += 1
|
|
575
|
+
self._logs = all_logs
|
|
573
576
|
|
|
574
577
|
print("--- SIMULATION FINISHED ---")
|
|
575
578
|
print(
|
|
@@ -582,7 +585,7 @@ class CodeBattles(
|
|
|
582
585
|
if len(self.active_players) > 0
|
|
583
586
|
else None,
|
|
584
587
|
"steps": self.step,
|
|
585
|
-
"logs": self._logs,
|
|
588
|
+
"logs": [log for logs in self._logs for log in logs],
|
|
586
589
|
}
|
|
587
590
|
)
|
|
588
591
|
)
|
|
@@ -606,7 +609,7 @@ class CodeBattles(
|
|
|
606
609
|
try:
|
|
607
610
|
simulation = Simulation.load(str(contents))
|
|
608
611
|
navigate(
|
|
609
|
-
f"/simulation/{simulation.map}/{'-'.join(simulation.player_names)}"
|
|
612
|
+
f"/simulation/{simulation.map}/{'-'.join(simulation.player_names)}?seed={simulation.seed}"
|
|
610
613
|
)
|
|
611
614
|
show_alert(
|
|
612
615
|
"Loaded simulation file!",
|
|
@@ -633,8 +636,7 @@ class CodeBattles(
|
|
|
633
636
|
)
|
|
634
637
|
while document.getElementById("loader") is None:
|
|
635
638
|
await asyncio.sleep(0.01)
|
|
636
|
-
|
|
637
|
-
self._initialize()
|
|
639
|
+
self._initialize()
|
|
638
640
|
self.map = simulation.map
|
|
639
641
|
self.map_image = await download_image(
|
|
640
642
|
self.configure_map_image_url(simulation.map)
|
|
@@ -711,8 +713,7 @@ class CodeBattles(
|
|
|
711
713
|
await self.setup()
|
|
712
714
|
|
|
713
715
|
if not self.background:
|
|
714
|
-
|
|
715
|
-
self._initialize()
|
|
716
|
+
self._initialize()
|
|
716
717
|
|
|
717
718
|
# Show that loading finished
|
|
718
719
|
document.getElementById("loader").style.display = "none"
|
|
@@ -967,5 +968,3 @@ class CodeBattles(
|
|
|
967
968
|
0,
|
|
968
969
|
)
|
|
969
970
|
)
|
|
970
|
-
else:
|
|
971
|
-
await asyncio.sleep(0.01)
|
package/dist/esm/index.js
CHANGED
|
@@ -460,7 +460,10 @@ const useLocalStorage = ({ key, defaultValue, }) => {
|
|
|
460
460
|
}
|
|
461
461
|
if (newValue) {
|
|
462
462
|
localStorage.setItem(key, JSON.stringify(newValue));
|
|
463
|
-
window.dispatchEvent(new StorageEvent("storage", {
|
|
463
|
+
window.dispatchEvent(new StorageEvent("storage", {
|
|
464
|
+
key,
|
|
465
|
+
newValue: JSON.stringify(newValue),
|
|
466
|
+
}));
|
|
464
467
|
}
|
|
465
468
|
};
|
|
466
469
|
return [value, userSetValue];
|
package/package.json
CHANGED