code-battles 1.7.1 → 1.7.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 +3 -2
- package/dist/code_battles/battles.py +19 -10
- package/dist/esm/index.js +3 -2
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -3033,6 +3033,7 @@ const Round = () => {
|
|
|
3033
3033
|
roundIterations !== 1 && (React.createElement("th", { style: { width: "35%" } }, "Results")),
|
|
3034
3034
|
React.createElement("th", null))),
|
|
3035
3035
|
React.createElement("tbody", null, rounds.map((round, index) => {
|
|
3036
|
+
var _a, _b;
|
|
3036
3037
|
const winCounts = {};
|
|
3037
3038
|
if (results[round.players.join(", ")] !== undefined) {
|
|
3038
3039
|
const currentResults = results[round.players.join(", ")][JSON.stringify(round.parameters)];
|
|
@@ -3055,9 +3056,9 @@ const Round = () => {
|
|
|
3055
3056
|
React.createElement("td", null, round.players.map((player, index) => (React.createElement("img", { key: index, src: `/images/teams/${player.toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } })))),
|
|
3056
3057
|
roundIterations === 1 && (React.createElement(React.Fragment, null,
|
|
3057
3058
|
React.createElement("td", null, results[round.players.join(", ")] !== undefined &&
|
|
3058
|
-
results[round.players.join(", ")][JSON.stringify(round.parameters)] !== undefined && (React.createElement("img", { src: `/images/teams/${round.players[results[round.players.join(", ")][JSON.stringify(round.parameters)][0][0]].toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } }))),
|
|
3059
|
+
results[round.players.join(", ")][JSON.stringify(round.parameters)] !== undefined && (React.createElement("img", { src: `/images/teams/${(_a = round.players[results[round.players.join(", ")][JSON.stringify(round.parameters)][0][0]]) === null || _a === void 0 ? void 0 : _a.toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } }))),
|
|
3059
3060
|
React.createElement("td", null, results[round.players.join(", ")] !== undefined &&
|
|
3060
|
-
results[round.players.join(", ")][JSON.stringify(round.parameters)] !== undefined && (React.createElement("img", { src: `/images/teams/${round.players[results[round.players.join(", ")][JSON.stringify(round.parameters)][0][1]].toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } }))))),
|
|
3061
|
+
results[round.players.join(", ")][JSON.stringify(round.parameters)] !== undefined && (React.createElement("img", { src: `/images/teams/${(_b = round.players[results[round.players.join(", ")][JSON.stringify(round.parameters)][0][1]]) === null || _b === void 0 ? void 0 : _b.toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } }))))),
|
|
3061
3062
|
roundIterations !== 1 && (React.createElement("td", null, winners.map((winner, index) => (React.createElement("p", { key: index },
|
|
3062
3063
|
winner,
|
|
3063
3064
|
": ",
|
|
@@ -259,6 +259,11 @@ class CodeBattles(
|
|
|
259
259
|
|
|
260
260
|
return 20
|
|
261
261
|
|
|
262
|
+
def configure_breakpoint_by_time(self) -> bool:
|
|
263
|
+
"""Return whether the breakpoint value should be a time instead of steps (multiplied by `configure_steps_per_second`)."""
|
|
264
|
+
|
|
265
|
+
return False
|
|
266
|
+
|
|
262
267
|
def configure_board_count(self) -> int:
|
|
263
268
|
"""The number of wanted boards for the game. 1 by default."""
|
|
264
269
|
|
|
@@ -547,7 +552,9 @@ class CodeBattles(
|
|
|
547
552
|
)
|
|
548
553
|
step_element = document.getElementById("step")
|
|
549
554
|
if step_element is not None:
|
|
550
|
-
step_element.onclick = create_proxy(
|
|
555
|
+
step_element.onclick = create_proxy(
|
|
556
|
+
lambda _: asyncio.get_event_loop().run_until_complete(self._step())
|
|
557
|
+
)
|
|
551
558
|
|
|
552
559
|
# Start the simulation.
|
|
553
560
|
document.getElementById("playpause").click()
|
|
@@ -1024,15 +1031,13 @@ class CodeBattles(
|
|
|
1024
1031
|
document.getElementById("playpause").click()
|
|
1025
1032
|
|
|
1026
1033
|
@web_only
|
|
1027
|
-
def _step(self):
|
|
1028
|
-
from js import document
|
|
1029
|
-
from pyscript.ffi import create_proxy
|
|
1034
|
+
async def _step(self):
|
|
1035
|
+
from js import document
|
|
1030
1036
|
|
|
1031
1037
|
if not self.over:
|
|
1032
1038
|
if len(self._decisions) == self._decision_index:
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
return
|
|
1039
|
+
await asyncio.sleep(0.01)
|
|
1040
|
+
return await self._step()
|
|
1036
1041
|
else:
|
|
1037
1042
|
logs = self._logs[self._decision_index]
|
|
1038
1043
|
for log in logs:
|
|
@@ -1098,6 +1103,7 @@ class CodeBattles(
|
|
|
1098
1103
|
return False
|
|
1099
1104
|
|
|
1100
1105
|
if self.step == self._get_breakpoint():
|
|
1106
|
+
self._ensure_paused()
|
|
1101
1107
|
return False
|
|
1102
1108
|
|
|
1103
1109
|
if self.step in self._breakpoints and self.console_visible:
|
|
@@ -1128,6 +1134,10 @@ class CodeBattles(
|
|
|
1128
1134
|
return -1
|
|
1129
1135
|
|
|
1130
1136
|
try:
|
|
1137
|
+
if self.configure_breakpoint_by_time():
|
|
1138
|
+
return int(
|
|
1139
|
+
float(breakpoint_element.value) * self.configure_steps_per_second()
|
|
1140
|
+
)
|
|
1131
1141
|
return int(breakpoint_element.value)
|
|
1132
1142
|
except Exception:
|
|
1133
1143
|
return -1
|
|
@@ -1137,9 +1147,10 @@ class CodeBattles(
|
|
|
1137
1147
|
while self._should_play():
|
|
1138
1148
|
start = time.time()
|
|
1139
1149
|
try:
|
|
1140
|
-
self._step()
|
|
1150
|
+
await self._step()
|
|
1141
1151
|
except Exception:
|
|
1142
1152
|
traceback.print_exc()
|
|
1153
|
+
|
|
1143
1154
|
if not self.background:
|
|
1144
1155
|
await asyncio.sleep(
|
|
1145
1156
|
max(
|
|
@@ -1150,5 +1161,3 @@ class CodeBattles(
|
|
|
1150
1161
|
0,
|
|
1151
1162
|
)
|
|
1152
1163
|
)
|
|
1153
|
-
else:
|
|
1154
|
-
await asyncio.sleep(0.0005)
|
package/dist/esm/index.js
CHANGED
|
@@ -3031,6 +3031,7 @@ const Round = () => {
|
|
|
3031
3031
|
roundIterations !== 1 && (React.createElement("th", { style: { width: "35%" } }, "Results")),
|
|
3032
3032
|
React.createElement("th", null))),
|
|
3033
3033
|
React.createElement("tbody", null, rounds.map((round, index) => {
|
|
3034
|
+
var _a, _b;
|
|
3034
3035
|
const winCounts = {};
|
|
3035
3036
|
if (results[round.players.join(", ")] !== undefined) {
|
|
3036
3037
|
const currentResults = results[round.players.join(", ")][JSON.stringify(round.parameters)];
|
|
@@ -3053,9 +3054,9 @@ const Round = () => {
|
|
|
3053
3054
|
React.createElement("td", null, round.players.map((player, index) => (React.createElement("img", { key: index, src: `/images/teams/${player.toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } })))),
|
|
3054
3055
|
roundIterations === 1 && (React.createElement(React.Fragment, null,
|
|
3055
3056
|
React.createElement("td", null, results[round.players.join(", ")] !== undefined &&
|
|
3056
|
-
results[round.players.join(", ")][JSON.stringify(round.parameters)] !== undefined && (React.createElement("img", { src: `/images/teams/${round.players[results[round.players.join(", ")][JSON.stringify(round.parameters)][0][0]].toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } }))),
|
|
3057
|
+
results[round.players.join(", ")][JSON.stringify(round.parameters)] !== undefined && (React.createElement("img", { src: `/images/teams/${(_a = round.players[results[round.players.join(", ")][JSON.stringify(round.parameters)][0][0]]) === null || _a === void 0 ? void 0 : _a.toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } }))),
|
|
3057
3058
|
React.createElement("td", null, results[round.players.join(", ")] !== undefined &&
|
|
3058
|
-
results[round.players.join(", ")][JSON.stringify(round.parameters)] !== undefined && (React.createElement("img", { src: `/images/teams/${round.players[results[round.players.join(", ")][JSON.stringify(round.parameters)][0][1]].toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } }))))),
|
|
3059
|
+
results[round.players.join(", ")][JSON.stringify(round.parameters)] !== undefined && (React.createElement("img", { src: `/images/teams/${(_b = round.players[results[round.players.join(", ")][JSON.stringify(round.parameters)][0][1]]) === null || _b === void 0 ? void 0 : _b.toLowerCase()}.png`, width: 30, style: { marginInlineEnd: 10 } }))))),
|
|
3059
3060
|
roundIterations !== 1 && (React.createElement("td", null, winners.map((winner, index) => (React.createElement("p", { key: index },
|
|
3060
3061
|
winner,
|
|
3061
3062
|
": ",
|
package/package.json
CHANGED