code-battles 1.5.4 → 1.5.5
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/code_battles/battles.py +27 -14
- package/package.json +1 -1
|
@@ -530,13 +530,15 @@ class CodeBattles(
|
|
|
530
530
|
|
|
531
531
|
def _run_local_simulation(self):
|
|
532
532
|
command = sys.argv[1]
|
|
533
|
+
output_file = None
|
|
533
534
|
decisions = []
|
|
534
535
|
if command == "simulate":
|
|
535
536
|
seed = None if sys.argv[2] == "None" else int(sys.argv[2])
|
|
536
|
-
|
|
537
|
-
self.
|
|
537
|
+
output_file = None if sys.argv[3] == "None" else sys.argv[3]
|
|
538
|
+
self.map = sys.argv[4]
|
|
539
|
+
self.player_names = sys.argv[5].split("-")
|
|
538
540
|
player_codes = []
|
|
539
|
-
for filename in sys.argv[
|
|
541
|
+
for filename in sys.argv[6:]:
|
|
540
542
|
with open(filename, "r") as f:
|
|
541
543
|
player_codes.append(f.read())
|
|
542
544
|
elif command == "simulate-from-file":
|
|
@@ -561,7 +563,10 @@ class CodeBattles(
|
|
|
561
563
|
if len(decisions) != 0:
|
|
562
564
|
self.apply_decisions(decisions.pop(0))
|
|
563
565
|
else:
|
|
564
|
-
self.
|
|
566
|
+
_decisions = self.make_decisions()
|
|
567
|
+
if output_file is not None:
|
|
568
|
+
self._decisions.append(_decisions)
|
|
569
|
+
self.apply_decisions(_decisions)
|
|
565
570
|
|
|
566
571
|
if not self.over:
|
|
567
572
|
self.step += 1
|
|
@@ -582,6 +587,11 @@ class CodeBattles(
|
|
|
582
587
|
)
|
|
583
588
|
)
|
|
584
589
|
|
|
590
|
+
if output_file is not None:
|
|
591
|
+
simulation_str = self._get_simulation().dump()
|
|
592
|
+
with open(output_file, "w") as f:
|
|
593
|
+
f.write(simulation_str)
|
|
594
|
+
|
|
585
595
|
def _start_simulation(self, *args, **kwargs):
|
|
586
596
|
loop = asyncio.get_event_loop()
|
|
587
597
|
loop.run_until_complete(self._start_simulation_async(*args, **kwargs))
|
|
@@ -719,6 +729,18 @@ class CodeBattles(
|
|
|
719
729
|
except Exception:
|
|
720
730
|
traceback.print_exc()
|
|
721
731
|
|
|
732
|
+
def _get_simulation(self):
|
|
733
|
+
return Simulation(
|
|
734
|
+
self.map,
|
|
735
|
+
self.player_names,
|
|
736
|
+
self.__class__.__name__,
|
|
737
|
+
self.configure_version(),
|
|
738
|
+
datetime.datetime.now(),
|
|
739
|
+
self._logs,
|
|
740
|
+
self._decisions,
|
|
741
|
+
self._seed,
|
|
742
|
+
)
|
|
743
|
+
|
|
722
744
|
def _update_step(self, decisions_str: str, logs_str: str, is_over_str: str):
|
|
723
745
|
from js import window, document
|
|
724
746
|
|
|
@@ -732,16 +754,7 @@ class CodeBattles(
|
|
|
732
754
|
|
|
733
755
|
if is_over:
|
|
734
756
|
try:
|
|
735
|
-
simulation =
|
|
736
|
-
self.map,
|
|
737
|
-
self.player_names,
|
|
738
|
-
self.__class__.__name__,
|
|
739
|
-
self.configure_version(),
|
|
740
|
-
datetime.datetime.now(),
|
|
741
|
-
self._logs,
|
|
742
|
-
self._decisions,
|
|
743
|
-
self._seed,
|
|
744
|
-
)
|
|
757
|
+
simulation = self._get_simulation()
|
|
745
758
|
window.simulationToDownload = simulation.dump()
|
|
746
759
|
show_download()
|
|
747
760
|
except Exception as e:
|
package/package.json
CHANGED