graph-games-proto 0.3.1952__py3-none-any.whl → 0.3.1964__py3-none-any.whl

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.
graph_games_proto/fns.py CHANGED
@@ -1947,6 +1947,7 @@ class StateKernel(PClass):
1947
1947
  edgeuuid2idx = field(type=dict) # Dict[str, int]
1948
1948
  carduuid2card = field(type=dict) # Dict[str, Card]
1949
1949
  edgetuple2uuid = field(type=dict) # Dict[Tuple[int, int], str]
1950
+ nodeuuid2idx = field(type=dict) # Dict[str, int]
1950
1951
  def __todict__(self):
1951
1952
  return {
1952
1953
  "rng": rng2json(self.rng),
@@ -1963,6 +1964,7 @@ class StateKernel(PClass):
1963
1964
  "edgeuuid2idx": self.edgeuuid2idx,
1964
1965
  "carduuid2card": {k: v.__todict__() for k, v in self.carduuid2card.items()},
1965
1966
  "edgetuple2uuid": [{"k": list(k), "v": v} for k, v in self.edgetuple2uuid.items()],
1967
+ "nodeuuid2idx": self.nodeuuid2idx,
1966
1968
  }
1967
1969
  @staticmethod
1968
1970
  def __fromdict__(d):
@@ -1981,6 +1983,7 @@ class StateKernel(PClass):
1981
1983
  edgeuuid2idx=d["edgeuuid2idx"],
1982
1984
  carduuid2card={k: Card.__fromdict(v) for k, v in d["carduuid2card"].items()},
1983
1985
  edgetuple2uuid={tuple(item["k"]): item["v"] for item in d["edgetuple2uuid"]},
1986
+ nodeuuid2idx=d["nodeuuid2idx"],
1984
1987
  )
1985
1988
 
1986
1989
 
@@ -2032,6 +2035,7 @@ def init_state_kernel(**kwargs):
2032
2035
  carduuid2card=carduuid2card,
2033
2036
  pieceuuid2piece=pieceuuid2piece,
2034
2037
  edgetuple2uuid=edgetuple2uuid,
2038
+ nodeuuid2idx=nodeuuid2idx,
2035
2039
  )
2036
2040
 
2037
2041
 
@@ -2049,7 +2053,6 @@ class State(PClass):
2049
2053
  player_graphs = field(type=list) # List[PlayerGraph]
2050
2054
  goals = field(type=list) # List[Goal]
2051
2055
  nodes = field(type=list) # List[Node]
2052
- nodeuuid2idx = field(type=dict) # Dict[str, int]
2053
2056
  edges = field(type=list) # List[BiEdge]
2054
2057
  regions = field(type=list) # List[Region]
2055
2058
  legal_actions_3 = field(type=list) # List[LegalAction]
@@ -2057,7 +2060,6 @@ class State(PClass):
2057
2060
  players = field(type=list) # List[Player]
2058
2061
  player_idxs = field(type=list) # List[int]
2059
2062
  decks = field(type=list) # List[Deck]
2060
- game_config = field(type=GameConfig)
2061
2063
  rng = field(type=random.Random)
2062
2064
  last_to_play = field(type=(int, type(None)), initial=None)
2063
2065
  winners = field(type=list) # List[int]
@@ -2076,7 +2078,6 @@ class State(PClass):
2076
2078
  "player_graphs": [x.__todict__() for x in self.player_graphs],
2077
2079
  "goals": [goal.__todict__() for goal in self.goals],
2078
2080
  "nodes": [node.__todict__() for node in self.nodes],
2079
- "nodeuuid2idx": self.nodeuuid2idx,
2080
2081
  "edges": [edge.__todict__() for edge in self.edges],
2081
2082
  "regions": [region.__todict__() for region in self.regions],
2082
2083
  "legal_actions_3": [x.__todict__() for x in self.legal_actions_3],
@@ -2084,7 +2085,6 @@ class State(PClass):
2084
2085
  "players": [player.__todict__() for player in self.players],
