graph-games-proto 0.3.1916__py3-none-any.whl → 0.3.1918__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 +116 -83
- {graph_games_proto-0.3.1916.dist-info → graph_games_proto-0.3.1918.dist-info}/METADATA +1 -1
- {graph_games_proto-0.3.1916.dist-info → graph_games_proto-0.3.1918.dist-info}/RECORD +5 -5
- {graph_games_proto-0.3.1916.dist-info → graph_games_proto-0.3.1918.dist-info}/WHEEL +0 -0
- {graph_games_proto-0.3.1916.dist-info → graph_games_proto-0.3.1918.dist-info}/top_level.txt +0 -0
graph_games_proto/fns.py
CHANGED
@@ -1932,10 +1932,98 @@ class BonusStatus(PClass):
|
|
1932
1932
|
)
|
1933
1933
|
|
1934
1934
|
|
1935
|
+
class StateKernal(PClass):
|
1936
|
+
rng = field(type=random.Random)
|
1937
|
+
game_config = field(type=GameConfig)
|
1938
|
+
edges = field(type=list) # List[BiEdge]
|
1939
|
+
decks = field(type=list) # List[Deck]
|
1940
|
+
piles = field(type=list) # List[Pile]
|
1941
|
+
players = field(type=list) # List[Player]
|
1942
|
+
player_idxs = field(type=list) # List[int]
|
1943
|
+
history = field(type=list) # List[PublicAction]
|
1944
|
+
player_scores = field(type=list) # List[PlayerScore]
|
1945
|
+
idx2path = field(type=list) # List[Path2]
|
1946
|
+
pieceuuid2piece = field(type=dict) # Dict[str, Piece]
|
1947
|
+
edgeuuid2idx = field(type=dict) # Dict[str, int]
|
1948
|
+
carduuid2card = field(type=dict) # Dict[str, Card]
|
1949
|
+
def __todict__(self):
|
1950
|
+
return {
|
1951
|
+
"rng": rng2json(self.rng),
|
1952
|
+
"game_config": self.game_config.__todict__(),
|
1953
|
+
"edges": [edge.__todict__() for edge in self.edges],
|
1954
|
+
"decks": [deck.__todict__() for deck in self.decks],
|
1955
|
+
"piles": [pile.__todict__() for pile in self.piles],
|
1956
|
+
"players": [player.__todict__() for player in self.players],
|
1957
|
+
"player_idxs": self.player_idxs,
|
1958
|
+
"history": [action.__todict__() for action in self.history],
|
1959
|
+
"player_scores": [score.__todict__() for score in self.player_scores],
|
1960
|
+
"idx2path": [v.__todict__() for v in self.idx2path],
|
1961
|
+
"pieceuuid2piece": {k: v.__todict__() for k, v in self.pieceuuid2piece.items()},
|
1962
|
+
"edgeuuid2idx": self.edgeuuid2idx,
|
1963
|
+
"carduuid2card": {k: v.__todict__() for k, v in self.carduuid2card.items()},
|
1964
|
+
}
|
1965
|
+
@staticmethod
|
1966
|
+
def __fromdict__(d):
|
1967
|
+
return StateKernal(
|
1968
|
+
rng=json2rng(d["rng"]),
|
1969
|
+
game_config=GameConfig.__fromdict__(d["game_config"]),
|
1970
|
+
edges=[BiEdge.__fromdict__(edge) for edge in d["edges"]],
|
1971
|
+
decks=[Deck.__fromdict__(deck) for deck in d["decks"]],
|
1972
|
+
piles=[Pile.__fromdict__(pile) for pile in d["piles"]],
|
1973
|
+
players=[Player.__fromdict__(player) for player in d["players"]],
|
1974
|
+
player_idxs=d["player_idxs"],
|
1975
|
+
history=[PublicAction.__fromdict__(action) for action in d["history"]],
|
1976
|
+
player_scores=[PlayerScore.__fromdict__(score) for score in d["player_scores"]],
|
1977
|
+
idx2path=[Path2.__fromdict(v) for v in d["idx2path"]],
|
1978
|
+
pieceuuid2piece={k: Piece.__fromdict(v) for k, v in d["pieceuuid2piece"].items()},
|
1979
|
+
edgeuuid2idx=d["edgeuuid2idx"],
|
1980
|
+
carduuid2card={k: Card.__fromdict(v) for k, v in d["carduuid2card"].items()},
|
1981
|
+
)
|
1982
|
+
|
1983
|
+
|
1984
|
+
def init_state_kernal(**kwargs):
|
1985
|
+
game_config = kwargs.get('game_config')
|
1986
|
+
fig = game_config.fig
|
1987
|
+
board_config = fig.board_config
|
1988
|
+
edges = kwargs.get('edges', [])
|
1989
|
+
idx2path = []
|
1990
|
+
edgeuuid2idx = {edge.uuid: idx for idx, edge in enumerate(edges)}
|
1991
|
+
for edge in edges:
|
1992
|
+
for path in edge.paths:
|
1993
|
+
idx2path.append(path)
|
1994
|
+
pieceuuid2piece = {}
|
1995
|
+
for piece_template in board_config.piece_templates:
|
1996
|
+
if piece_template.has_player:
|
1997
|
+
for player_idx in range(game_config.num_players):
|
1998
|
+
pieces = generate_pieces(piece_template, player_idx)
|
1999
|
+
for piece in pieces:
|
2000
|
+
pieceuuid2piece[piece.uuid] = piece
|
2001
|
+
carduuid2card = {}
|
2002
|
+
for dek in board_config.deks:
|
2003
|
+
cards = generate_cards(dek)
|
2004
|
+
for card in cards:
|
2005
|
+
carduuid2card[card.uuid] = card
|
2006
|
+
|
2007
|
+
return StateKernal(
|
2008
|
+
rng=kwargs.get('rng'),
|
2009
|
+
game_config=game_config,
|
2010
|
+
edges=edges,
|
2011
|
+
decks=kwargs.get('decks'),
|
2012
|
+
piles=kwargs.get('piles'),
|
2013
|
+
players=kwargs.get('players'),
|
2014
|
+
player_idxs=kwargs.get('player_idxs'),
|
2015
|
+
history=kwargs.get('history'),
|
2016
|
+
player_scores=kwargs.get('player_scores'),
|
2017
|
+
idx2path=idx2path,
|
2018
|
+
edgeuuid2idx=edgeuuid2idx,
|
2019
|
+
carduuid2card=carduuid2card,
|
2020
|
+
pieceuuid2piece=pieceuuid2piece,
|
2021
|
+
)
|
2022
|
+
|
2023
|
+
|
1935
2024
|
class State(PClass):
|
1936
|
-
|
2025
|
+
kernal = field(type=StateKernal)
|
1937
2026
|
idx2path = field(type=list) # List[Path2]
|
1938
|
-
uuid2segment = field(type=dict) # Dict[str, Segment]
|
1939
2027
|
pieceuuid2piece = field(type=dict) # Dict[str, Piece]
|
1940
2028
|
carduuid2card = field(type=dict) # Dict[str, Card]
|
1941
2029
|
bonus_statuses = field(type=list) # List[BonusStatus]
|
@@ -1964,9 +2052,8 @@ class State(PClass):
|
|
1964
2052
|
winners = field(type=list) # List[int]
|
1965
2053
|
def __todict__(self):
|
1966
2054
|
return {
|
1967
|
-
"
|
2055
|
+
"kernal": self.kernal.__todict__(),
|
1968
2056
|
"idx2path": [v.__todict__() for v in self.idx2path],
|
1969
|
-
"uuid2segment": {k: v.__todict__() for k, v in self.uuid2segment.items()},
|
1970
2057
|
"pieceuuid2piece": {k: v.__todict__() for k, v in self.pieceuuid2piece.items()},
|
1971
2058
|
"carduuid2card": {k: v.__todict__() for k, v in self.carduuid2card.items()},
|
1972
2059
|
"bonus_statuses": [status.__todict__() for status in self.bonus_statuses],
|
@@ -1997,9 +2084,8 @@ class State(PClass):
|
|
1997
2084
|
@staticmethod
|
1998
2085
|
def __fromdict__(d):
|
1999
2086
|
return State(
|
2000
|
-
|
2087
|
+
kernal=StateKernal.__fromdict__(d["kernal"]),
|
2001
2088
|
idx2path=[Path2.__fromdict__(v) for v in d["idx2path"]],
|
2002
|
-
uuid2segment={k: Segment2.__fromdict__(v) for k, v in d["uuid2segment"].items()},
|
2003
2089
|
pieceuuid2piece={k: Piece.__fromdict__(v) for k, v in d["pieceuuid2piece"].items()},
|
2004
2090
|
carduuid2card={k: Card.__fromdict__(v) for k, v in d["carduuid2card"].items()},
|
2005
2091
|
bonus_statuses=[BonusStatus.__fromdict__(x) for x in d["bonus_statuses"]],
|
@@ -2533,17 +2619,11 @@ def getinitialstate(game_config):
|
|
2533
2619
|
edge_tuple = (min(node_1_idx, node_2_idx), max(node_1_idx, node_2_idx))
|
2534
2620
|
edgetuple2uuid[edge_tuple] = edge.uuid
|
2535
2621
|
|
2536
|
-
|
2537
|
-
uuid2edge = {}
|
2538
2622
|
idx2path = []
|
2539
|
-
uuid2segment = {}
|
2540
2623
|
|
2541
2624
|
for edge in edges:
|
2542
|
-
uuid2edge[edge.uuid] = edge
|
2543
2625
|
for path in edge.paths:
|
2544
2626
|
idx2path.append(path)
|
2545
|
-
for segment in path.segments:
|
2546
|
-
uuid2segment[segment.uuid] = segment
|
2547
2627
|
|
2548
2628
|
bonuses = game_config.fig.board_config.bonuses
|
2549
2629
|
bonusuuid2bonusidx = {bonus.uuid: idx for idx, bonus in enumerate(bonuses)}
|
@@ -2564,9 +2644,7 @@ def getinitialstate(game_config):
|
|
2564
2644
|
]
|
2565
2645
|
|
2566
2646
|
state = State(
|
2567
|
-
uuid2edge=uuid2edge,
|
2568
2647
|
idx2path=idx2path,
|
2569
|
-
uuid2segment=uuid2segment,
|
2570
2648
|
pieceuuid2piece=pieceuuid2piece,
|
2571
2649
|
carduuid2card=carduuid2card,
|
2572
2650
|
bonus_statuses=bonus_statuses,
|
@@ -2606,7 +2684,7 @@ def getinitialstate(game_config):
|
|
2606
2684
|
|
2607
2685
|
state = run_state_hooks(state, INITIALIZATION_HOOKS, True)
|
2608
2686
|
|
2609
|
-
|
2687
|
+
kernal = init_state_kernal(
|
2610
2688
|
rng=rng,
|
2611
2689
|
game_config=state.game_config,
|
2612
2690
|
edges=state.edges,
|
@@ -2617,7 +2695,9 @@ def getinitialstate(game_config):
|
|
2617
2695
|
history=state.history,
|
2618
2696
|
player_scores=state.player_scores,
|
2619
2697
|
)
|
2620
|
-
|
2698
|
+
|
2699
|
+
state = state.set(kernal=kernal)
|
2700
|
+
state = state.set(legal_actions_3=calc_legal_actions3(kernal))
|
2621
2701
|
|
2622
2702
|
return state
|
2623
2703
|
|
@@ -4142,69 +4222,26 @@ def get_next_player_shuffled_idx(state_kernal, last_action):
|
|
4142
4222
|
return next_player_shuffled_idx
|
4143
4223
|
|
4144
4224
|
|
4145
|
-
|
4146
|
-
|
4147
|
-
|
4148
|
-
|
4149
|
-
|
4150
|
-
|
4151
|
-
|
4152
|
-
|
4153
|
-
|
4154
|
-
|
4155
|
-
|
4156
|
-
|
4157
|
-
|
4158
|
-
|
4159
|
-
|
4160
|
-
|
4161
|
-
|
4162
|
-
|
4163
|
-
def init_state_kernal(**kwargs):
|
4164
|
-
game_config = kwargs.get('game_config')
|
4165
|
-
fig = game_config.fig
|
4166
|
-
board_config = fig.board_config
|
4167
|
-
edges = kwargs.get('edges', [])
|
4168
|
-
uuid2edge = {}
|
4169
|
-
idx2path = []
|
4170
|
-
uuid2segment = {}
|
4171
|
-
edgeuuid2idx = {edge.uuid: idx for idx, edge in enumerate(edges)}
|
4172
|
-
for edge in edges:
|
4173
|
-
uuid2edge[edge.uuid] = edge
|
4174
|
-
for path in edge.paths:
|
4175
|
-
idx2path.append(path)
|
4176
|
-
for segment in path.segments:
|
4177
|
-
uuid2segment[segment.uuid] = segment
|
4178
|
-
pieceuuid2piece = {}
|
4179
|
-
for piece_template in board_config.piece_templates:
|
4180
|
-
if piece_template.has_player:
|
4181
|
-
for player_idx in range(game_config.num_players):
|
4182
|
-
pieces = generate_pieces(piece_template, player_idx)
|
4183
|
-
for piece in pieces:
|
4184
|
-
pieceuuid2piece[piece.uuid] = piece
|
4185
|
-
carduuid2card = {}
|
4186
|
-
for dek in board_config.deks:
|
4187
|
-
cards = generate_cards(dek)
|
4188
|
-
for card in cards:
|
4189
|
-
carduuid2card[card.uuid] = card
|
4190
|
-
|
4191
|
-
return StateKernal(
|
4192
|
-
rng=kwargs.get('rng'),
|
4193
|
-
game_config=game_config,
|
4194
|
-
edges=edges,
|
4195
|
-
decks=kwargs.get('decks'),
|
4196
|
-
piles=kwargs.get('piles'),
|
4197
|
-
players=kwargs.get('players'),
|
4198
|
-
player_idxs=kwargs.get('player_idxs'),
|
4199
|
-
history=kwargs.get('history'),
|
4200
|
-
player_scores=kwargs.get('player_scores'),
|
4201
|
-
uuid2edge=uuid2edge,
|
4202
|
-
idx2path=idx2path,
|
4203
|
-
uuid2segment=uuid2segment,
|
4204
|
-
edgeuuid2idx=edgeuuid2idx,
|
4205
|
-
carduuid2card=carduuid2card,
|
4206
|
-
pieceuuid2piece=pieceuuid2piece,
|
4225
|
+
def init_state(kernal):
|
4226
|
+
state = State(
|
4227
|
+
rng=kernal.rng,
|
4228
|
+
game_config=kernal.game_config,
|
4229
|
+
edges=kernal.edges,
|
4230
|
+
decks=kernal.decks,
|
4231
|
+
piles=kernal.piles,
|
4232
|
+
players=kernal.players,
|
4233
|
+
player_idxs=kernal.player_idxs,
|
4234
|
+
history=kernal.history,
|
4235
|
+
player_scores=kernal.player_scores,
|
4236
|
+
legal_actions_3=[],
|
4237
|
+
is_terminal=False,
|
4238
|
+
idx2path=kernal.idx2path,
|
4239
|
+
pieceuuid2piece=kernal.pieceuuid2piece,
|
4240
|
+
edgeuuid2idx=kernal.edgeuuid2idx,
|
4241
|
+
carduuid2card=kernal.carduuid2card,
|
4207
4242
|
)
|
4243
|
+
state = state.set(legal_actions_3=calc_legal_actions3(kernal))
|
4244
|
+
return state
|
4208
4245
|
|
4209
4246
|
|
4210
4247
|
def getnextstate2(s, a, log=False):
|
@@ -4352,10 +4389,6 @@ def get_public_history(s):
|
|
4352
4389
|
return [action.get_public(s) for action in s.history]
|
4353
4390
|
|
4354
4391
|
|
4355
|
-
def imagine_rng():
|
4356
|
-
return random.Random()
|
4357
|
-
|
4358
|
-
|
4359
4392
|
def imagine_history(public_state, private_state):
|
4360
4393
|
pass
|
4361
4394
|
|
@@ -4374,7 +4407,7 @@ def imagine_decks(public_state, private_state):
|
|
4374
4407
|
|
4375
4408
|
def imagine_state(public_state, private_state):
|
4376
4409
|
kernal = init_state_kernal(
|
4377
|
-
rng=
|
4410
|
+
rng=random.Random(),
|
4378
4411
|
game_config=public_state.game_config,
|
4379
4412
|
player_idxs=public_state.player_idxs,
|
4380
4413
|
piles=public_state.piles,
|
@@ -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=tlnr9TsZohGevs4lUqAPaF7qPknJWnzH_jmEpiEKITc,191851
|
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.1918.dist-info/METADATA,sha256=NpjVzxy7lmO0xpfAdfDo4G-bVCE-cbsPXrvvRd9M_cQ,188
|
7
|
+
graph_games_proto-0.3.1918.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
8
|
+
graph_games_proto-0.3.1918.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
|
9
|
+
graph_games_proto-0.3.1918.dist-info/RECORD,,
|
File without changes
|
File without changes
|