code-battles 1.5.5 → 1.5.7
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 +7 -4
- package/dist/code_battles/battles.py +9 -10
- package/dist/esm/index.js +7 -4
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -460,9 +460,12 @@ const useLocalStorage = ({ key, defaultValue, }) => {
|
|
|
460
460
|
if (typeof newValue === "function") {
|
|
461
461
|
newValue = newValue(value);
|
|
462
462
|
}
|
|
463
|
-
if (newValue) {
|
|
463
|
+
if (newValue !== undefined) {
|
|
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];
|
|
@@ -2518,7 +2521,7 @@ const RunSimulationBlock = () => {
|
|
|
2518
2521
|
const run = () => {
|
|
2519
2522
|
// @ts-ignore
|
|
2520
2523
|
window._isSimulationFromFile = false;
|
|
2521
|
-
navigate(`/simulation/${map.replaceAll(" ", "-")}/${playerBots.join("-")}?seed=${seed}`);
|
|
2524
|
+
navigate(`/simulation/${map.replaceAll(" ", "-")}/${playerBots.join("-")}?seed=${seed === "-" ? "" : seed}`);
|
|
2522
2525
|
};
|
|
2523
2526
|
const startRunNoUI = () => {
|
|
2524
2527
|
setRunningNoUI(true);
|
|
@@ -15880,7 +15883,6 @@ const LogViewer = ({ playerNames }) => {
|
|
|
15880
15883
|
defaultValue: [],
|
|
15881
15884
|
});
|
|
15882
15885
|
React.useEffect(() => {
|
|
15883
|
-
setLogs([]);
|
|
15884
15886
|
setShowLogs(playerNames.map(() => true));
|
|
15885
15887
|
}, [playerNames]);
|
|
15886
15888
|
React.useEffect(() => {
|
|
@@ -15960,6 +15962,7 @@ const Simulation = () => {
|
|
|
15960
15962
|
const colorScheme = hooks.useColorScheme();
|
|
15961
15963
|
const showcaseMode = location.search.includes("showcase=true");
|
|
15962
15964
|
React.useEffect(() => {
|
|
15965
|
+
setLocalStorage("Logs", []);
|
|
15963
15966
|
n((engine) => __awaiter(void 0, void 0, void 0, function* () { return yield loadFull(engine); }));
|
|
15964
15967
|
// @ts-ignore
|
|
15965
15968
|
window.showDownload = () => {
|
|
@@ -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
|
@@ -458,9 +458,12 @@ const useLocalStorage = ({ key, defaultValue, }) => {
|
|
|
458
458
|
if (typeof newValue === "function") {
|
|
459
459
|
newValue = newValue(value);
|
|
460
460
|
}
|
|
461
|
-
if (newValue) {
|
|
461
|
+
if (newValue !== undefined) {
|
|
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];
|
|
@@ -2516,7 +2519,7 @@ const RunSimulationBlock = () => {
|
|
|
2516
2519
|
const run = () => {
|
|
2517
2520
|
// @ts-ignore
|
|
2518
2521
|
window._isSimulationFromFile = false;
|
|
2519
|
-
navigate(`/simulation/${map.replaceAll(" ", "-")}/${playerBots.join("-")}?seed=${seed}`);
|
|
2522
|
+
navigate(`/simulation/${map.replaceAll(" ", "-")}/${playerBots.join("-")}?seed=${seed === "-" ? "" : seed}`);
|
|
2520
2523
|
};
|
|
2521
2524
|
const startRunNoUI = () => {
|
|
2522
2525
|
setRunningNoUI(true);
|
|
@@ -15878,7 +15881,6 @@ const LogViewer = ({ playerNames }) => {
|
|
|
15878
15881
|
defaultValue: [],
|
|
15879
15882
|
});
|
|
15880
15883
|
useEffect(() => {
|
|
15881
|
-
setLogs([]);
|
|
15882
15884
|
setShowLogs(playerNames.map(() => true));
|
|
15883
15885
|
}, [playerNames]);
|
|
15884
15886
|
useEffect(() => {
|
|
@@ -15958,6 +15960,7 @@ const Simulation = () => {
|
|
|
15958
15960
|
const colorScheme = useColorScheme();
|
|
15959
15961
|
const showcaseMode = location.search.includes("showcase=true");
|
|
15960
15962
|
useEffect(() => {
|
|
15963
|
+
setLocalStorage("Logs", []);
|
|
15961
15964
|
n((engine) => __awaiter(void 0, void 0, void 0, function* () { return yield loadFull(engine); }));
|
|
15962
15965
|
// @ts-ignore
|
|
15963
15966
|
window.showDownload = () => {
|
package/package.json
CHANGED