graph-games-proto 0.3.1916__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 +131 -69
- {graph_games_proto-0.3.1916.dist-info → graph_games_proto-0.3.1917.dist-info}/METADATA +1 -1
- {graph_games_proto-0.3.1916.dist-info → graph_games_proto-0.3.1917.dist-info}/RECORD +5 -5
- {graph_games_proto-0.3.1916.dist-info → graph_games_proto-0.3.1917.dist-info}/WHEEL +0 -0
- {graph_games_proto-0.3.1916.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,7 @@ def getinitialstate(game_config):
|
|
2606
2711
|
|
2607
2712
|
state = run_state_hooks(state, INITIALIZATION_HOOKS, True)
|
2608
2713
|
|
2609
|
-
|
2714
|
+
kernal = init_state_kernal(
|
2610
2715
|
rng=rng,
|
2611
2716
|
game_config=state.game_config,
|
2612
2717
|
edges=state.edges,
|
@@ -2617,7 +2722,9 @@ def getinitialstate(game_config):
|
|
2617
2722
|
history=state.history,
|
2618
2723
|
player_scores=state.player_scores,
|
2619
2724
|
)
|
2620
|
-
|
2725
|
+
|
2726
|
+
state = state.set(kernal=kernal)
|
2727
|
+
state = state.set(legal_actions_3=calc_legal_actions3(kernal))
|
2621
2728
|
|
2622
2729
|
return state
|
2623
2730
|
|
@@ -4142,69 +4249,28 @@ def get_next_player_shuffled_idx(state_kernal, last_action):
|
|
4142
4249
|
return next_player_shuffled_idx
|
4143
4250
|
|
4144
4251
|
|
4145
|
-
|
4146
|
-
|
4147
|
-
|
4148
|
-
|
4149
|
-
|
4150
|
-
|
4151
|
-
|
4152
|
-
|
4153
|
-
|
4154
|
-
|
4155
|
-
|
4156
|
-
|
4157
|
-
|
4158
|
-
|
4159
|
-
|
4160
|
-
|
4161
|
-
|
4162
|
-
|
4163
|
-
|
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,
|
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,
|
4207
4271
|
)
|
4272
|
+
state = state.set(legal_actions_3=calc_legal_actions3(kernal))
|
4273
|
+
return state
|
4208
4274
|
|
4209
4275
|
|
4210
4276
|
def getnextstate2(s, a, log=False):
|
@@ -4352,10 +4418,6 @@ def get_public_history(s):
|
|
4352
4418
|
return [action.get_public(s) for action in s.history]
|
4353
4419
|
|
4354
4420
|
|
4355
|
-
def imagine_rng():
|
4356
|
-
return random.Random()
|
4357
|
-
|
4358
|
-
|
4359
4421
|
def imagine_history(public_state, private_state):
|
4360
4422
|
pass
|
4361
4423
|
|
@@ -4374,7 +4436,7 @@ def imagine_decks(public_state, private_state):
|
|
4374
4436
|
|
4375
4437
|
def imagine_state(public_state, private_state):
|
4376
4438
|
kernal = init_state_kernal(
|
4377
|
-
rng=
|
4439
|
+
rng=random.Random(),
|
4378
4440
|
game_config=public_state.game_config,
|
4379
4441
|
player_idxs=public_state.player_idxs,
|
4380
4442
|
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=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
|