graph-games-proto 0.3.1937__py3-none-any.whl → 0.3.1952__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
@@ -1932,7 +1932,7 @@ class BonusStatus(PClass):
1932
1932
  )
1933
1933
 
1934
1934
 
1935
- class StateKernal(PClass):
1935
+ class StateKernel(PClass):
1936
1936
  rng = field(type=random.Random)
1937
1937
  game_config = field(type=GameConfig)
1938
1938
  edges = field(type=list) # List[BiEdge]
@@ -1966,7 +1966,7 @@ class StateKernal(PClass):
1966
1966
  }
1967
1967
  @staticmethod
1968
1968
  def __fromdict__(d):
1969
- return StateKernal(
1969
+ return StateKernel(
1970
1970
  rng=json2rng(d["rng"]),
1971
1971
  game_config=GameConfig.__fromdict__(d["game_config"]),
1972
1972
  edges=[BiEdge.__fromdict__(edge) for edge in d["edges"]],
@@ -2017,7 +2017,7 @@ def init_state_kernel(**kwargs):
2017
2017
  edge_tuple = (min(node_1_idx, node_2_idx), max(node_1_idx, node_2_idx))
2018
2018
  edgetuple2uuid[edge_tuple] = edge.uuid
2019
2019
 
2020
- return StateKernal(
2020
+ return StateKernel(
2021
2021
  rng=rng,
2022
2022
  game_config=game_config,
2023
2023
  edges=edges,
@@ -2036,7 +2036,7 @@ def init_state_kernel(**kwargs):
2036
2036
 
2037
2037
 
2038
2038
  class State(PClass):
2039
- kernel = field(type=StateKernal)
2039
+ kernel = field(type=StateKernel)
2040
2040
  idx2path = field(type=list) # List[Path2]
2041
2041
  pieceuuid2piece = field(type=dict) # Dict[str, Piece]
2042
2042
  bonus_statuses = field(type=list) # List[BonusStatus]
@@ -2092,7 +2092,7 @@ class State(PClass):
2092
2092
  @staticmethod
2093
2093
  def __fromdict__(d):
2094
2094
  return State(
2095
- kernel=StateKernal.__fromdict__(d["kernel"]),
2095
+ kernel=StateKernel.__fromdict__(d["kernel"]),
2096
2096
  idx2path=[Path2.__fromdict__(v) for v in d["idx2path"]],
2097
2097
  pieceuuid2piece={k: Piece.__fromdict__(v) for k, v in d["pieceuuid2piece"].items()},
2098
2098
  bonus_statuses=[BonusStatus.__fromdict__(x) for x in d["bonus_statuses"]],
@@ -3192,15 +3192,16 @@ def find_player_with_longest_path(game):
3192
3192
  return game.players[longest_path_player_idx]
3193
3193
 
3194
3194
 
3195
- def calc_path_len_from_edges(game, edge_tuples):
3195
+ @dispatch(State, set)
3196
+ def calc_path_len_from_edges(state, edge_tuples):
3196
3197
  if edge_tuples is None:
3197
3198
  return 0
3198
3199
  edge_lens = []
3199
3200
  for edge_tuple in edge_tuples:
3200
- edge_uuid = game.kernel.edgetuple2uuid.get(edge_tuple)
3201
- edge_idx = game.edgeuuid2idx.get(edge_uuid)
3201
+ edge_uuid = state.kernel.edgetuple2uuid.get(edge_tuple)
3202
+ edge_idx = state.kernel.edgeuuid2idx.get(edge_uuid)
3202
3203
  if edge_idx is not None:
3203
- edge = game.edges[edge_idx]
3204
+ edge = state.edges[edge_idx]
3204
3205
  if edge and edge.paths:
3205
3206
  first_path = edge.paths[0]
3206
3207
  edge_len = len(first_path.segments)
@@ -3568,7 +3569,7 @@ def is_move_pieces_to_path_action_legal(game, action):
3568
3569
  # print("******************************1234 is_move_pieces_to_path_action_legal 1d: ", len(remaining_segments))
3569
3570
 
3570
3571
  card_fulfillment, piece_fulfillment = get_path_fulfillment_from_resources(
3571
- game,
3572
+ game.kernel,
3572
3573
  proposed_cards,
3573
3574
  proposed_pieces,
3574
3575
  remaining_segments,
@@ -3718,24 +3719,25 @@ HOOK_NAMESPACE = {
3718
3719
  'ActionMovePiecesToPath': ActionMovePiecesToPathOptional,
3719
3720
  }
3720
3721
 
3721
-
3722
- def get_wild_unit_uuids(game):
3722
+ @dispatch(StateKernel)
3723
+ def get_wild_unit_uuids(state_kernel):
3723
3724
  wild_unit_uuids = []
3724
- for card in game.carduuid2card.values():
3725
+ for card in state_kernel.carduuid2card.values():
3725
3726
  if card.is_wild:
3726
3727
  wild_unit_uuids.append(card.resource_uuid)
3727
3728
  return wild_unit_uuids
3728
3729
 
3729
3730
 
3730
- def match_strict_wild(game, fulfillment, cards, segments):
3731
+ @dispatch(StateKernel, list, list, list)
3732
+ def match_strict_wild(state_kernel, fulfillment, cards, segments):
3731
3733
  new_fulfillment = fulfillment.copy()
3732
3734
  new_cards = cards.copy()
3733
- wild_unit_uuids = get_wild_unit_uuids(game)
3735
+ wild_unit_uuids = get_wild_unit_uuids(state_kernel)
3734
3736
  new_segments = []
3735
3737
 
3736
3738
  for segment in segments:
3737
3739
  if segment.unit_uuid and segment.unit_uuid in wild_unit_uuids:
3738
- first_matching_idx = next((i for i, card_uuid in enumerate(new_cards) if game.carduuid2card[card_uuid].resource_uuid == segment.unit_uuid), None)
3740
+ first_matching_idx = next((i for i, card_uuid in enumerate(new_cards) if state_kernel.carduuid2card[card_uuid].resource_uuid == segment.unit_uuid), None)
3739
3741
  if first_matching_idx is not None:
3740
3742
  new_fulfillment.append(new_cards.pop(first_matching_idx))
3741
3743
  else:
@@ -3745,16 +3747,16 @@ def match_strict_wild(game, fulfillment, cards, segments):
3745
3747
 
3746
3748
  return new_fulfillment, new_cards, new_segments
3747
3749
 
3748
-
3749
- def match_non_wild_non_empty(game, fulfillment, cards, segments, log=False):
3750
+ @dispatch(StateKernel, list, list, list)
3751
+ def match_non_wild_non_empty(state_kernel, fulfillment, cards, segments):
3750
3752
  new_fulfillment = fulfillment.copy()
3751
3753
  new_cards = cards.copy()
3752
- wild_unit_uuids = get_wild_unit_uuids(game)
3754
+ wild_unit_uuids = get_wild_unit_uuids(state_kernel)
3753
3755
  new_segments = []
3754
3756
 
3755
3757
  for segment in segments:
3756
- first_strict_matching_idx = next((i for i, card_uuid in enumerate(new_cards) if game.carduuid2card[card_uuid].resource_uuid == segment.unit_uuid), None)
3757
- first_wild_matching_idx = next((i for i, card_uuid in enumerate(new_cards) if game.carduuid2card[card_uuid].resource_uuid in wild_unit_uuids), None)
3758
+ first_strict_matching_idx = next((i for i, card_uuid in enumerate(new_cards) if state_kernel.carduuid2card[card_uuid].resource_uuid == segment.unit_uuid), None)
3759
+ first_wild_matching_idx = next((i for i, card_uuid in enumerate(new_cards) if state_kernel.carduuid2card[card_uuid].resource_uuid in wild_unit_uuids), None)
3758
3760
  first_matching_idx = first_strict_matching_idx if first_strict_matching_idx is not None else first_wild_matching_idx
3759
3761
  if first_matching_idx is not None:
3760
3762
  new_fulfillment.append(new_cards.pop(first_matching_idx))
@@ -3764,14 +3766,13 @@ def match_non_wild_non_empty(game, fulfillment, cards, segments, log=False):
3764
3766
  return new_fulfillment, new_cards, new_segments
3765
3767
 
3766
3768
 
3767
-
3768
-
3769
- def match_empty(game, fulfillment, cards, segments):
3769
+ @dispatch(StateKernel, list, list, list)
3770
+ def match_empty(state_kernel, fulfillment, cards, segments):
3770
3771
  num_empty_segments = sum(1 for segment in segments if segment.unit_uuid is None)
3771
3772
  if num_empty_segments == 0:
3772
3773
  return fulfillment, cards, segments
3773
3774
 
3774
- tuples = get_uniform_sets(game, cards, num_empty_segments)
3775
+ tuples = get_uniform_sets(state_kernel, cards, num_empty_segments)
3775
3776
  # print(f"****************************************** len(cards): {len(cards)}")
3776
3777
  # print(f"****************************************** num_empty_segments: {num_empty_segments}")
3777
3778
  # print(f"Found {len(tuples)} tuples for empty segments: {tuples}")
@@ -3792,15 +3793,16 @@ def match_empty(game, fulfillment, cards, segments):
3792
3793
  return new_fulfillment, new_cards, new_segments
3793
3794
 
3794
3795
 
3795
- def get_uniform_sets(game, cards, min_length):
3796
- wilds = [card_uuid for card_uuid in cards if game.carduuid2card[card_uuid].is_wild]
3797
- non_wilds = [card_uuid for card_uuid in cards if not game.carduuid2card[card_uuid].is_wild]
3796
+ @dispatch(StateKernel, list, int)
3797
+ def get_uniform_sets(state_kernel, cards, min_length):
3798
+ wilds = [card_uuid for card_uuid in cards if state_kernel.carduuid2card[card_uuid].is_wild]
3799
+ non_wilds = [card_uuid for card_uuid in cards if not state_kernel.carduuid2card[card_uuid].is_wild]
3798
3800
  # print("********************* cards: ", cards)
3799
3801
  # print("********************* wilds: ", wilds)
3800
3802
  # print("********************* non_wilds: ", non_wilds)
3801
3803
  unit_uuid_2_cards = {}
3802
3804
  for card_uuid in non_wilds:
3803
- card = game.carduuid2card[card_uuid]
3805
+ card = state_kernel.carduuid2card[card_uuid]
3804
3806
  if card.resource_uuid not in unit_uuid_2_cards:
3805
3807
  unit_uuid_2_cards[card.resource_uuid] = []
3806
3808
  unit_uuid_2_cards[card.resource_uuid].append(card_uuid)
@@ -3863,8 +3865,8 @@ def get_sample_path_fulfillment(game, player_idx, path_idx):
3863
3865
  remaining_segments,
3864
3866
  )
3865
3867
 
3866
-
3867
- def get_path_fulfillment_from_resources(game, remaining_card_uuids, remaining_pieces, remaining_segments, log=False):
3868
+ @dispatch(StateKernel, list, list, list)
3869
+ def get_path_fulfillment_from_resources(state_kernel, remaining_card_uuids, remaining_pieces, remaining_segments, log=False):
3868
3870
 
3869
3871
  if len(remaining_pieces) < len(remaining_segments):
3870
3872
  print("Not enough pieces to fulfill the path segments")
@@ -3873,7 +3875,7 @@ def get_path_fulfillment_from_resources(game, remaining_card_uuids, remaining_pi
3873
3875
  piece_fulfillment = remaining_pieces[:len(remaining_segments)]
3874
3876
 
3875
3877
  card_fulfillment = []
3876
- card_fulfillment, remaining_card_uuids, remaining_segments = match_strict_wild(game, card_fulfillment, remaining_card_uuids, remaining_segments)
3878
+ card_fulfillment, remaining_card_uuids, remaining_segments = match_strict_wild(state_kernel, card_fulfillment, remaining_card_uuids, remaining_segments)
3877
3879
 
3878
3880
  if len(remaining_segments) == 0:
3879
3881
  return card_fulfillment, piece_fulfillment
@@ -3881,14 +3883,14 @@ def get_path_fulfillment_from_resources(game, remaining_card_uuids, remaining_pi
3881
3883
  # elif len(get_wild_segments(remaining_segments)) > 0:
3882
3884
  # return None
3883
3885
 
3884
- card_fulfillment, remaining_card_uuids, remaining_segments = match_non_wild_non_empty(game, card_fulfillment, remaining_card_uuids, remaining_segments, log)
3886
+ card_fulfillment, remaining_card_uuids, remaining_segments = match_non_wild_non_empty(state_kernel, card_fulfillment, remaining_card_uuids, remaining_segments)
3885
3887
  if len(remaining_segments) == 0:
3886
3888
  return card_fulfillment, piece_fulfillment
3887
3889
  # Probably don't need this check, but we should unit test
3888
3890
  # elif len(get_non_wild_non_empty_segments(remaining_segments)) > 0:
3889
3891
  # return None
3890
3892
 
3891
- card_fulfillment, remaining_card_uuids, remaining_segments = match_empty(game, card_fulfillment, remaining_card_uuids, remaining_segments)
3893
+ card_fulfillment, remaining_card_uuids, remaining_segments = match_empty(state_kernel, card_fulfillment, remaining_card_uuids, remaining_segments)
3892
3894
  if len(remaining_segments) == 0:
3893
3895
  return card_fulfillment, piece_fulfillment
3894
3896
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graph_games_proto
3
- Version: 0.3.1937
3
+ Version: 0.3.1952
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=7Sub-734RnmdNZ2bR9r4b2dYjWdaTNcD8v6MxS6dBhQ,182190
3
+ graph_games_proto/fns.py,sha256=k9npdHPzXr009dTSA_iJeTC7GiZj8TYohJlLyp1wULg,182582
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.1937.dist-info/METADATA,sha256=L7F7-8wAqBVh6XrujYeaukSL2Lcn_xTOHKdVhDknwoQ,188
7
- graph_games_proto-0.3.1937.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
- graph_games_proto-0.3.1937.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
- graph_games_proto-0.3.1937.dist-info/RECORD,,
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,,