graph-games-proto 0.3.1752__py3-none-any.whl → 0.3.1756__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
@@ -2005,11 +2005,13 @@ class Segment2(PClass):
2005
2005
  class Path2(PClass):
2006
2006
  uuid = field(type=str)
2007
2007
  idx = field(type=int)
2008
+ edge_uuid = field(type=str)
2008
2009
  segments = field(type=list) # List[Segment]
2009
2010
  def __todict__(self):
2010
2011
  return {
2011
2012
  "uuid": self.uuid,
2012
2013
  "idx": self.idx,
2014
+ "edge_uuid": self.edge_uuid,
2013
2015
  "segments": [segment.__todict__() for segment in self.segments],
2014
2016
  }
2015
2017
  @staticmethod
@@ -2017,6 +2019,7 @@ class Path2(PClass):
2017
2019
  return Path2(
2018
2020
  uuid=d["uuid"],
2019
2021
  idx=d["idx"],
2022
+ edge_uuid=d["edge_uuid"],
2020
2023
  segments=[Segment2.__fromdict__(segment) for segment in d["segments"]],
2021
2024
  )
2022
2025
 
@@ -2358,21 +2361,43 @@ class PublicPlayerScore(PClass):
2358
2361
  items=[ScoreItem2.__fromdict__(x) for x in d["items"]],
2359
2362
  total=d["total"]
2360
2363
  )
2364
+
2365
+
2366
+ class ScoreItemOwnsPath(PClass):
2367
+ path_idx = field(type=int)
2368
+ edge_uuid = field(type=str)
2369
+ length = field(type=int)
2370
+ def __todict__(self):
2371
+ return {
2372
+ "path_idx": self.path_idx,
2373
+ "edge_uuid": self.edge_uuid,
2374
+ "length": self.length,
2375
+ }
2376
+ @staticmethod
2377
+ def __fromdict__(d):
2378
+ return ScoreItemOwnsPath(
2379
+ path_idx=d["path_idx"],
2380
+ edge_uuid=d["edge_uuid"],
2381
+ length=d["length"],
2382
+ )
2361
2383
 
2362
2384
 
2363
2385
  class ScoreItem2(PClass):
2364
2386
  amount = field(type=int)
2365
2387
  description = field(type=(str, type(None)), initial=None)
2388
+ owns_path = field(type=(ScoreItemOwnsPath, type(None)), initial=None) # Optional[ScoreItemOwnsPath]
2366
2389
  def __todict__(self):
2367
2390
  return {
2368
2391
  "amount": self.amount,
2369
2392
  "description": self.description,
2393
+ "owns_path": self.owns_path.__todict__() if self.owns_path else None,
2370
2394
  }
2371
2395
  @staticmethod
2372
2396
  def __fromdict__(d):
2373
2397
  return ScoreItem2(
2374
2398
  amount=d["amount"],
2375
- description=d.get("description") # Handle None case
2399
+ description=d.get("description"), # Handle None case
2400
+ owns_path=ScoreItemOwnsPath.__fromdict__(d["owns_path"]) if d.get("owns_path") else None
2376
2401
  )
2377
2402
 
2378
2403
 
@@ -2532,7 +2557,6 @@ class PublicState(PClass):
2532
2557
  decks = field(type=list) # List[PublicDeck]
2533
2558
  piles = field(type=list) # List[Pile]
2534
2559
  player_idxs = field(type=list) # List[int]
2535
- game_idx = field(type=int)
2536
2560
  initial_to_play = field(type=list) # List[int]
2537
2561
  to_play = field(type=list) # List[int]
2538
2562
  unit_discards = field(type=list) # List[int]
@@ -2605,7 +2629,6 @@ class PublicState(PClass):
2605
2629
  decks=[PublicDeck.__fromdict__(deck) for deck in d["decks"]],
2606
2630
  piles=[Pile.__fromdict__(x) for x in d["piles"]],
2607
2631
  player_idxs=d["player_idxs"],
2608
- game_idx=d["game_idx"],
2609
2632
  initial_to_play=d["initial_to_play"],
2610
2633
  to_play=d["to_play"],
2611
2634
  unit_discards=d["unit_discards"],
@@ -2694,7 +2717,12 @@ def get_edges(rng, board_config, nodeuuid2idx):
2694
2717
  segments = [
2695
2718
  Segment2(uuid=s.uuid, unit_uuid=s.unit_uuid, pieces=[]) for s in matching_board_path.path.segments
2696
2719
  ]
2697
- path = Path2(uuid=str(generate_uuid_with_rng(rng)), idx=path_idx, segments=segments)
2720
+ path = Path2(
2721
+ uuid=str(generate_uuid_with_rng(rng)),
2722
+ idx=path_idx,
2723
+ edge_uuid=link.uuid,
2724
+ segments=segments,
2725
+ )
2698
2726
  paths.append(path)
