graph-games-proto 0.3.1913__py3-none-any.whl → 0.3.1915__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 +24 -49
- {graph_games_proto-0.3.1913.dist-info → graph_games_proto-0.3.1915.dist-info}/METADATA +1 -1
- {graph_games_proto-0.3.1913.dist-info → graph_games_proto-0.3.1915.dist-info}/RECORD +5 -5
- {graph_games_proto-0.3.1913.dist-info → graph_games_proto-0.3.1915.dist-info}/WHEEL +0 -0
- {graph_games_proto-0.3.1913.dist-info → graph_games_proto-0.3.1915.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)],
|
@@ -2724,7 +2717,7 @@ def handle_last_to_play(game):
|
|
2724
2717
|
if len(player.pieces) < 3:
|
2725
2718
|
return game.set(last_to_play=player.idx)
|
2726
2719
|
elif game.last_to_play == game.history[-1].legal_action.player_idx:
|
2727
|
-
if not game.
|
2720
|
+
if not game.legal_actions_3:
|
2728
2721
|
return game.set(terminal=True)
|
2729
2722
|
return game
|
2730
2723
|
|
@@ -2848,11 +2841,11 @@ def default_after_accept_action(game, action):
|
|
2848
2841
|
if player_idx < 0 or player_idx >= len(game.players):
|
2849
2842
|
return game
|
2850
2843
|
new_legal_actions = [
|
2851
|
-
la for la in game.
|
2844
|
+
la for la in game.legal_actions_3 if la.player_idx != player_idx
|
2852
2845
|
]
|
2853
2846
|
history = game.history + [action]
|
2854
2847
|
return game.set(
|
2855
|
-
|
2848
|
+
legal_actions_3=new_legal_actions,
|
2856
2849
|
history=history,
|
2857
2850
|
)
|
2858
2851
|
|
@@ -3543,19 +3536,19 @@ def append_all_to_legal_actions(game, legal_actions):
|
|
3543
3536
|
def append_to_legal_actions(game, legal_action):
|
3544
3537
|
if not game:
|
3545
3538
|
return game
|
3546
|
-
|
3547
|
-
game.
|
3539
|
+
|
3540
|
+
game.legal_actions_3.append(
|
3548
3541
|
legal_action
|
3549
3542
|
)
|
3550
3543
|
|
3551
|
-
return game.set(
|
3544
|
+
return game.set(legal_actions_3=game.legal_actions_3)
|
3552
3545
|
|
3553
3546
|
|
3554
3547
|
def default_accept_action(game, action):
|
3555
3548
|
|
3556
|
-
# Returns true if action.legal_action is found in game.
|
3549
|
+
# Returns true if action.legal_action is found in game.legal_actions_3
|
3557
3550
|
# The comparision is by value, not by reference
|
3558
|
-
if action.legal_action not in game.
|
3551
|
+
if action.legal_action not in game.legal_actions_3:
|
3559
3552
|
return False, "Action not found in legal actions"
|
3560
3553
|
|
3561
3554
|
# Check if "action.move_pieces_to_path" is not None
|
@@ -4082,6 +4075,7 @@ def calc_legal_actions3(state_kernal):
|
|
4082
4075
|
last_action = history[-1] if len(history) > 0 else None
|
4083
4076
|
|
4084
4077
|
if last_action is None or last_action.legal_action.name == "INITIAL-GOAL-KEEP":
|
4078
|
+
|
4085
4079
|
yet_to_make_initial_move = [
|
4086
4080
|
player for player in state_kernal.players if len(player.discard_tray) > 0
|
4087
4081
|
]
|
@@ -4108,11 +4102,15 @@ def calc_legal_actions3(state_kernal):
|
|
4108
4102
|
elif last_action.legal_action.faceup_draw:
|
4109
4103
|
faceup_draw = last_action.legal_action.faceup_draw
|
4110
4104
|
if not state_kernal.carduuid2card[faceup_draw.card_uuid].is_wild:
|
4111
|
-
|
4105
|
+
legal_actions = get_follow_up_draw_legal_actions(state_kernal, last_action)
|
4106
|
+
if legal_actions:
|
4107
|
+
return legal_actions
|
4112
4108
|
|
4113
4109
|
elif last_action.legal_action.draw:
|
4114
4110
|
if last_action.legal_action.draw.quantity == 1:
|
4115
|
-
|
4111
|
+
legal_actions = get_follow_up_draw_legal_actions(state_kernal, last_action)
|
4112
|
+
if legal_actions:
|
4113
|
+
return legal_actions
|
4116
4114
|
|
4117
4115
|
elif last_action.legal_action.draw_discard:
|
4118
4116
|
draw_discard = last_action.legal_action.draw_discard
|
@@ -4214,8 +4212,6 @@ def getnextstate2(s, a, log=False):
|
|
4214
4212
|
s = run_state_action_hooks(s, a, HANDLE_ACTION_HOOKS, log)
|
4215
4213
|
s = run_state_hooks(s, HANDLE_SCORING_HOOKS, log)
|
4216
4214
|
s = run_state_hooks(s, HANDLE_TERMINAL_HOOKS, log)
|
4217
|
-
if not s.legal_actions_2:
|
4218
|
-
s = run_state_action_hooks(s, a, EMPTY_LEGAL_ACTIONS_HOOKS, log)
|
4219
4215
|
|
4220
4216
|
state_kernal = init_state_kernal(
|
4221
4217
|
game_config=s.game_config,
|
@@ -4256,7 +4252,7 @@ def getprivateplayerscore(s, player_score):
|
|
4256
4252
|
|
4257
4253
|
|
4258
4254
|
def getpublictoplay(s):
|
4259
|
-
player_idxs = [legal_action.player_idx for legal_action in s.
|
4255
|
+
player_idxs = [legal_action.player_idx for legal_action in s.legal_actions_3]
|
4260
4256
|
# filter out duplicates
|
4261
4257
|
return list(set(player_idxs))
|
4262
4258
|
|
@@ -4271,7 +4267,7 @@ def get_max_allotted_times(s):
|
|
4271
4267
|
def get_player_max_allotted_time(s, player_idx):
|
4272
4268
|
max_allotted_seconds = 0
|
4273
4269
|
since_action_idx_of_max = -1
|
4274
|
-
for legal_action in s.
|
4270
|
+
for legal_action in s.legal_actions_3:
|
4275
4271
|
if legal_action.player_idx == player_idx:
|
4276
4272
|
if legal_action.allotted_seconds > max_allotted_seconds:
|
4277
4273
|
max_allotted_seconds = legal_action.allotted_seconds
|
@@ -4345,7 +4341,6 @@ def get_public_player_scores(s):
|
|
4345
4341
|
|
4346
4342
|
# player_score = field(type=PrivatePlayerScore)
|
4347
4343
|
# player = field(type=Player)
|
4348
|
-
# legal_actions_2 = field(type=list) # List[LegalAction]
|
4349
4344
|
# goal_completions = field(type=list, initial=[]) # List[GoalCompletion]
|
4350
4345
|
|
4351
4346
|
|
@@ -4397,7 +4392,6 @@ def imagine_state(public_state, private_state):
|
|
4397
4392
|
piles = public_state.piles,
|
4398
4393
|
player_idxs = public_state.player_idxs,
|
4399
4394
|
game_config = public_state.game_config,
|
4400
|
-
legal_actions_2 = imagine_legal_actions(public_state, private_state),
|
4401
4395
|
players = imagine_players(public_state, private_state),
|
4402
4396
|
decks = imagine_decks(public_state, private_state),
|
4403
4397
|
rng = imagine_rng(public_state, private_state),
|
@@ -4407,7 +4401,7 @@ def imagine_state(public_state, private_state):
|
|
4407
4401
|
|
4408
4402
|
|
4409
4403
|
def isterminal(s):
|
4410
|
-
return len(s.
|
4404
|
+
return len(s.legal_actions_3) == 0
|
4411
4405
|
|
4412
4406
|
|
4413
4407
|
@dispatch(State)
|
@@ -4598,7 +4592,7 @@ def get_legal_actions3(s, player_idx):
|
|
4598
4592
|
|
4599
4593
|
@dispatch(State, int)
|
4600
4594
|
def get_legal_actions(s, player_idx):
|
4601
|
-
return [a for a in s.
|
4595
|
+
return [a for a in s.legal_actions_3 if a.player_idx == player_idx]
|
4602
4596
|
|
4603
4597
|
|
4604
4598
|
def get_goal_completions(s, player_idx):
|
@@ -5089,7 +5083,6 @@ def getprivatestate(s, player_idx):
|
|
5089
5083
|
my_history=[a for a in s.history if a.legal_action.player_idx == player_idx],
|
5090
5084
|
player_score=getprivateplayerscore(s, s.player_scores[player_idx]),
|
5091
5085
|
player=s.players[player_idx],
|
5092
|
-
legal_actions_2 = get_legal_actions(s, player_idx),
|
5093
5086
|
legal_actions_3 = get_legal_actions3(s, player_idx),
|
5094
5087
|
goal_completions=get_goal_completions(s, player_idx),
|
5095
5088
|
)
|
@@ -5241,15 +5234,15 @@ def diff(A, dims=None):
|
|
5241
5234
|
|
5242
5235
|
|
5243
5236
|
def get_default_toplay(s):
|
5244
|
-
if s.
|
5245
|
-
return s.
|
5237
|
+
if s.legal_actions_3:
|
5238
|
+
return s.legal_actions_3[0].player_idx
|
5246
5239
|
return None
|
5247
5240
|
|
5248
5241
|
|
5249
5242
|
def get_intuited_best_actions(ps):
|
5250
|
-
if not ps.
|
5243
|
+
if not ps.legal_actions_3:
|
5251
5244
|
return None
|
5252
|
-
return ps.
|
5245
|
+
return ps.legal_actions_3[:8]
|
5253
5246
|
|
5254
5247
|
|
5255
5248
|
def get_spread(q_values, p_idx):
|
@@ -5277,7 +5270,7 @@ def dynamics(s, a):
|
|
5277
5270
|
|
5278
5271
|
def alpha0(ps):
|
5279
5272
|
td = 3
|
5280
|
-
legal_actions = ps.
|
5273
|
+
legal_actions = ps.legal_actions_3
|
5281
5274
|
if not legal_actions:
|
5282
5275
|
return None
|
5283
5276
|
intuited = get_intuited_best_actions(ps)
|
@@ -5528,24 +5521,6 @@ ACCEPT_ACTION_HOOKS = [
|
|
5528
5521
|
)
|
5529
5522
|
]
|
5530
5523
|
|
5531
|
-
EMPTY_LEGAL_ACTIONS_HOOK_1 = """
|
5532
|
-
def handler(game, action):
|
5533
|
-
if action.legal_action.name == "INITIAL-GOAL-KEEP":
|
5534
|
-
return append_default_legal_actions_for_initial_player(game, action)
|
5535
|
-
else:
|
5536
|
-
return append_default_legal_actions_for_next_player(game, action)
|
5537
|
-
return game
|
5538
|
-
"""
|
5539
|
-
|
5540
|
-
EMPTY_LEGAL_ACTIONS_HOOKS = [
|
5541
|
-
Hook(
|
5542
|
-
name="EmptyLegalActionsHook",
|
5543
|
-
uuid="f45dabf6-8f46-4af2-9b88-327db8b985eb",
|
5544
|
-
when="EMPTY_LEGAL_ACTIONS",
|
5545
|
-
code=EMPTY_LEGAL_ACTIONS_HOOK_1,
|
5546
|
-
)
|
5547
|
-
]
|
5548
|
-
|
5549
5524
|
HANDLE_SCORING_HOOK_1 = """
|
5550
5525
|
def handler(game):
|
5551
5526
|
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=Rj9ALtDUBPp5C0sn7ExUcuXrzOabAw7A1Xsf-LKL7Sg,191027
|
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.1915.dist-info/METADATA,sha256=8DzNZJm4Rg3_o3wwY0t6DEQIjF8wFibw9dK6jrRntd4,188
|
7
|
+
graph_games_proto-0.3.1915.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
8
|
+
graph_games_proto-0.3.1915.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
|
9
|
+
graph_games_proto-0.3.1915.dist-info/RECORD,,
|
File without changes
|
File without changes
|