graph-games-proto 0.3.1937__py3-none-any.whl → 0.3.1953__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 +42 -49
- {graph_games_proto-0.3.1937.dist-info → graph_games_proto-0.3.1953.dist-info}/METADATA +1 -1
- {graph_games_proto-0.3.1937.dist-info → graph_games_proto-0.3.1953.dist-info}/RECORD +5 -5
- {graph_games_proto-0.3.1937.dist-info → graph_games_proto-0.3.1953.dist-info}/WHEEL +0 -0
- {graph_games_proto-0.3.1937.dist-info → graph_games_proto-0.3.1953.dist-info}/top_level.txt +0 -0
graph_games_proto/fns.py
CHANGED
@@ -1932,7 +1932,7 @@ class BonusStatus(PClass):
|
|
1932
1932
|
)
|
1933
1933
|
|
1934
1934
|
|
1935
|
-
class
|
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]
|
@@ -1947,6 +1947,7 @@ class StateKernal(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,10 +1964,11 @@ class StateKernal(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):
|
1969
|
-
return
|
1971
|
+
return StateKernel(
|
1970
1972
|
rng=json2rng(d["rng"]),
|
1971
1973
|
game_config=GameConfig.__fromdict__(d["game_config"]),
|
1972
1974
|
edges=[BiEdge.__fromdict__(edge) for edge in d["edges"]],
|
@@ -1981,6 +1983,7 @@ class StateKernal(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
|
|
@@ -2017,7 +2020,7 @@ def init_state_kernel(**kwargs):
|
|
2017
2020
|
edge_tuple = (min(node_1_idx, node_2_idx), max(node_1_idx, node_2_idx))
|
2018
2021
|
edgetuple2uuid[edge_tuple] = edge.uuid
|
2019
2022
|
|
2020
|
-
return
|
2023
|
+
return StateKernel(
|
2021
2024
|
rng=rng,
|
2022
2025
|
game_config=game_config,
|
2023
2026
|
edges=edges,
|
@@ -2032,11 +2035,12 @@ 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
|
|
2038
2042
|
class State(PClass):
|
2039
|
-
kernel = field(type=
|
2043
|
+
kernel = field(type=StateKernel)
|
2040
2044
|
idx2path = field(type=list) # List[Path2]
|
2041
2045
|
pieceuuid2piece = field(type=dict) # Dict[str, Piece]
|
2042
2046
|
bonus_statuses = field(type=list) # List[BonusStatus]
|
@@ -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]
|
@@ -2076,7 +2079,6 @@ class State(PClass):
|
|
2076
2079
|
"player_graphs": [x.__todict__() for x in self.player_graphs],
|
2077
2080
|
"goals": [goal.__todict__() for goal in self.goals],
|
2078
2081
|
"nodes": [node.__todict__() for node in self.nodes],
|
2079
|
-
"nodeuuid2idx": self.nodeuuid2idx,
|
2080
2082
|
"edges": [edge.__todict__() for edge in self.edges],
|
2081
2083
|
"regions": [region.__todict__() for region in self.regions],
|
2082
2084
|
"legal_actions_3": [x.__todict__() for x in self.legal_actions_3],
|
@@ -2092,7 +2094,7 @@ class State(PClass):
|
|
2092
2094
|
@staticmethod
|
2093
2095
|
def __fromdict__(d):
|
2094
2096
|
return State(
|
2095
|
-
kernel=
|
2097
|
+
kernel=StateKernel.__fromdict__(d["kernel"]),
|
2096
2098
|
idx2path=[Path2.__fromdict__(v) for v in d["idx2path"]],
|
2097
2099
|
pieceuuid2piece={k: Piece.__fromdict__(v) for k, v in d["pieceuuid2piece"].items()},
|
2098
2100
|
bonus_statuses=[BonusStatus.__fromdict__(x) for x in d["bonus_statuses"]],
|
@@ -2105,7 +2107,6 @@ class State(PClass):
|
|
2105
2107
|
player_graphs=[PlayerGraph.__fromdict__(x) for x in d["player_graphs"]],
|
2106
2108
|
goals=[FrozenGoal.__fromdict__(goal) for goal in d["goals"]],
|
2107
2109
|
nodes=[Node.__fromdict__(n) for n in d["nodes"]],
|
2108
|
-
nodeuuid2idx=d["nodeuuid2idx"],
|
2109
2110
|
edges=[BiEdge.__fromdict__(e) for e in d["edges"]],
|
2110
2111
|
regions=[Region.__fromdict__(r) for r in d["regions"]],
|
2111
2112
|
legal_actions_3=[LegalAction.__fromdict__(x) for x in d["legal_actions_3"]],
|
@@ -2661,7 +2662,6 @@ def getinitialstate(game_config):
|
|
2661
2662
|
],
|
2662
2663
|
goals = board_config.goals,
|
2663
2664
|
nodes = nodes,
|
2664
|
-
nodeuuid2idx = nodeuuid2idx,
|
2665
2665
|
edges = edges,
|
2666
2666
|
regions = get_regions(board_config),
|
2667
2667
|
legal_actions_3=[],
|
@@ -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
|
-
|
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 =
|
3201
|
-
edge_idx =
|
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 =
|
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(
|
3722
|
+
@dispatch(StateKernel)
|
3723
|
+
def get_wild_unit_uuids(state_kernel):
|
3723
3724
|
wild_unit_uuids = []
|
3724
|
-
for card in
|
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
|
-
|
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(
|
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
|
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(
|
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(
|
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
|
3757
|
-
first_wild_matching_idx = next((i for i, card_uuid in enumerate(new_cards) if
|
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(
|
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
|
-
|
3796
|
-
|
3797
|
-
|
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 =
|
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(
|
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(
|
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(
|
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(
|
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
|
|
@@ -4466,19 +4468,10 @@ def get_goal_completions(s, player_idx):
|
|
4466
4468
|
]
|
4467
4469
|
|
4468
4470
|
|
4471
|
+
@dispatch(State, FrozenGoal, int)
|
4469
4472
|
def is_goal_complete(s, goal, player_idx):
|
4470
4473
|
graph = s.player_graphs[player_idx].neighbors
|
4471
|
-
|
4472
|
-
node_idxs = [nodeuuid2idx[node_uuid] for node_uuid in goal.node_uuids]
|
4473
|
-
if goal.uuid == "d9ef7d75-63d4-4ceb-adce-f889db3c75f0":
|
4474
|
-
print("goal.uuid: ", goal.uuid)
|
4475
|
-
print("goal.node_uuids: ", goal.node_uuids)
|
4476
|
-
print(f"player: {player_idx} goal: ", goal.uuid)
|
4477
|
-
print("graph: ", graph)
|
4478
|
-
print("node_idxs: ", node_idxs)
|
4479
|
-
print("are_nodes_connected(graph, node_idxs): ", are_nodes_connected(graph, node_idxs))
|
4480
|
-
for node in s.nodes:
|
4481
|
-
print(f"node: {node}")
|
4474
|
+
node_idxs = [s.kernel.nodeuuid2idx[node_uuid] for node_uuid in goal.node_uuids]
|
4482
4475
|
return are_nodes_connected(
|
4483
4476
|
graph,
|
4484
4477
|
node_idxs,
|
@@ -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=
|
3
|
+
graph_games_proto/fns.py,sha256=Y880m_lmU6FCvxx4zowDu9Lrgcco4pOdDYYYQXzrQNY,182121
|
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.
|
7
|
-
graph_games_proto-0.3.
|
8
|
-
graph_games_proto-0.3.
|
9
|
-
graph_games_proto-0.3.
|
6
|
+
graph_games_proto-0.3.1953.dist-info/METADATA,sha256=ZAxOkRoFWLDz0NzLq1q15j0-FWw_gYTHWiqVvOH_Is8,188
|
7
|
+
graph_games_proto-0.3.1953.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
8
|
+
graph_games_proto-0.3.1953.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
|
9
|
+
graph_games_proto-0.3.1953.dist-info/RECORD,,
|
File without changes
|
File without changes
|