code-battles 1.7.9 → 1.7.11

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.
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import sys
2
4
 
3
5
  from code_battles.battles import CodeBattles
@@ -1,3 +1,7 @@
1
+ """Code Battles base class implementation."""
2
+
3
+ from __future__ import annotations
4
+
1
5
  import asyncio
2
6
  import base64
3
7
  import datetime
@@ -45,6 +49,7 @@ class Simulation:
45
49
  version: str
46
50
  timestamp: datetime.datetime
47
51
  logs: list
52
+ alerts: list
48
53
  decisions: List[bytes]
49
54
  seed: int
50
55
 
@@ -59,6 +64,7 @@ class Simulation:
59
64
  "version": self.version,
60
65
  "timestamp": self.timestamp.isoformat(),
61
66
  "logs": self.logs,
67
+ "alerts": self.alerts,
62
68
  "decisions": [
63
69
  base64.b64encode(decision).decode()
64
70
  for decision in self.decisions
@@ -81,6 +87,7 @@ class Simulation:
81
87
  contents["version"],
82
88
  datetime.datetime.fromisoformat(contents["timestamp"]),
83
89
  contents["logs"],
90
+ contents["alerts"],
84
91
  [base64.b64decode(decision) for decision in contents["decisions"]],
85
92
  contents["seed"],
86
93
  )
@@ -627,7 +634,8 @@ class CodeBattles(
627
634
  if command == "simulate":
628
635
  seed = None if sys.argv[2] == "None" else int(sys.argv[2])
629
636
  output_file = None if sys.argv[3] == "None" else sys.argv[3]
630
- self.map = sys.argv[4]
637
+ self.parameters = json.loads(sys.argv[4])
638
+ self.map = self.parameters.get("map")
631
639
  self.player_names = sys.argv[5].split("-")
632
640
  player_codes = []
633
641
  for filename in sys.argv[6:]:
@@ -652,15 +660,19 @@ class CodeBattles(
652
660
  self._initialize_simulation(player_codes, seed)
653
661
 
654
662
  all_logs = []
663
+ all_alerts = []
655
664
  while not self.over:
656
665
  print("__CODE_BATTLES_ADVANCE_STEP")
657
666
  if len(decisions) != 0:
658
667
  self.apply_decisions(decisions.pop(0))
659
668
  else:
660
669
  self._logs = []
670
+ self._alerts = []
661
671
  _decisions = self._make_decisions()
662
672
  all_logs.append(self._logs)
673
+ all_alerts.append(self._alerts)
663
674
  self._logs = []
675
+ self._alerts = []
664
676
  if output_file is not None:
665
677
  self._decisions.append(_decisions)
666
678
  self.apply_decisions(_decisions)
@@ -668,6 +680,7 @@ class CodeBattles(
668
680
  if not self.over:
669
681
  self.step += 1
670
682
  self._logs = all_logs
683
+ self._alerts = all_alerts
671
684
 
672
685
  print("--- SIMULATION FINISHED ---")
673
686
  print(
@@ -741,6 +754,7 @@ class CodeBattles(
741
754
  )
742
755
  self._decisions = simulation.decisions
743
756
  self._logs = simulation.logs
757
+ self._alerts = simulation.alerts
744
758
  self.canvas = GameCanvas(
745
759
  document.getElementById("simulation"),
746
760
  self.configure_board_count(),
@@ -852,6 +866,7 @@ class CodeBattles(
852
866
  self.configure_version(),
853
867
  datetime.datetime.now(),
854
868
  self._logs,
869
+ self._alerts,
855
870
  self._decisions,
856
871
  self._seed,
857
872
  )
@@ -908,8 +923,8 @@ class CodeBattles(
908
923
  "player_api": None,
909
924
  "context": context,
910
925
  **self.get_api().__dict__,
926
+ **self.configure_bot_globals(player_index),
911
927
  }
912
- | self.configure_bot_globals(player_index)
913
928
  for player_index, context in enumerate(contexts)
914
929
  ]
915
930
  for index, api_code in enumerate(player_codes):
@@ -1,5 +1,7 @@
1
1
  """Generic useful utilities for creating games with PyScript."""
2
2
 
3
+ from __future__ import annotations
4
+
3
5
  import asyncio
4
6
  import math
5
7
  import sys
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-battles",
3
- "version": "1.7.9",
3
+ "version": "1.7.11",
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",