graph-games-proto 0.3.1699__py3-none-any.whl → 0.3.1700__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
@@ -2003,16 +2003,19 @@ class Segment2(PClass):
2003
2003
 
2004
2004
 
2005
2005
  class Path2(PClass):
2006
+ uuid = field(type=str)
2006
2007
  idx = field(type=int)
2007
2008
  segments = field(type=list) # List[Segment]
2008
2009
  def __todict__(self):
2009
2010
  return {
2011
+ "uuid": self.uuid,
2010
2012
  "idx": self.idx,
2011
2013
  "segments": [segment.__todict__() for segment in self.segments],
2012
2014
  }
2013
2015
  @staticmethod
2014
2016
  def __fromdict__(d):
2015
2017
  return Path2(
2018
+ uuid=d["uuid"],
2016
2019
  idx=d["idx"],
2017
2020
  segments=[Segment2.__fromdict__(segment) for segment in d["segments"]],
2018
2021
  )
@@ -2148,6 +2151,9 @@ class BonusStatus(PClass):
2148
2151
 
2149
2152
 
2150
2153
  class State(PClass):
2154
+ uuid2edge = field(type=dict) # Dict[str, BiEdge]
2155
+ uuid2path = field(type=dict) # Dict[str, Path2]
2156
+ uuid2segment = field(type=dict) # Dict[str, Segment]
2151
2157
  pieceuuid2piece = field(type=dict) # Dict[str, Piece]
2152
2158
  carduuid2card = field(type=dict) # Dict[str, Card]
2153
2159
  final_scores = field(type=(list, type(None)), initial=None) # Optional[List[int]]
@@ -2189,6 +2195,9 @@ class State(PClass):
2189
2195
  # market_refills::Vector{MarketRefill}
2190
2196
  def __todict__(self):