2085
2086
  "player_idxs": self.player_idxs,
2086
2087
  "decks": [deck.__todict__() for deck in self.decks],
2087
- "game_config": self.game_config.__todict__(),
2088
2088
  "rng": rng2json(self.rng),
2089
2089
  "last_to_play": self.last_to_play,
2090
2090
  "winners": self.winners,
@@ -2105,7 +2105,6 @@ class State(PClass):
2105
2105
  player_graphs=[PlayerGraph.__fromdict__(x) for x in d["player_graphs"]],
2106
2106
  goals=[FrozenGoal.__fromdict__(goal) for goal in d["goals"]],
2107
2107
  nodes=[Node.__fromdict__(n) for n in d["nodes"]],
2108
- nodeuuid2idx=d["nodeuuid2idx"],
2109
2108
  edges=[BiEdge.__fromdict__(e) for e in d["edges"]],
2110
2109
  regions=[Region.__fromdict__(r) for r in d["regions"]],
2111
2110
  legal_actions_3=[LegalAction.__fromdict__(x) for x in d["legal_actions_3"]],
@@ -2113,7 +2112,6 @@ class State(PClass):
2113
2112
  players=[Player.__fromdict__(p) for p in d["players"]],
2114
2113
  player_idxs=d["player_idxs"],
2115
2114
  decks=[Deck.__fromdict__(deck) for deck in d["decks"]],
2116
- game_config=GameConfig.__fromdict__(d["game_config"]),
2117
2115
  rng=json2rng(d["rng"]),
2118
2116
  last_to_play=d.get("last_to_play"),
2119
2117
  winners=d["winners"],
@@ -2661,7 +2659,6 @@ def getinitialstate(game_config):
2661
2659
  ],
2662
2660
  goals = board_config.goals,
2663
2661
  nodes = nodes,
2664
- nodeuuid2idx = nodeuuid2idx,
2665
2662
  edges = edges,
2666
2663
  regions = get_regions(board_config),
2667
2664
  legal_actions_3=[],
@@ -2669,7 +2666,6 @@ def getinitialstate(game_config):
2669
2666
  players=[Player(idx=idx, pieces=[], cards=[], discard_tray=[]) for idx in range(game_config.num_players)],
2670
2667
  player_idxs=list(range(game_config.num_players)),
2671
2668
  decks=decks,
2672
- game_config=game_config,
2673
2669
  rng=rng,
2674
2670
  last_to_play=None,
2675
2671
  winners=[],
@@ -2679,7 +2675,7 @@ def getinitialstate(game_config):
2679
2675
 
2680
2676
  kernel = init_state_kernel(
2681
2677
  rng=rng,
2682
- game_config=state.game_config,
2678
+ game_config=game_config,
2683
2679
  edges=state.edges,
2684
2680
  decks=state.decks,
2685
2681
  piles=state.piles,
@@ -2722,14 +2718,14 @@ def run_state_action_hooks(state, action, hooks, log=False):
2722
2718
  )
2723
2719
 
2724
2720
 
2725
- def score_public_items(game, player_idx):
2721
+ def score_public_items(state, player_idx):
2726
2722
  items = []
2727
- for edge in game.edges:
2723
+ for edge in state.edges:
2728
2724
  for path in edge.paths:
2729
2725
  if len(path.segments) > 0:
2730
2726
  first_segment = path.segments[0]
2731
2727
  if first_segment.pieces and len(first_segment.pieces) > 0:
2732
- first_piece = game.pieceuuid2piece[first_segment.pieces[0]]
2728
+ first_piece = state.pieceuuid2piece[first_segment.pieces[0]]
2733
2729
  if first_piece.player_idx == player_idx:
2734
2730
  items.append(
2735
2731
  ScoreItem2(
@@ -2742,9 +2738,9 @@ def score_public_items(game, player_idx):
2742
2738
  description="Player {} owns edge {}".format(player_idx, edge.uuid),
2743
2739
  )
2744
2740
  )
