graph-games-proto 0.3.1914__py3-none-any.whl → 0.3.1916__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 +39 -81
- {graph_games_proto-0.3.1914.dist-info → graph_games_proto-0.3.1916.dist-info}/METADATA +1 -1
- {graph_games_proto-0.3.1914.dist-info → graph_games_proto-0.3.1916.dist-info}/RECORD +5 -5
- {graph_games_proto-0.3.1914.dist-info → graph_games_proto-0.3.1916.dist-info}/WHEEL +0 -0
- {graph_games_proto-0.3.1914.dist-info → graph_games_proto-0.3.1916.dist-info}/top_level.txt +0 -0
graph_games_proto/fns.py
CHANGED
@@ -1103,7 +1103,6 @@ class PrivateState(PClass):
|
|
1103
1103
|
my_history = field(type=list) # List[Action2]
|
1104
1104
|
player_score = field(type=PrivatePlayerScore)
|
1105
1105
|
player = field(type=Player)
|
1106
|
-
legal_actions_2 = field(type=list) # List[LegalAction]
|
1107
1106
|
legal_actions_3 = field(type=list) # List[LegalAction]
|
1108
1107
|
goal_completions = field(type=list, initial=[]) # List[GoalCompletion]
|
1109
1108
|
def __todict__(self):
|
@@ -1111,7 +1110,6 @@ class PrivateState(PClass):
|
|
1111
1110
|
"my_history": [x.__todict__() for x in self.my_history],
|
1112
1111
|
"player_score": self.player_score.__todict__(),
|
1113
1112
|
"player": self.player.__todict__(),
|
1114
|
-
"legal_actions_2": [x.__todict__() for x in self.legal_actions_2],
|
1115
1113
|
"legal_actions_3": [x.__todict__() for x in self.legal_actions_3],
|
1116
1114
|
"goal_completions": [x.__todict__() for x in self.goal_completions],
|
1117
1115
|
}
|
@@ -1121,7 +1119,6 @@ class PrivateState(PClass):
|
|
1121
1119
|
my_history=[Action2.__fromdict__(x) for x in d["my_history"]],
|
1122
1120
|
player_score=PrivatePlayerScore.__fromdict__(d["player_score"]),
|
1123
1121
|
player=Player.__fromdict__(d["player"]),
|
1124
|
-
legal_actions_2=[LegalAction.__fromdict__(x) for x in d["legal_actions_2"]],
|
1125
1122
|
legal_actions_3=[LegalAction.__fromdict__(x) for x in d["legal_actions_3"]],
|
1126
1123
|
goal_completions=[GoalCompletion.__fromdict__(x) for x in d["goal_completions"]],
|
1127
1124
|
)
|
@@ -1956,7 +1953,6 @@ class State(PClass):
|
|
1956
1953
|
edgeuuid2idx = field(type=dict) # Dict[str, int]
|
1957
1954
|
edgetuple2uuid = field(type=dict) # Dict[Tuple[int, int], str]
|
1958
1955
|
regions = field(type=list) # List[Region]
|
1959
|
-
legal_actions_2 = field(type=list) # List[LegalAction]
|
1960
1956
|
legal_actions_3 = field(type=list) # List[LegalAction]
|
1961
1957
|
piles = field(type=list) # List[Pile]
|
1962
1958
|
players = field(type=list) # List[Player]
|
@@ -1988,7 +1984,6 @@ class State(PClass):
|
|
1988
1984
|
"edgeuuid2idx": self.edgeuuid2idx,
|
1989
1985
|
"edgetuple2uuid": [{"k": list(k), "v": v} for k, v in self.edgetuple2uuid.items()],
|
1990
1986
|
"regions": [region.__todict__() for region in self.regions],
|
1991
|
-
"legal_actions_2": [x.__todict__() for x in self.legal_actions_2],
|
1992
1987
|
"legal_actions_3": [x.__todict__() for x in self.legal_actions_3],
|
1993
1988
|
"piles": [pile.__todict__() for pile in self.piles],
|
1994
1989
|
"players": [player.__todict__() for player in self.players],
|
@@ -2022,7 +2017,6 @@ class State(PClass):
|
|
2022
2017
|
edgeuuid2idx=d["edgeuuid2idx"],
|
2023
2018
|
edgetuple2uuid={tuple(item["k"]): item["v"] for item in d["edgetuple2uuid"]},
|
2024
2019
|
regions=[Region.__fromdict__(r) for r in d["regions"]],
|
2025
|
-
legal_actions_2=[LegalAction.__fromdict__(x) for x in d["legal_actions_2"]],
|
2026
2020
|
legal_actions_3=[LegalAction.__fromdict__(x) for x in d["legal_actions_3"]],
|
2027
2021
|
piles=[Pile.__fromdict__(p) for p in d["piles"]],
|
2028
2022
|
players=[Player.__fromdict__(p) for p in d["players"]],
|
@@ -2599,7 +2593,6 @@ def getinitialstate(game_config):
|
|
2599
2593
|
edgeuuid2idx = edgeuuid2idx,
|
2600
2594
|
edgetuple2uuid = edgetuple2uuid,
|
2601
2595
|
regions = get_regions(board_config),
|
2602
|
-
legal_actions_2=[],
|
2603
2596
|
legal_actions_3=[],
|
2604
2597
|
piles=piles,
|
2605
2598
|
players=[Player(idx=idx, pieces=[], cards=[], discard_tray=[]) for idx in range(game_config.num_players)],
|
@@ -2614,6 +2607,8 @@ def getinitialstate(game_config):
|
|
2614
2607
|
state = run_state_hooks(state, INITIALIZATION_HOOKS, True)
|
2615
2608
|
|
2616
2609
|
state_kernal = init_state_kernal(
|
2610
|
+
rng=rng,
|
2611
|
+
game_config=state.game_config,
|
2617
2612
|
edges=state.edges,
|
2618
2613
|
decks=state.decks,
|
2619
2614
|
piles=state.piles,
|
@@ -2621,7 +2616,6 @@ def getinitialstate(game_config):
|
|
2621
2616
|
player_idxs=state.player_idxs,
|
2622
2617
|
history=state.history,
|
2623
2618
|
player_scores=state.player_scores,
|
2624
|
-
game_config=state.game_config,
|
2625
2619
|
)
|
2626
2620
|
state = state.set(legal_actions_3=calc_legal_actions3(state_kernal))
|
2627
2621
|
|
@@ -2724,7 +2718,7 @@ def handle_last_to_play(game):
|
|
2724
2718
|
if len(player.pieces) < 3:
|
2725
2719
|
return game.set(last_to_play=player.idx)
|
2726
2720
|
elif game.last_to_play == game.history[-1].legal_action.player_idx:
|
2727
|
-
if not game.
|
2721
|
+
if not game.legal_actions_3:
|
2728
2722
|
return game.set(terminal=True)
|
2729
2723
|
return game
|
2730
2724
|
|
@@ -2848,11 +2842,11 @@ def default_after_accept_action(game, action):
|
|
2848
2842
|
if player_idx < 0 or player_idx >= len(game.players):
|
2849
2843
|
return game
|
2850
2844
|
new_legal_actions = [
|
2851
|
-
la for la in game.
|
2845
|
+
la for la in game.legal_actions_3 if la.player_idx != player_idx
|
2852
2846
|
]
|
2853
2847
|
history = game.history + [action]
|
2854
2848
|
return game.set(
|
2855
|
-
|
2849
|
+
legal_actions_3=new_legal_actions,
|
2856
2850
|
history=history,
|
2857
2851
|
)
|
2858
2852
|
|
@@ -3543,19 +3537,19 @@ def append_all_to_legal_actions(game, legal_actions):
|
|
3543
3537
|
def append_to_legal_actions(game, legal_action):
|
3544
3538
|
if not game:
|
3545
3539
|
return game
|
3546
|
-
|
3547
|
-
game.
|
3540
|
+
|
3541
|
+
game.legal_actions_3.append(
|
3548
3542
|
legal_action
|
3549
3543
|
)
|
3550
3544
|
|
3551
|
-
return game.set(
|
3545
|
+
return game.set(legal_actions_3=game.legal_actions_3)
|
3552
3546
|
|
3553
3547
|
|
3554
3548
|
def default_accept_action(game, action):
|
3555
3549
|
|
3556
|
-
# Returns true if action.legal_action is found in game.
|
3550
|
+
# Returns true if action.legal_action is found in game.legal_actions_3
|
3557
3551
|
# The comparision is by value, not by reference
|
3558
|
-
if action.legal_action not in game.
|
3552
|
+
if action.legal_action not in game.legal_actions_3:
|
3559
3553
|
return False, "Action not found in legal actions"
|
3560
3554
|
|
3561
3555
|
# Check if "action.move_pieces_to_path" is not None
|
@@ -4149,6 +4143,7 @@ def get_next_player_shuffled_idx(state_kernal, last_action):
|
|
4149
4143
|
|
4150
4144
|
|
4151
4145
|
class StateKernal(PClass):
|
4146
|
+
rng = field(type=random.Random)
|
4152
4147
|
game_config = field(type=GameConfig)
|
4153
4148
|
edges = field(type=list) # List[BiEdge]
|
4154
4149
|
decks = field(type=list) # List[Deck]
|
@@ -4194,6 +4189,7 @@ def init_state_kernal(**kwargs):
|
|
4194
4189
|
carduuid2card[card.uuid] = card
|
4195
4190
|
|
4196
4191
|
return StateKernal(
|
4192
|
+
rng=kwargs.get('rng'),
|
4197
4193
|
game_config=game_config,
|
4198
4194
|
edges=edges,
|
4199
4195
|
decks=kwargs.get('decks'),
|
@@ -4219,10 +4215,9 @@ def getnextstate2(s, a, log=False):
|
|
4219
4215
|
s = run_state_action_hooks(s, a, HANDLE_ACTION_HOOKS, log)
|
4220
4216
|
s = run_state_hooks(s, HANDLE_SCORING_HOOKS, log)
|
4221
4217
|
s = run_state_hooks(s, HANDLE_TERMINAL_HOOKS, log)
|
4222
|
-
if not s.legal_actions_2:
|
4223
|
-
s = run_state_action_hooks(s, a, EMPTY_LEGAL_ACTIONS_HOOKS, log)
|
4224
4218
|
|
4225
4219
|
state_kernal = init_state_kernal(
|
4220
|
+
rng=s.rng,
|
4226
4221
|
game_config=s.game_config,
|
4227
4222
|
edges=s.edges,
|
4228
4223
|
decks=s.decks,
|
@@ -4261,7 +4256,7 @@ def getprivateplayerscore(s, player_score):
|
|
4261
4256
|
|
4262
4257
|
|
4263
4258
|
def getpublictoplay(s):
|
4264
|
-
player_idxs = [legal_action.player_idx for legal_action in s.
|
4259
|
+
player_idxs = [legal_action.player_idx for legal_action in s.legal_actions_3]
|
4265
4260
|
# filter out duplicates
|
4266
4261
|
return list(set(player_idxs))
|
4267
4262
|
|
@@ -4276,7 +4271,7 @@ def get_max_allotted_times(s):
|
|
4276
4271
|
def get_player_max_allotted_time(s, player_idx):
|
4277
4272
|
max_allotted_seconds = 0
|
4278
4273
|
since_action_idx_of_max = -1
|
4279
|
-
for legal_action in s.
|
4274
|
+
for legal_action in s.legal_actions_3:
|
4280
4275
|
if legal_action.player_idx == player_idx:
|
4281
4276
|
if legal_action.allotted_seconds > max_allotted_seconds:
|
4282
4277
|
max_allotted_seconds = legal_action.allotted_seconds
|
@@ -4350,14 +4345,17 @@ def get_public_player_scores(s):
|
|
4350
4345
|
|
4351
4346
|
# player_score = field(type=PrivatePlayerScore)
|
4352
4347
|
# player = field(type=Player)
|
4353
|
-
# legal_actions_2 = field(type=list) # List[LegalAction]
|
4354
4348
|
# goal_completions = field(type=list, initial=[]) # List[GoalCompletion]
|
4355
4349
|
|
4356
4350
|
|
4357
|
-
|
4358
4351
|
def get_public_history(s):
|
4359
4352
|
return [action.get_public(s) for action in s.history]
|
4360
4353
|
|
4354
|
+
|
4355
|
+
def imagine_rng():
|
4356
|
+
return random.Random()
|
4357
|
+
|
4358
|
+
|
4361
4359
|
def imagine_history(public_state, private_state):
|
4362
4360
|
pass
|
4363
4361
|
|
@@ -4373,46 +4371,25 @@ def imagine_players(public_state, private_state):
|
|
4373
4371
|
def imagine_decks(public_state, private_state):
|
4374
4372
|
pass
|
4375
4373
|
|
4376
|
-
def imagine_rng(public_state, private_state):
|
4377
|
-
pass
|
4378
|
-
|
4379
4374
|
|
4380
4375
|
def imagine_state(public_state, private_state):
|
4381
|
-
|
4382
|
-
|
4383
|
-
|
4384
|
-
|
4385
|
-
|
4386
|
-
|
4387
|
-
|
4388
|
-
|
4389
|
-
|
4390
|
-
|
4391
|
-
starting_piles = public_state.starting_piles,
|
4392
|
-
player_graphs = public_state.player_graphs,
|
4393
|
-
goals = public_state.goals,
|
4394
|
-
nodes = public_state.nodes,
|
4395
|
-
nodeuuid2idx = public_state.nodeuuid2idx,
|
4396
|
-
edges = public_state.edges,
|
4397
|
-
edgeuuid2idx = public_state.edgeuuid2idx,
|
4398
|
-
edgetuple2uuid = public_state.edgetuple2uuid,
|
4399
|
-
regions = public_state.regions,
|
4400
|
-
last_to_play = public_state.last_to_play,
|
4401
|
-
winners = public_state.winners,
|
4402
|
-
piles = public_state.piles,
|
4403
|
-
player_idxs = public_state.player_idxs,
|
4404
|
-
game_config = public_state.game_config,
|
4405
|
-
legal_actions_2 = imagine_legal_actions(public_state, private_state),
|
4406
|
-
players = imagine_players(public_state, private_state),
|
4407
|
-
decks = imagine_decks(public_state, private_state),
|
4408
|
-
rng = imagine_rng(public_state, private_state),
|
4409
|
-
history = imagine_history(public_state, private_state),
|
4410
|
-
player_scores = imagine_player_scores(public_state, private_state),
|
4376
|
+
kernal = init_state_kernal(
|
4377
|
+
rng=imagine_rng(),
|
4378
|
+
game_config=public_state.game_config,
|
4379
|
+
player_idxs=public_state.player_idxs,
|
4380
|
+
piles=public_state.piles,
|
4381
|
+
edges=public_state.edges,
|
4382
|
+
decks=imagine_decks(public_state, private_state),
|
4383
|
+
players=imagine_players(public_state, private_state),
|
4384
|
+
history=imagine_history(public_state, private_state),
|
4385
|
+
player_scores=imagine_player_scores(public_state, private_state),
|
4411
4386
|
)
|
4387
|
+
imagined_state = init_state(kernal)
|
4388
|
+
return imagined_state
|
4412
4389
|
|
4413
4390
|
|
4414
4391
|
def isterminal(s):
|
4415
|
-
return len(s.
|
4392
|
+
return len(s.legal_actions_3) == 0
|
4416
4393
|
|
4417
4394
|
|
4418
4395
|
@dispatch(State)
|
@@ -4603,7 +4580,7 @@ def get_legal_actions3(s, player_idx):
|
|
4603
4580
|
|
4604
4581
|
@dispatch(State, int)
|
4605
4582
|
def get_legal_actions(s, player_idx):
|
4606
|
-
return [a for a in s.
|
4583
|
+
return [a for a in s.legal_actions_3 if a.player_idx == player_idx]
|
4607
4584
|
|
4608
4585
|
|
4609
4586
|
def get_goal_completions(s, player_idx):
|
@@ -5094,7 +5071,6 @@ def getprivatestate(s, player_idx):
|
|
5094
5071
|
my_history=[a for a in s.history if a.legal_action.player_idx == player_idx],
|
5095
5072
|
player_score=getprivateplayerscore(s, s.player_scores[player_idx]),
|
5096
5073
|
player=s.players[player_idx],
|
5097
|
-
legal_actions_2 = get_legal_actions(s, player_idx),
|
5098
5074
|
legal_actions_3 = get_legal_actions3(s, player_idx),
|
5099
5075
|
goal_completions=get_goal_completions(s, player_idx),
|
5100
5076
|
)
|
@@ -5246,15 +5222,15 @@ def diff(A, dims=None):
|
|
5246
5222
|
|
5247
5223
|
|
5248
5224
|
def get_default_toplay(s):
|
5249
|
-
if s.
|
5250
|
-
return s.
|
5225
|
+
if s.legal_actions_3:
|
5226
|
+
return s.legal_actions_3[0].player_idx
|
5251
5227
|
return None
|
5252
5228
|
|
5253
5229
|
|
5254
5230
|
def get_intuited_best_actions(ps):
|
5255
|
-
if not ps.
|
5231
|
+
if not ps.legal_actions_3:
|
5256
5232
|
return None
|
5257
|
-
return ps.
|
5233
|
+
return ps.legal_actions_3[:8]
|
5258
5234
|
|
5259
5235
|
|
5260
5236
|
def get_spread(q_values, p_idx):
|
@@ -5282,7 +5258,7 @@ def dynamics(s, a):
|
|
5282
5258
|
|
5283
5259
|
def alpha0(ps):
|
5284
5260
|
td = 3
|
5285
|
-
legal_actions = ps.
|
5261
|
+
legal_actions = ps.legal_actions_3
|
5286
5262
|
if not legal_actions:
|
5287
5263
|
return None
|
5288
5264
|
intuited = get_intuited_best_actions(ps)
|
@@ -5533,24 +5509,6 @@ ACCEPT_ACTION_HOOKS = [
|
|
5533
5509
|
)
|
5534
5510
|
]
|
5535
5511
|
|
5536
|
-
EMPTY_LEGAL_ACTIONS_HOOK_1 = """
|
5537
|
-
def handler(game, action):
|
5538
|
-
if action.legal_action.name == "INITIAL-GOAL-KEEP":
|
5539
|
-
return append_default_legal_actions_for_initial_player(game, action)
|
5540
|
-
else:
|
5541
|
-
return append_default_legal_actions_for_next_player(game, action)
|
5542
|
-
return game
|
5543
|
-
"""
|
5544
|
-
|
5545
|
-
EMPTY_LEGAL_ACTIONS_HOOKS = [
|
5546
|
-
Hook(
|
5547
|
-
name="EmptyLegalActionsHook",
|
5548
|
-
uuid="f45dabf6-8f46-4af2-9b88-327db8b985eb",
|
5549
|
-
when="EMPTY_LEGAL_ACTIONS",
|
5550
|
-
code=EMPTY_LEGAL_ACTIONS_HOOK_1,
|
5551
|
-
)
|
5552
|
-
]
|
5553
|
-
|
5554
5512
|
HANDLE_SCORING_HOOK_1 = """
|
5555
5513
|
def handler(game):
|
5556
5514
|
return default_handle_scoring(game)
|
@@ -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=W7tRrFF1jmt6x8BD5HOomrwiRJ6xWjMyhlD5OAw6jUQ,190223
|
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.1916.dist-info/METADATA,sha256=tx8X1XVD9ogkC-atGxhajgT-xu_FTZPH7-EkYfmTWUI,188
|
7
|
+
graph_games_proto-0.3.1916.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
8
|
+
graph_games_proto-0.3.1916.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
|
9
|
+
graph_games_proto-0.3.1916.dist-info/RECORD,,
|
File without changes
|
File without changes
|