code-battles 1.5.1 → 1.5.3
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
CHANGED
|
@@ -2592,7 +2592,7 @@ const RunSimulationBlock = () => {
|
|
|
2592
2592
|
}
|
|
2593
2593
|
} }),
|
|
2594
2594
|
React.createElement(BotSelector, { playerCount: playerCount, setPlayerCount: setPlayerCount, playerBots: playerBots, setPlayerBots: setPlayerBots, apis: apis }),
|
|
2595
|
-
React.createElement(core.NumberInput, { leftSection: React.createElement("i", { className: "fa-solid fa-dice" }), label: "Randomness Seed", min: 0, value: seed, onChange: setSeed }),
|
|
2595
|
+
React.createElement(core.NumberInput, { mt: "xs", leftSection: React.createElement("i", { className: "fa-solid fa-dice" }), label: "Randomness Seed", min: 0, value: seed, onChange: setSeed }),
|
|
2596
2596
|
React.createElement(core.Button.Group, { mt: "xs" },
|
|
2597
2597
|
React.createElement(core.Button, { variant: "default", w: "50%", leftSection: React.createElement("i", { className: "fa-solid fa-play" }), onClick: run }, "Run"),
|
|
2598
2598
|
React.createElement(core.Button, { variant: "default", w: "50%", leftSection: React.createElement("i", { className: "fa-solid fa-forward" }), onClick: startRunNoUI, loading: runningNoUI || loading }, "Run (No UI)")),
|
|
@@ -15880,7 +15880,7 @@ const LogViewer = ({ playerNames }) => {
|
|
|
15880
15880
|
defaultValue: [],
|
|
15881
15881
|
});
|
|
15882
15882
|
React.useEffect(() => {
|
|
15883
|
-
|
|
15883
|
+
setLogs([]);
|
|
15884
15884
|
setShowLogs(playerNames.map(() => true));
|
|
15885
15885
|
}, [playerNames]);
|
|
15886
15886
|
React.useEffect(() => {
|
|
@@ -527,20 +527,39 @@ class CodeBattles(
|
|
|
527
527
|
self.step += 1
|
|
528
528
|
|
|
529
529
|
def _run_local_simulation(self):
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
530
|
+
command = sys.argv[1]
|
|
531
|
+
decisions = []
|
|
532
|
+
if command == "simulate":
|
|
533
|
+
seed = None if sys.argv[2] == "None" else int(sys.argv[2])
|
|
534
|
+
self.map = sys.argv[3]
|
|
535
|
+
self.player_names = sys.argv[4].split("-")
|
|
536
|
+
player_codes = []
|
|
537
|
+
for filename in sys.argv[5:]:
|
|
538
|
+
with open(filename, "r") as f:
|
|
539
|
+
player_codes.append(f.read())
|
|
540
|
+
elif command == "simulate-from-file":
|
|
541
|
+
with open(sys.argv[2], "r") as f:
|
|
542
|
+
contents = f.read()
|
|
543
|
+
simulation = Simulation.load(contents)
|
|
544
|
+
seed = simulation.seed
|
|
545
|
+
self.map = simulation.map
|
|
546
|
+
self.player_names = simulation.player_names
|
|
547
|
+
decisions = simulation.decisions
|
|
548
|
+
player_codes = ["" for _ in simulation.player_names]
|
|
549
|
+
else:
|
|
550
|
+
print(f"invalid command {sys.argv[1]}", file=sys.stderr)
|
|
551
|
+
exit(-1)
|
|
533
552
|
self.background = True
|
|
534
553
|
self.console_visible = False
|
|
535
554
|
self.verbose = False
|
|
536
|
-
player_codes = []
|
|
537
|
-
for filename in sys.argv[4:]:
|
|
538
|
-
with open(filename, "r") as f:
|
|
539
|
-
player_codes.append(f.read())
|
|
540
555
|
self._initialize_simulation(player_codes, seed)
|
|
541
556
|
|
|
542
557
|
while not self.over:
|
|
543
|
-
|
|
558
|
+
print("__CODE_BATTLES_ADVANCE_STEP")
|
|
559
|
+
if len(decisions) != 0:
|
|
560
|
+
self.apply_decisions(decisions.pop(0))
|
|
561
|
+
else:
|
|
562
|
+
self.apply_decisions(self.make_decisions())
|
|
544
563
|
|
|
545
564
|
if not self.over:
|
|
546
565
|
self.step += 1
|
|
@@ -18,13 +18,15 @@ def is_worker():
|
|
|
18
18
|
|
|
19
19
|
return False
|
|
20
20
|
except Exception:
|
|
21
|
-
return
|
|
21
|
+
return is_web_or_worker()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def is_web_or_worker():
|
|
25
|
+
return "MicroPython" in sys.version or "pyodide" in sys.executable
|
|
22
26
|
|
|
23
27
|
|
|
24
28
|
def is_web():
|
|
25
|
-
return (
|
|
26
|
-
"MicroPython" in sys.version or "pyodide" in sys.executable
|
|
27
|
-
) and not is_worker()
|
|
29
|
+
return is_web_or_worker() and not is_worker()
|
|
28
30
|
|
|
29
31
|
|
|
30
32
|
def web_only(method):
|
package/dist/esm/index.js
CHANGED
|
@@ -2590,7 +2590,7 @@ const RunSimulationBlock = () => {
|
|
|
2590
2590
|
}
|
|
2591
2591
|
} }),
|
|
2592
2592
|
React.createElement(BotSelector, { playerCount: playerCount, setPlayerCount: setPlayerCount, playerBots: playerBots, setPlayerBots: setPlayerBots, apis: apis }),
|
|
2593
|
-
React.createElement(NumberInput, { leftSection: React.createElement("i", { className: "fa-solid fa-dice" }), label: "Randomness Seed", min: 0, value: seed, onChange: setSeed }),
|
|
2593
|
+
React.createElement(NumberInput, { mt: "xs", leftSection: React.createElement("i", { className: "fa-solid fa-dice" }), label: "Randomness Seed", min: 0, value: seed, onChange: setSeed }),
|
|
2594
2594
|
React.createElement(Button.Group, { mt: "xs" },
|
|
2595
2595
|
React.createElement(Button, { variant: "default", w: "50%", leftSection: React.createElement("i", { className: "fa-solid fa-play" }), onClick: run }, "Run"),
|
|
2596
2596
|
React.createElement(Button, { variant: "default", w: "50%", leftSection: React.createElement("i", { className: "fa-solid fa-forward" }), onClick: startRunNoUI, loading: runningNoUI || loading }, "Run (No UI)")),
|
|
@@ -15878,7 +15878,7 @@ const LogViewer = ({ playerNames }) => {
|
|
|
15878
15878
|
defaultValue: [],
|
|
15879
15879
|
});
|
|
15880
15880
|
useEffect(() => {
|
|
15881
|
-
|
|
15881
|
+
setLogs([]);
|
|
15882
15882
|
setShowLogs(playerNames.map(() => true));
|
|
15883
15883
|
}, [playerNames]);
|
|
15884
15884
|
useEffect(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "code-battles",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
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",
|
|
@@ -38,15 +38,15 @@
|
|
|
38
38
|
"tsparticles": "^3.5.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@mantine/core": "^7.13.
|
|
42
|
-
"@mantine/dates": "^7.13.
|
|
43
|
-
"@mantine/dropzone": "^7.13.
|
|
44
|
-
"@mantine/hooks": "^7.13.
|
|
45
|
-
"@mantine/notifications": "^7.13.
|
|
41
|
+
"@mantine/core": "^7.13.5",
|
|
42
|
+
"@mantine/dates": "^7.13.5",
|
|
43
|
+
"@mantine/dropzone": "^7.13.5",
|
|
44
|
+
"@mantine/hooks": "^7.13.5",
|
|
45
|
+
"@mantine/notifications": "^7.13.5",
|
|
46
46
|
"firebase": "^11.0.1",
|
|
47
47
|
"react": "^18.3.1",
|
|
48
48
|
"react-dom": "^18.3.1",
|
|
49
|
-
"react-router-dom": "^6.
|
|
49
|
+
"react-router-dom": "^6.28.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@pyscript/core": "^0.5.16",
|