2191
2197
  return {
2198
+ "uuid2edge": {k: v.__todict__() for k, v in self.uuid2edge.items()},
2199
+ "uuid2path": {k: v.__todict__() for k, v in self.uuid2path.items()},
2200
+ "uuid2segment": {k: v.__todict__() for k, v in self.uuid2segment.items()},
2192
2201
  "pieceuuid2piece": {k: v.__todict__() for k, v in self.pieceuuid2piece.items()},
2193
2202
  "carduuid2card": {k: v.__todict__() for k, v in self.carduuid2card.items()},
2194
2203
  "final_scores": self.final_scores,
@@ -2231,6 +2240,9 @@ class State(PClass):
2231
2240
  @staticmethod
2232
2241
  def __fromdict__(d):
2233
2242
  return State(
2243
+ uuid2edge={k: BiEdge.__fromdict__(v) for k, v in d["uuid2edge"].items()},
2244
+ uuid2path={k: Path2.__fromdict__(v) for k, v in d["uuid2path"].items()},
2245
+ uuid2segment={k: Segment2.__fromdict__(v) for k, v in d["uuid2segment"].items()},
2234
2246
  pieceuuid2piece={k: Piece.__fromdict__(v) for k, v in d["pieceuuid2piece"].items()},
2235
2247
  carduuid2card={k: Card.__fromdict__(v) for k, v in d["carduuid2card"].items()},
2236
2248
  final_scores=d["final_scores"],
@@ -2688,7 +2700,7 @@ def get_nodes(board_config):
2688
2700
  return []
2689
2701
 
2690
2702
 
2691
- def get_edges(board_config, nodeuuid2idx):
2703
+ def get_edges(rng, board_config, nodeuuid2idx):
2692
2704
  edges = []
2693
2705
 
2694
2706
 
@@ -2703,7 +2715,7 @@ def get_edges(board_config, nodeuuid2idx):
2703
2715
  segments = [
2704
2716
  Segment2(uuid=s.uuid, pieces=[]) for s in matching_board_path.path.segments
2705
2717
  ]
2706
- path = Path2(idx=path_idx, segments=segments)
2718
+ path = Path2(uuid=str(generate_uuid_with_rng(rng)), idx=path_idx, segments=segments)
2707
2719
  paths.append(path)
2708
2720
 
2709
2721
  if len(paths) == 0:
@@ -2814,6 +2826,17 @@ def getinitialstate(game_config):
2814
2826
  deck_1_rng = getrng(8738758)
2815
2827
  nodes = get_nodes(board_config)
2816
2828
 
2829
+ uuid2edge = {}
2830
+ uuid2path = {}
2831
+ uuid2segment = {}
2832
+
2833
+ for edge in edges:
2834
+ uuid2edge[edge.uuid] = edge
2835
+ for path in edge.paths:
2836
+ uuid2path[path.uuid] = path
2837
+ for segment in path.segments:
2838
+ uuid2segment[segment.uuid] = segment
2839
+
2817
2840
  pieceuuid2piece = {}
2818
2841
  piles = []
2819
2842
  for piece_template in board_config.piece_templates:
@@ -2848,7 +2871,7 @@ def getinitialstate(game_config):
2848
2871
  decks.append(deck_obj)
2849
2872
 
2850
2873
  nodeuuid2idx = {node.uuid: idx for idx, node in enumerate(board_config.points)}
2851
- edges = get_edges(board_config, nodeuuid2idx)
2874
+ edges = get_edges(rng, board_config, nodeuuid2idx)
2852
2875
  edgeuuid2idx = {edge.uuid: idx for idx, edge in enumerate(edges)}
2853
2876
  edgetuple2uuid = {}
2854
2877
  for edge in edges:
@@ -2876,6 +2899,9 @@ def getinitialstate(game_config):
2876
2899
  ]
2877
2900
 
2878
2901
  state = State(
2902
+ uuid2edge=uuid2edge,
2903
+ uuid2path=uuid2path,
2904
+ uuid2segment=uuid2segment,
2879
2905
  pieceuuid2piece=pieceuuid2piece,
2880
2906
  carduuid2card=carduuid2card,
2881
2907
  final_scores=None,
@@ -3864,7 +3890,7 @@ def append_default_legal_actions_for_next_player(game, action, log=False):
3864
3890
 
3865
3891
 
3866
3892
  def get_total_path_count(game):
3867
- return sum(len(edge.paths) for edge in game.edges)
3893
+ return len(game.uuid2path.values())
3868
3894
 
3869
3895
 
3870
3896
  def get_legal_actions_for_path(game, player_idx, path_idx):
@@ -3873,9 +3899,6 @@ def get_legal_actions_for_path(game, player_idx, path_idx):
3873
3899
 
3874
3900
  if not is_path_open_to_player(game, path_idx, player_idx):
3875
3901
  return []
3876
-
3877
- # TODO check if player has enough pieces to claim the path
3878
- player_pieces = game.players[player_idx].pieces
3879
3902
 
3880
3903
  legal_actions = []
3881
3904
  default = get_sample_actionclaimpath(game, player_idx, path_idx)
@@ -3914,11 +3937,13 @@ def get_legal_actions_for_paths(game, player_idx):
3914
3937
 
3915
3938
 
3916
3939
  def is_path_open_to_player(game, path_idx, player_idx):
3917
- # TODO check if player has enough pieces to claim the path
3918
3940
 
3919
3941
  if not game or path_idx < 0 or path_idx >= get_total_path_count(game):
3920
3942
  return False
3921
3943
 
3944
+ # Check if edge is too crowded for the number of players
3945
+
3946
+
3922
3947
  # Check if any segment of the path has pieces from any player
3923
3948
  path = get_path_by_idx(game, path_idx)
3924
3949
  if path.segments[0].pieces:
@@ -7073,7 +7098,7 @@ def get_imagined_state(static_board_config, player_state):
7073
7098
 
7074
7099
 
7075
7100
  nodeuuid2idx = {node.uuid: idx for idx, node in enumerate(board_config.points)}
7076
- edges = get_edges(board_config, nodeuuid2idx)
7101
+ edges = get_edges(rng, board_config, nodeuuid2idx)
7077
7102
  edgeuuid2idx = {edge.uuid: idx for idx, edge in enumerate(edges)}
7078
7103
  edgetuple2uuid = {}
7079
7104
  for edge in edges:
@@ -7087,7 +7112,7 @@ def get_imagined_state(static_board_config, player_state):
7087
7112
  player_graphs = [],
7088
7113
  nodes = get_nodes(board_config),
7089
7114
  nodeuuid2idx = nodeuuid2idx,
7090
- edges = get_edges(board_config, nodeuuid2idx),
7115
+ edges = edges,
7091
7116
  edgeuuid2idx = edgeuuid2idx,
7092
7117
  edgetuple2uuid = edgetuple2uuid,
7093
7118
  regions = get_regions(board_config),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graph_games_proto
3
- Version: 0.3.1699
3
+ Version: 0.3.1700
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=LOpk1mGZxPWMRGrPNoXDENn7JPG6rNfhieehItW8bEA,881
2
2
  graph_games_proto/all_types.py,sha256=IpbwftEcHS5Ewz-saFNk0lO9FvcbuHG36odRTayCXUk,54911
3
- graph_games_proto/fns.py,sha256=_1TSlhRwtpwLbk5bHKrLPv_sHHSbWPCBwJ50kezzw6g,263497
3
+ graph_games_proto/fns.py,sha256=QDewUyasIGcpavrEdAcnEDwZtJq0YRBzoTjPIDQUC14,264542
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.1699.dist-info/METADATA,sha256=BKDzvlucWgKvaWmzobi-y_mAVwUULSKpMR6JoQHDFD4,188
7
- graph_games_proto-0.3.1699.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
- graph_games_proto-0.3.1699.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
- graph_games_proto-0.3.1699.dist-info/RECORD,,
6
+ graph_games_proto-0.3.1700.dist-info/METADATA,sha256=MZ4Kcxgx7QiPgfsPk4urx0lxB-2tMQYu-sX5q6tS-6s,188
7
+ graph_games_proto-0.3.1700.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
+ graph_games_proto-0.3.1700.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
+ graph_games_proto-0.3.1700.dist-info/RECORD,,