2745
- for bonus_status in game.bonus_statuses:
2746
- bonus_idx = game.bonusuuid2bonusidx.get(bonus_status.bonus_uuid)
2747
- bonus = game.game_config.fig.board_config.bonuses[bonus_idx] if bonus_idx is not None else None
2741
+ for bonus_status in state.bonus_statuses:
2742
+ bonus_idx = state.bonusuuid2bonusidx.get(bonus_status.bonus_uuid)
2743
+ bonus = state.kernel.game_config.fig.board_config.bonuses[bonus_idx] if bonus_idx is not None else None
2748
2744
  if bonus:
2749
2745
  if player_idx in bonus_status.winners:
2750
2746
  items.append(
@@ -2836,13 +2832,13 @@ def calc_bonus_status(game, bonus):
2836
2832
  return None
2837
2833
 
2838
2834
 
2839
- def get_bonus_status_longest_trail(game, bonus):
2835
+ def get_bonus_status_longest_trail(state, bonus):
2840
2836
  longest_trail = 0
2841
2837
  winners = []
2842
2838
  player_longest_trail_lens = []
2843
2839
 
2844
- for player_idx in range(game.game_config.num_players):
2845
- trail_length = get_longest_path_length(game, player_idx)
2840
+ for player_idx in range(state.kernel.game_config.num_players):
2841
+ trail_length = get_longest_path_length(state, player_idx)
2846
2842
  player_longest_trail_lens.append(trail_length)
2847
2843
  if trail_length > longest_trail:
2848
2844
  longest_trail = trail_length
@@ -2868,14 +2864,14 @@ def get_bonus_status_longest_trail(game, bonus):
2868
2864
  )
2869
2865
 
2870
2866
 
2871
- def handle_bonus_statuses(game):
2867
+ def handle_bonus_statuses(state):
2872
2868
  bonus_statuses = [
2873
- calc_bonus_status(game, bonus)
2874
- for bonus in game.game_config.fig.board_config.bonuses
2869
+ calc_bonus_status(state, bonus)
2870
+ for bonus in state.kernel.game_config.fig.board_config.bonuses
2875
2871
  ]
2876
2872
  # Remove all None bonus statuses
2877
2873
  bonus_statuses = [bs for bs in bonus_statuses if bs is not None]
2878
- return game.set(bonus_statuses=bonus_statuses)
2874
+ return state.set(bonus_statuses=bonus_statuses)
2879
2875
 
2880
2876
 
2881
2877
  def default_handle_scoring(game):
@@ -3176,12 +3172,12 @@ def random_player_graph_walk(game, player_idx):
3176
3172
  return walk([random_start_node_idx], set([]))
3177
3173
 
3178
3174
 
3179
- def find_player_with_longest_path(game):
3175
+ def find_player_with_longest_path(state):
3180
3176
  longest_path_player_idx = None
3181
3177
  longest_path_length = 0
3182
3178
 
3183
- for player_idx in range(game.game_config.num_players):
3184
- path_length = get_longest_path_length(game, player_idx)
3179
+ for player_idx in range(state.kernel.game_config.num_players):
3180
+ path_length = get_longest_path_length(state, player_idx)
3185
3181
  if path_length > longest_path_length:
3186
3182
  longest_path_length = path_length
3187
3183
  longest_path_player_idx = player_idx
@@ -3189,7 +3185,7 @@ def find_player_with_longest_path(game):
3189
3185
  if longest_path_player_idx is None:
3190
3186
  return None
3191
3187
 
3192
- return game.players[longest_path_player_idx]
3188
+ return state.players[longest_path_player_idx]
3193
3189
 
3194
3190
 
3195
3191
  @dispatch(State, set)
@@ -3340,10 +3336,10 @@ def calc_player_graph(game, player_idx):
3340
3336
  )
3341
3337
 
3342
3338
 
