graph-games-proto 0.3.1915__py3-none-any.whl → 0.3.1917__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 +146 -96
- {graph_games_proto-0.3.1915.dist-info → graph_games_proto-0.3.1917.dist-info}/METADATA +1 -1
- {graph_games_proto-0.3.1915.dist-info → graph_games_proto-0.3.1917.dist-info}/RECORD +5 -5
- {graph_games_proto-0.3.1915.dist-info → graph_games_proto-0.3.1917.dist-info}/WHEEL +0 -0
- {graph_games_proto-0.3.1915.dist-info → graph_games_proto-0.3.1917.dist-info}/top_level.txt +0 -0
graph_games_proto/fns.py
CHANGED
@@ -1932,7 +1932,110 @@ 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
|
+
uuid2edge = field(type=dict) # Dict[str, BiEdge]
|
1946
|
+
idx2path = field(type=list) # List[Path2]
|
1947
|
+
uuid2segment = field(type=dict) # Dict[str, Segment]
|
1948
|
+
pieceuuid2piece = field(type=dict) # Dict[str, Piece]
|
1949
|
+
edgeuuid2idx = field(type=dict) # Dict[str, int]
|
1950
|
+
carduuid2card = field(type=dict) # Dict[str, Card]
|
1951
|
+
def __todict__(self):
|
1952
|
+
return {
|
1953
|
+
"rng": rng2json(self.rng),
|
1954
|
+
"game_config": self.game_config.__todict__(),
|
1955
|
+
"edges": [edge.__todict__() for edge in self.edges],
|
1956
|
+
"decks": [deck.__todict__() for deck in self.decks],
|
1957
|
+
"piles": [pile.__todict__() for pile in self.piles],
|
1958
|
+
"players": [player.__todict__() for player in self.players],
|
1959
|
+
"player_idxs": self.player_idxs,
|
1960
|
+
"history": [action.__todict__() for action in self.history],
|
1961
|
+
"player_scores": [score.__todict__() for score in self.player_scores],
|
1962
|
+
"uuid2edge": {k: v.__todict() for k, v in self.uuid2edge.items()},
|
1963
|
+
"idx2path": [v.__todict__() for v in self.idx2path],
|
1964
|
+
"uuid2segment": {k: v.__todict__() for k, v in self.uuid2segment.items()},
|
1965
|
+
"pieceuuid2piece": {k: v.__todict__() for k, v in self.pieceuuid2piece.items()},
|
1966
|
+
"edgeuuid2idx": self.edgeuuid2idx,
|
1967
|
+
"carduuid2card": {k: v.__todict__() for k, v in self.carduuid2card.items()},
|
1968
|
+
}
|
1969
|
+
@staticmethod
|
1970
|
+
def __fromdict__(d):
|
1971
|
+
return StateKernal(
|
1972
|
+
rng=json2rng(d["rng"]),
|
1973
|
+
game_config=GameConfig.__fromdict__(d["game_config"]),
|
1974
|
+
edges=[BiEdge.__fromdict__(edge) for edge in d["edges"]],
|
1975
|
+
decks=[Deck.__fromdict__(deck) for deck in d["decks"]],
|
1976
|
+
piles=[Pile.__fromdict__(pile) for pile in d["piles"]],
|
1977
|
+
players=[Player.__fromdict__(player) for player in d["players"]],
|
1978
|
+
player_idxs=d["player_idxs"],
|
1979
|
+
history=[PublicAction.__fromdict__(action) for action in d["history"]],
|
1980
|
+
player_scores=[PlayerScore.__fromdict__(score) for score in d["player_scores"]],
|
1981
|
+
uuid2edge={k: BiEdge.__fromdict(v) for k, v in d["uuid2edge"].items()},
|
1982
|
+
idx2path=[Path2.__fromdict(v) for v in d["idx2path"]],
|
1983
|
+
uuid2segment={k: Segment2.__fromdict(v) for k, v in d["uuid2segment"].items()},
|
1984
|
+
pieceuuid2piece={k: Piece.__fromdict(v) for k, v in d["pieceuuid2piece"].items()},
|
1985
|
+
edgeuuid2idx=d["edgeuuid2idx"],
|
1986
|
+
carduuid2card={k: Card.__fromdict(v) for k, v in d["carduuid2card"].items()},
|
1987
|
+
)
|
1988
|
+
|
1989
|
+
|
1990
|
+
def init_state_kernal(**kwargs):
|
1991
|
+
game_config = kwargs.get('game_config')
|
1992
|
+
fig = game_config.fig
|
1993
|
+
board_config = fig.board_config
|
1994
|
+
edges = kwargs.get('edges', [])
|
1995
|
+
uuid2edge = {}
|
1996
|
+
idx2path = []
|
1997
|
+
uuid2segment = {}
|
1998
|
+
edgeuuid2idx = {edge.uuid: idx for idx, edge in enumerate(edges)}
|
1999
|
+
for edge in edges:
|
2000
|
+
uuid2edge[edge.uuid] = edge
|
2001
|
+
for path in edge.paths:
|
2002
|
+
idx2path.append(path)
|
2003
|
+
for segment in path.segments:
|
2004
|
+
uuid2segment[segment.uuid] = segment
|
2005
|
+
pieceuuid2piece = {}
|
2006
|
+
for piece_template in board_config.piece_templates:
|
2007
|
+
if piece_template.has_player:
|
2008
|
+
for player_idx in range(game_config.num_players):
|
2009
|
+
pieces = generate_pieces(piece_template, player_idx)
|
2010
|
+
for piece in pieces:
|
2011
|
+
pieceuuid2piece[piece.uuid] = piece
|
2012
|
+
carduuid2card = {}
|
2013
|
+
for dek in board_config.deks:
|
2014
|
+
cards = generate_cards(dek)
|
2015
|
+
for card in cards:
|
2016
|
+
carduuid2card[card.uuid] = card
|
2017
|
+
|
2018
|
+
return StateKernal(
|
2019
|
+
rng=kwargs.get('rng'),
|
2020
|
+
game_config=game_config,
|
2021
|
+
edges=edges,
|
2022
|
+
decks=kwargs.get('decks'),
|
2023
|
+
piles=kwargs.get('piles'),
|
2024
|
+
players=kwargs.get('players'),
|
2025
|
+
player_idxs=kwargs.get('player_idxs'),
|
2026
|
+
history=kwargs.get('history'),
|
2027
|
+
player_scores=kwargs.get('player_scores'),
|
2028
|
+
uuid2edge=uuid2edge,
|
2029
|
+
idx2path=idx2path,
|
2030
|
+
uuid2segment=uuid2segment,
|
2031
|
+
edgeuuid2idx=edgeuuid2idx,
|
2032
|
+
carduuid2card=carduuid2card,
|
2033
|
+
pieceuuid2piece=pieceuuid2piece,
|
2034
|
+
)
|
2035
|
+
|
2036
|
+
|
1935
2037
|
class State(PClass):
|
2038
|
+
kernal = field(type=StateKernal)
|
1936
2039
|
uuid2edge = field(type=dict) # Dict[str, BiEdge]
|
1937
2040
|
idx2path = field(type=list) # List[Path2]
|
1938
2041
|
uuid2segment = field(type=dict) # Dict[str, Segment]
|
@@ -1964,6 +2067,7 @@ class State(PClass):
|
|
1964
2067
|
winners = field(type=list) # List[int]
|
1965
2068
|
def __todict__(self):
|
1966
2069
|
return {
|
2070
|
+
"kernal": self.kernal.__todict__(),
|
1967
2071
|
"uuid2edge": {k: v.__todict__() for k, v in self.uuid2edge.items()},
|
1968
2072
|
"idx2path": [v.__todict__() for v in self.idx2path],
|
1969
2073
|
"uuid2segment": {k: v.__todict__() for k, v in self.uuid2segment.items()},
|
@@ -1997,6 +2101,7 @@ class State(PClass):
|
|
1997
2101
|
@staticmethod
|
1998
2102
|
def __fromdict__(d):
|
1999
2103
|
return State(
|
2104
|
+
kernal=StateKernal.__fromdict__(d["kernal"]),
|
2000
2105
|
uuid2edge={k: BiEdge.__fromdict__(v) for k, v in d["uuid2edge"].items()},
|
2001
2106
|
idx2path=[Path2.__fromdict__(v) for v in d["idx2path"]],
|
2002
2107
|
uuid2segment={k: Segment2.__fromdict__(v) for k, v in d["uuid2segment"].items()},
|
@@ -2606,7 +2711,9 @@ def getinitialstate(game_config):
|
|
2606
2711
|
|
2607
2712
|
state = run_state_hooks(state, INITIALIZATION_HOOKS, True)
|
2608
2713
|
|
2609
|
-
|
2714
|
+
kernal = init_state_kernal(
|
2715
|
+
rng=rng,
|
2716
|
+
game_config=state.game_config,
|
2610
2717
|
edges=state.edges,
|
2611
2718
|
decks=state.decks,
|
2612
2719
|
piles=state.piles,
|
@@ -2614,9 +2721,10 @@ def getinitialstate(game_config):
|
|
2614
2721
|
player_idxs=state.player_idxs,
|
2615
2722
|
history=state.history,
|
2616
2723
|
player_scores=state.player_scores,
|
2617
|
-
game_config=state.game_config,
|
2618
2724
|
)
|
2619
|
-
|
2725
|
+
|
2726
|
+
state = state.set(kernal=kernal)
|
2727
|
+
state = state.set(legal_actions_3=calc_legal_actions3(kernal))
|
2620
2728
|
|
2621
2729
|
return state
|
2622
2730
|
|
@@ -4141,67 +4249,28 @@ def get_next_player_shuffled_idx(state_kernal, last_action):
|
|
4141
4249
|
return next_player_shuffled_idx
|
4142
4250
|
|
4143
4251
|
|
4144
|
-
|
4145
|
-
|
4146
|
-
|
4147
|
-
|
4148
|
-
|
4149
|
-
|
4150
|
-
|
4151
|
-
|
4152
|
-
|
4153
|
-
|
4154
|
-
|
4155
|
-
|
4156
|
-
|
4157
|
-
|
4158
|
-
|
4159
|
-
|
4160
|
-
|
4161
|
-
|
4162
|
-
|
4163
|
-
fig = game_config.fig
|
4164
|
-
board_config = fig.board_config
|
4165
|
-
edges = kwargs.get('edges', [])
|
4166
|
-
uuid2edge = {}
|
4167
|
-
idx2path = []
|
4168
|
-
uuid2segment = {}
|
4169
|
-
edgeuuid2idx = {edge.uuid: idx for idx, edge in enumerate(edges)}
|
4170
|
-
for edge in edges:
|
4171
|
-
uuid2edge[edge.uuid] = edge
|
4172
|
-
for path in edge.paths:
|
4173
|
-
idx2path.append(path)
|
4174
|
-
for segment in path.segments:
|
4175
|
-
uuid2segment[segment.uuid] = segment
|
4176
|
-
pieceuuid2piece = {}
|
4177
|
-
for piece_template in board_config.piece_templates:
|
4178
|
-
if piece_template.has_player:
|
4179
|
-
for player_idx in range(game_config.num_players):
|
4180
|
-
pieces = generate_pieces(piece_template, player_idx)
|
4181
|
-
for piece in pieces:
|
4182
|
-
pieceuuid2piece[piece.uuid] = piece
|
4183
|
-
carduuid2card = {}
|
4184
|
-
for dek in board_config.deks:
|
4185
|
-
cards = generate_cards(dek)
|
4186
|
-
for card in cards:
|
4187
|
-
carduuid2card[card.uuid] = card
|
4188
|
-
|
4189
|
-
return StateKernal(
|
4190
|
-
game_config=game_config,
|
4191
|
-
edges=edges,
|
4192
|
-
decks=kwargs.get('decks'),
|
4193
|
-
piles=kwargs.get('piles'),
|
4194
|
-
players=kwargs.get('players'),
|
4195
|
-
player_idxs=kwargs.get('player_idxs'),
|
4196
|
-
history=kwargs.get('history'),
|
4197
|
-
player_scores=kwargs.get('player_scores'),
|
4198
|
-
uuid2edge=uuid2edge,
|
4199
|
-
idx2path=idx2path,
|
4200
|
-
uuid2segment=uuid2segment,
|
4201
|
-
edgeuuid2idx=edgeuuid2idx,
|
4202
|
-
carduuid2card=carduuid2card,
|
4203
|
-
pieceuuid2piece=pieceuuid2piece,
|
4252
|
+
def init_state(kernal):
|
4253
|
+
state = State(
|
4254
|
+
rng=kernal.rng,
|
4255
|
+
game_config=kernal.game_config,
|
4256
|
+
edges=kernal.edges,
|
4257
|
+
decks=kernal.decks,
|
4258
|
+
piles=kernal.piles,
|
4259
|
+
players=kernal.players,
|
4260
|
+
player_idxs=kernal.player_idxs,
|
4261
|
+
history=kernal.history,
|
4262
|
+
player_scores=kernal.player_scores,
|
4263
|
+
legal_actions_3=[],
|
4264
|
+
is_terminal=False,
|
4265
|
+
uuid2edge=kernal.uuid2edge,
|
4266
|
+
idx2path=kernal.idx2path,
|
4267
|
+
uuid2segment=kernal.uuid2segment,
|
4268
|
+
pieceuuid2piece=kernal.pieceuuid2piece,
|
4269
|
+
edgeuuid2idx=kernal.edgeuuid2idx,
|
4270
|
+
carduuid2card=kernal.carduuid2card,
|
4204
4271
|
)
|
4272
|
+
state = state.set(legal_actions_3=calc_legal_actions3(kernal))
|
4273
|
+
return state
|
4205
4274
|
|
4206
4275
|
|
4207
4276
|
def getnextstate2(s, a, log=False):
|
@@ -4214,6 +4283,7 @@ def getnextstate2(s, a, log=False):
|
|
4214
4283
|
s = run_state_hooks(s, HANDLE_TERMINAL_HOOKS, log)
|
4215
4284
|
|
4216
4285
|
state_kernal = init_state_kernal(
|
4286
|
+
rng=s.rng,
|
4217
4287
|
game_config=s.game_config,
|
4218
4288
|
edges=s.edges,
|
4219
4289
|
decks=s.decks,
|
@@ -4344,10 +4414,10 @@ def get_public_player_scores(s):
|
|
4344
4414
|
# goal_completions = field(type=list, initial=[]) # List[GoalCompletion]
|
4345
4415
|
|
4346
4416
|
|
4347
|
-
|
4348
4417
|
def get_public_history(s):
|
4349
4418
|
return [action.get_public(s) for action in s.history]
|
4350
4419
|
|
4420
|
+
|
4351
4421
|
def imagine_history(public_state, private_state):
|
4352
4422
|
pass
|
4353
4423
|
|
@@ -4363,41 +4433,21 @@ def imagine_players(public_state, private_state):
|
|
4363
4433
|
def imagine_decks(public_state, private_state):
|
4364
4434
|
pass
|
4365
4435
|
|
4366
|
-
def imagine_rng(public_state, private_state):
|
4367
|
-
pass
|
4368
|
-
|
4369
4436
|
|
4370
4437
|
def imagine_state(public_state, private_state):
|
4371
|
-
|
4372
|
-
|
4373
|
-
|
4374
|
-
|
4375
|
-
|
4376
|
-
|
4377
|
-
|
4378
|
-
|
4379
|
-
|
4380
|
-
|
4381
|
-
starting_piles = public_state.starting_piles,
|
4382
|
-
player_graphs = public_state.player_graphs,
|
4383
|
-
goals = public_state.goals,
|
4384
|
-
nodes = public_state.nodes,
|
4385
|
-
nodeuuid2idx = public_state.nodeuuid2idx,
|
4386
|
-
edges = public_state.edges,
|
4387
|
-
edgeuuid2idx = public_state.edgeuuid2idx,
|
4388
|
-
edgetuple2uuid = public_state.edgetuple2uuid,
|
4389
|
-
regions = public_state.regions,
|
4390
|
-
last_to_play = public_state.last_to_play,
|
4391
|
-
winners = public_state.winners,
|
4392
|
-
piles = public_state.piles,
|
4393
|
-
player_idxs = public_state.player_idxs,
|
4394
|
-
game_config = public_state.game_config,
|
4395
|
-
players = imagine_players(public_state, private_state),
|
4396
|
-
decks = imagine_decks(public_state, private_state),
|
4397
|
-
rng = imagine_rng(public_state, private_state),
|
4398
|
-
history = imagine_history(public_state, private_state),
|
4399
|
-
player_scores = imagine_player_scores(public_state, private_state),
|
4438
|
+
kernal = init_state_kernal(
|
4439
|
+
rng=random.Random(),
|
4440
|
+
game_config=public_state.game_config,
|
4441
|
+
player_idxs=public_state.player_idxs,
|
4442
|
+
piles=public_state.piles,
|
4443
|
+
edges=public_state.edges,
|
4444
|
+
decks=imagine_decks(public_state, private_state),
|
4445
|
+
players=imagine_players(public_state, private_state),
|
4446
|
+
history=imagine_history(public_state, private_state),
|
4447
|
+
player_scores=imagine_player_scores(public_state, private_state),
|
4400
4448
|
)
|
4449
|
+
imagined_state = init_state(kernal)
|
4450
|
+
return imagined_state
|
4401
4451
|
|
4402
4452
|
|
4403
4453
|
def isterminal(s):
|
@@ -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=yH7roM_wtAdsgFfeQA8wahPykXQrdCoySKm3f8U5Diw,193316
|
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.1917.dist-info/METADATA,sha256=Nzsbrk3Z0TxOO5hmViO9MlS4_Lw-kTunuJoJiB3N9FU,188
|
7
|
+
graph_games_proto-0.3.1917.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
8
|
+
graph_games_proto-0.3.1917.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
|
9
|
+
graph_games_proto-0.3.1917.dist-info/RECORD,,
|
File without changes
|
File without changes
|