2699
2727
 
2700
2728
  if len(paths) == 0:
@@ -2979,7 +3007,15 @@ def score_public_items(game, player_idx):
2979
3007
  first_piece = game.pieceuuid2piece[first_segment.pieces[0]]
2980
3008
  if first_piece.player_idx == player_idx:
2981
3009
  items.append(
2982
- ScoreItem2(amount=edge.score, description="Player {} owns edge {}".format(player_idx, edge.uuid))
3010
+ ScoreItem2(
3011
+ amount=edge.score,
3012
+ owns_path=ScoreItemOwnsPath(
3013
+ path_idx=path.idx,
3014
+ edge_uuid=edge.uuid,
3015
+ length=len(path.segments),
3016
+ ),
3017
+ description="Player {} owns edge {}".format(player_idx, edge.uuid),
3018
+ )
2983
3019
  )
2984
3020
  for bonus_status in game.bonus_statuses:
2985
3021
  bonus_idx = game.bonusuuid2bonusidx.get(bonus_status.bonus_uuid)
@@ -2987,7 +3023,10 @@ def score_public_items(game, player_idx):
2987
3023
  if bonus:
2988
3024
  if player_idx in bonus_status.winners:
2989
3025
  items.append(
2990
- ScoreItem2(amount=bonus.score, description="Player {} wins bonus {}".format(player_idx, bonus.code))
3026
+ ScoreItem2(
3027
+ amount=bonus.score,
3028
+ description="Player {} wins bonus {}".format(player_idx, bonus.code),
3029
+ )
2991
3030
  )
2992
3031
  return items
2993
3032
 
@@ -3911,16 +3950,41 @@ def get_legal_actions_for_paths(game, player_idx):
3911
3950
  return legal_actions
3912
3951
 
3913
3952
 
3953
+ def get_player_idxs_on_edge(game, edge):
3954
+ player_idxs = set()
3955
+ if not edge or not edge.paths:
3956
+ return list(player_idxs)
3957
+
3958
+ for path in edge.paths:
3959
+ for segment in path.segments:
3960
+ if segment.pieces and segment.pieces[0]:
3961
+ piece = game.pieceuuid2piece.get(segment.pieces[0])
3962
+ if piece:
3963
+ player_idxs.add(piece.player_idx)
3964
+
3965
+ return list(player_idxs)
3966
+
3967
+
3914
3968
  def is_path_open_to_player(game, path_idx, player_idx):
3915
3969
 
3916
3970
  if not game or path_idx < 0 or get_total_path_count(game) <= path_idx:
3917
3971
  return False
3918
3972
 
3973
+ path = game.idx2path[path_idx]
3974
+ edge_idx = game.edgeuuid2idx[path.edge_uuid]
3975
+ edge = game.edges[edge_idx]
3976
+
3977
+ player_idxs_on_edge = get_player_idxs_on_edge(game, edge)
3978
+
3919
3979
  # Check if edge is too crowded for the number of players
3920
-
3980
+ if game.game_config.num_players <= 3:
3981
+ if len(player_idxs_on_edge) > 0:
3982
+ return False
3983
+
3984
+ if player_idx in player_idxs_on_edge:
3985
+ return False
3921
3986
 
3922
3987
  # Check if any segment of the path has pieces from any player
3923
- path = game.idx2path[path_idx]
3924
3988
  if path.segments[0].pieces:
3925
3989
  return False
3926
3990
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graph_games_proto
3
- Version: 0.3.1752
3
+ Version: 0.3.1756
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=O5XjRfe3DlxbJn4zezDvvy7cXvL4IzIRPZCL3Y-n7s8,776
2
2
  graph_games_proto/all_types.py,sha256=IpbwftEcHS5Ewz-saFNk0lO9FvcbuHG36odRTayCXUk,54911
3
- graph_games_proto/fns.py,sha256=CEs1hScC6_KPdLxWM13SrcunwYg4SICQPo2blYG7o_o,235957
3
+ graph_games_proto/fns.py,sha256=9eEpZsQCdHcRGNp1K-cfbpztqDEHxAA8pnleeRRAovE,238084
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.1752.dist-info/METADATA,sha256=ponF3VF7XgXC18_uuCgAWnm3jBlXhIA1RVeqDEPJS5Q,188
7
- graph_games_proto-0.3.1752.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
- graph_games_proto-0.3.1752.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
- graph_games_proto-0.3.1752.dist-info/RECORD,,
6
+ graph_games_proto-0.3.1756.dist-info/METADATA,sha256=FyQgp8JTxy5-lL1ictgC3444TV6pe2kWpDSC_FJYthg,188
7
+ graph_games_proto-0.3.1756.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
+ graph_games_proto-0.3.1756.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
+ graph_games_proto-0.3.1756.dist-info/RECORD,,