3343
- def calc_player_graphs(game):
3344
- game_config = game.game_config
3339
+ def calc_player_graphs(state):
3340
+ game_config = state.kernel.game_config
3345
3341
  return [
3346
- calc_player_graph(game, player_idx)
3342
+ calc_player_graph(state, player_idx)
3347
3343
  for player_idx in range(game_config.num_players)
3348
3344
  ]
3349
3345
 
@@ -4094,7 +4090,7 @@ def getnextstate2(s, a, log=False):
4094
4090
 
4095
4091
  state_kernel = init_state_kernel(
4096
4092
  rng=s.rng,
4097
- game_config=s.game_config,
4093
+ game_config=s.kernel.game_config,
4098
4094
  edges=s.edges,
4099
4095
  decks=s.decks,
4100
4096
  piles=s.piles,
@@ -4468,19 +4464,10 @@ def get_goal_completions(s, player_idx):
4468
4464
  ]
4469
4465
 
4470
4466
 
4467
+ @dispatch(State, FrozenGoal, int)
4471
4468
  def is_goal_complete(s, goal, player_idx):
4472
4469
  graph = s.player_graphs[player_idx].neighbors
4473
- nodeuuid2idx = {node.uuid: node.idx for node in s.nodes}
4474
- node_idxs = [nodeuuid2idx[node_uuid] for node_uuid in goal.node_uuids]
4475
- if goal.uuid == "d9ef7d75-63d4-4ceb-adce-f889db3c75f0":
4476
- print("goal.uuid: ", goal.uuid)
4477
- print("goal.node_uuids: ", goal.node_uuids)
4478
- print(f"player: {player_idx} goal: ", goal.uuid)
4479
- print("graph: ", graph)
4480
- print("node_idxs: ", node_idxs)
4481
- print("are_nodes_connected(graph, node_idxs): ", are_nodes_connected(graph, node_idxs))
4482
- for node in s.nodes:
4483
- print(f"node: {node}")
4470
+ node_idxs = [s.kernel.nodeuuid2idx[node_uuid] for node_uuid in goal.node_uuids]
4484
4471
  return are_nodes_connected(
4485
4472
  graph,
4486
4473
  node_idxs,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graph_games_proto
3
- Version: 0.3.1952
3
+ Version: 0.3.1964
4
4
  Requires-Dist: multipledispatch==1.0.0
5
5
  Requires-Dist: pyrsistent==0.20.0
6
6
  Requires-Dist: numpy==2.2.4
@@ -1,9 +1,9 @@
1
1
  graph_games_proto/__init__.py,sha256=_EVQR-51XehfH45XZlba1WPdx3omS3Gm1nTwrgGyn2Q,667
2
2
  graph_games_proto/all_types.py,sha256=IpbwftEcHS5Ewz-saFNk0lO9FvcbuHG36odRTayCXUk,54911
3
- graph_games_proto/fns.py,sha256=k9npdHPzXr009dTSA_iJeTC7GiZj8TYohJlLyp1wULg,182582
3
+ graph_games_proto/fns.py,sha256=NBy2Ugs9XrIkerSWX6c9yshGiWJKg3P6KoehZa1iIOE,181978
4
4
  graph_games_proto/main.py,sha256=fj2U7KcwrpZtuUhjOX5yVxY18LZvvsxDFYZ_S5mxe04,145
5
5
  graph_games_proto/state.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- graph_games_proto-0.3.1952.dist-info/METADATA,sha256=5BHTXHDTovOFX5UTg17YNTXEHi2_Q1vTPpfCl6vJkwA,188
7
- graph_games_proto-0.3.1952.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
- graph_games_proto-0.3.1952.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
- graph_games_proto-0.3.1952.dist-info/RECORD,,
6
+ graph_games_proto-0.3.1964.dist-info/METADATA,sha256=B3PirCx5a9Pcc2dG8qv9uT3ErTjWCEE0oIqs7eVk2QI,188
7
+ graph_games_proto-0.3.1964.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
+ graph_games_proto-0.3.1964.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
+ graph_games_proto-0.3.1964.dist-info/RECORD,,