graph-games-proto 0.3.1930__py3-none-any.whl → 0.3.1934__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 +5 -269
- {graph_games_proto-0.3.1930.dist-info → graph_games_proto-0.3.1934.dist-info}/METADATA +1 -1
- {graph_games_proto-0.3.1930.dist-info → graph_games_proto-0.3.1934.dist-info}/RECORD +5 -5
- {graph_games_proto-0.3.1930.dist-info → graph_games_proto-0.3.1934.dist-info}/WHEEL +0 -0
- {graph_games_proto-0.3.1930.dist-info → graph_games_proto-0.3.1934.dist-info}/top_level.txt +0 -0
graph_games_proto/fns.py
CHANGED
@@ -2037,7 +2037,6 @@ class State(PClass):
|
|
2037
2037
|
nodes = field(type=list) # List[Node]
|
2038
2038
|
nodeuuid2idx = field(type=dict) # Dict[str, int]
|
2039
2039
|
edges = field(type=list) # List[BiEdge]
|
2040
|
-
edgeuuid2idx = field(type=dict) # Dict[str, int]
|
2041
2040
|
edgetuple2uuid = field(type=dict) # Dict[Tuple[int, int], str]
|
2042
2041
|
regions = field(type=list) # List[Region]
|
2043
2042
|
legal_actions_3 = field(type=list) # List[LegalAction]
|
@@ -2066,7 +2065,6 @@ class State(PClass):
|
|
2066
2065
|
"nodes": [node.__todict__() for node in self.nodes],
|
2067
2066
|
"nodeuuid2idx": self.nodeuuid2idx,
|
2068
2067
|
"edges": [edge.__todict__() for edge in self.edges],
|
2069
|
-
"edgeuuid2idx": self.edgeuuid2idx,
|
2070
2068
|
"edgetuple2uuid": [{"k": list(k), "v": v} for k, v in self.edgetuple2uuid.items()],
|
2071
2069
|
"regions": [region.__todict__() for region in self.regions],
|
2072
2070
|
"legal_actions_3": [x.__todict__() for x in self.legal_actions_3],
|
@@ -2097,7 +2095,6 @@ class State(PClass):
|
|
2097
2095
|
nodes=[Node.__fromdict__(n) for n in d["nodes"]],
|
2098
2096
|
nodeuuid2idx=d["nodeuuid2idx"],
|
2099
2097
|
edges=[BiEdge.__fromdict__(e) for e in d["edges"]],
|
2100
|
-
edgeuuid2idx=d["edgeuuid2idx"],
|
2101
2098
|
edgetuple2uuid={tuple(item["k"]): item["v"] for item in d["edgetuple2uuid"]},
|
2102
2099
|
regions=[Region.__fromdict__(r) for r in d["regions"]],
|
2103
2100
|
legal_actions_3=[LegalAction.__fromdict__(x) for x in d["legal_actions_3"]],
|
@@ -2606,7 +2603,6 @@ def getinitialstate(game_config):
|
|
2606
2603
|
|
2607
2604
|
nodeuuid2idx = {node.uuid: idx for idx, node in enumerate(board_config.points)}
|
2608
2605
|
edges = get_edges(rng, board_config, nodeuuid2idx)
|
2609
|
-
edgeuuid2idx = {edge.uuid: idx for idx, edge in enumerate(edges)}
|
2610
2606
|
edgetuple2uuid = {}
|
2611
2607
|
for edge in edges:
|
2612
2608
|
node_1_idx = nodeuuid2idx[edge.node_1_uuid]
|
@@ -2662,7 +2658,6 @@ def getinitialstate(game_config):
|
|
2662
2658
|
nodes = nodes,
|
2663
2659
|
nodeuuid2idx = nodeuuid2idx,
|
2664
2660
|
edges = edges,
|
2665
|
-
edgeuuid2idx = edgeuuid2idx,
|
2666
2661
|
edgetuple2uuid = edgetuple2uuid,
|
2667
2662
|
regions = get_regions(board_config),
|
2668
2663
|
legal_actions_3=[],
|
@@ -2997,8 +2992,8 @@ def handle_draw_action(game, action):
|
|
2997
2992
|
)
|
2998
2993
|
|
2999
2994
|
# TODO: extract this out to user-defined function/hook
|
3000
|
-
if draw.quantity == 1:
|
3001
|
-
|
2995
|
+
# if draw.quantity == 1:
|
2996
|
+
# game = append_follow_up_draw_legal_actions(game, action)
|
3002
2997
|
|
3003
2998
|
return game
|
3004
2999
|
|
@@ -3017,22 +3012,6 @@ def handle_draw_discard_action(game, action):
|
|
3017
3012
|
for _ in range(draw_discard.quantity):
|
3018
3013
|
drawn_card = deck.facedown_stack.pop()
|
3019
3014
|
player.discard_tray.append(drawn_card)
|
3020
|
-
|
3021
|
-
game = append_to_legal_actions(
|
3022
|
-
game,
|
3023
|
-
LegalAction(
|
3024
|
-
player_idx=player.idx,
|
3025
|
-
name="GOAL-KEEP",
|
3026
|
-
instruction="Your move. Please select the routes you want to keep.",
|
3027
|
-
allotted_seconds=INITIAL_ALLOTTED_SECONDS,
|
3028
|
-
allotted_since_action_idx=(len(game.history) - 1),
|
3029
|
-
keep=LegalActionKeep(
|
3030
|
-
deck_idx=draw_discard.deck_idx,
|
3031
|
-
min=draw_discard.min,
|
3032
|
-
max=draw_discard.max,
|
3033
|
-
)
|
3034
|
-
)
|
3035
|
-
)
|
3036
3015
|
|
3037
3016
|
return game.set(
|
3038
3017
|
players=game.players,
|
@@ -3083,50 +3062,6 @@ def get_follow_up_draw_legal_actions(game, action):
|
|
3083
3062
|
return to_return
|
3084
3063
|
|
3085
3064
|
|
3086
|
-
def append_follow_up_draw_legal_actions(game, action):
|
3087
|
-
legal_action = action.legal_action
|
3088
|
-
if len(game.history) >= 2:
|
3089
|
-
last_action = game.history[-2]
|
3090
|
-
if (last_action.legal_action.player_idx != legal_action.player_idx) or last_action.legal_action.name == "INITIAL-GOAL-KEEP":
|
3091
|
-
|
3092
|
-
if len(game.decks[0].facedown_stack) >= 1:
|
3093
|
-
game = append_to_legal_actions(
|
3094
|
-
game,
|
3095
|
-
LegalAction(
|
3096
|
-
auto_preferred=True,
|
3097
|
-
player_idx=legal_action.player_idx,
|
3098
|
-
name="DRAW",
|
3099
|
-
instruction="draw a unit",
|
3100
|
-
allotted_seconds=DEFAULT_ALLOTTED_SECONDS,
|
3101
|
-
allotted_since_action_idx=(len(game.history) - 1),
|
3102
|
-
draw=LegalActionDraw(
|
3103
|
-
deck_idx=0,
|
3104
|
-
quantity=1,
|
3105
|
-
)
|
3106
|
-
)
|
3107
|
-
)
|
3108
|
-
|
3109
|
-
for card_uuid in game.decks[0].faceup_spots:
|
3110
|
-
if card_uuid:
|
3111
|
-
if not game.kernel.carduuid2card[card_uuid].is_wild:
|
3112
|
-
game = append_to_legal_actions(
|
3113
|
-
game,
|
3114
|
-
LegalAction(
|
3115
|
-
player_idx=legal_action.player_idx,
|
3116
|
-
name="FACEUP-DRAW",
|
3117
|
-
instruction="draw a faceup unit",
|
3118
|
-
allotted_seconds=DEFAULT_ALLOTTED_SECONDS,
|
3119
|
-
allotted_since_action_idx=(len(game.history) - 1),
|
3120
|
-
faceup_draw=LegalActionFaceupDraw(
|
3121
|
-
deck_idx=0,
|
3122
|
-
card_uuid=card_uuid,
|
3123
|
-
)
|
3124
|
-
)
|
3125
|
-
)
|
3126
|
-
|
3127
|
-
return game
|
3128
|
-
|
3129
|
-
|
3130
3065
|
def get_num_faceup_wilds(game, deck_idx):
|
3131
3066
|
deck = game.decks[deck_idx]
|
3132
3067
|
non_empty_spots = [spot for spot in deck.faceup_spots if spot]
|
@@ -3178,9 +3113,9 @@ def handle_faceup_draw_action(game, action):
|
|
3178
3113
|
game = replenish_faceup_spot_if_needed(game, faceup_draw.deck_idx, spot_idx)
|
3179
3114
|
|
3180
3115
|
# Prevent an extra draw if last draw was a face-wild-draw
|
3181
|
-
if not game.kernel.carduuid2card[drawn_card].is_wild:
|
3182
|
-
|
3183
|
-
|
3116
|
+
# if not game.kernel.carduuid2card[drawn_card].is_wild:
|
3117
|
+
# # TODO: extract this out to user-defined function/hook
|
3118
|
+
# game = append_follow_up_draw_legal_actions(game, action)
|
3184
3119
|
|
3185
3120
|
return game.set(
|
3186
3121
|
players=game.players,
|
@@ -3598,27 +3533,6 @@ def deal_cards_to_each_player(game, deck_idx, num_cards):
|
|
3598
3533
|
return game.set(players=game.players, decks=game.decks)
|
3599
3534
|
|
3600
3535
|
|
3601
|
-
def append_all_to_legal_actions(game, legal_actions):
|
3602
|
-
if not game or not legal_actions:
|
3603
|
-
return game
|
3604
|
-
|
3605
|
-
for legal_action in legal_actions:
|
3606
|
-
game = append_to_legal_actions(game, legal_action)
|
3607
|
-
|
3608
|
-
return game
|
3609
|
-
|
3610
|
-
|
3611
|
-
def append_to_legal_actions(game, legal_action):
|
3612
|
-
if not game:
|
3613
|
-
return game
|
3614
|
-
|
3615
|
-
game.legal_actions_3.append(
|
3616
|
-
legal_action
|
3617
|
-
)
|
3618
|
-
|
3619
|
-
return game.set(legal_actions_3=game.legal_actions_3)
|
3620
|
-
|
3621
|
-
|
3622
3536
|
def default_accept_action(game, action):
|
3623
3537
|
|
3624
3538
|
# Returns true if action.legal_action is found in game.legal_actions_3
|
@@ -3672,76 +3586,6 @@ def is_move_pieces_to_path_action_legal(game, action):
|
|
3672
3586
|
)
|
3673
3587
|
|
3674
3588
|
|
3675
|
-
def append_default_legal_actions_for_initial_player(game, action, log=False):
|
3676
|
-
# print("****************************************** Inside append_default_legal_actions_for_initial_player")
|
3677
|
-
|
3678
|
-
# Clone HOOK_NAMESPACE
|
3679
|
-
namespace = HOOK_NAMESPACE.copy()
|
3680
|
-
|
3681
|
-
try:
|
3682
|
-
# Execute the code string
|
3683
|
-
exec(DEFAULT_LEGAL_ACTIONS_HOOK, namespace)
|
3684
|
-
|
3685
|
-
# Retrieve the handler function
|
3686
|
-
handler_func = namespace.get('handler')
|
3687
|
-
|
3688
|
-
if handler_func is None or not callable(handler_func):
|
3689
|
-
raise ValueError("No callable function named 'handler' found in the code")
|
3690
|
-
|
3691
|
-
# Call the handler function
|
3692
|
-
result = handler_func(game, game.player_idxs[0])
|
3693
|
-
if log:
|
3694
|
-
pass
|
3695
|
-
# print(f"****************************** Running initialization hook 3: {hook.uuid} {result.player_idxs}")
|
3696
|
-
# print(f"****************************** Result of handler(5, 3): {result}")
|
3697
|
-
return result
|
3698
|
-
|
3699
|
-
except SyntaxError as e:
|
3700
|
-
msg = f"Syntax error in initialization hook: {str(e)}"
|
3701
|
-
logging.error(msg, exc_info=True)
|
3702
|
-
raise SyntaxError(msg) from e
|
3703
|
-
except Exception as e:
|
3704
|
-
msg = f"Error in initialization hook: {str(e)}"
|
3705
|
-
logging.error(msg, exc_info=True)
|
3706
|
-
raise Exception(msg) from e
|
3707
|
-
|
3708
|
-
|
3709
|
-
def append_default_legal_actions_for_next_player(game, action, log=False):
|
3710
|
-
|
3711
|
-
# Clone HOOK_NAMESPACE
|
3712
|
-
namespace = HOOK_NAMESPACE.copy()
|
3713
|
-
|
3714
|
-
try:
|
3715
|
-
# Execute the code string
|
3716
|
-
exec(DEFAULT_LEGAL_ACTIONS_HOOK, namespace)
|
3717
|
-
|
3718
|
-
# Retrieve the handler function
|
3719
|
-
handler_func = namespace.get('handler')
|
3720
|
-
|
3721
|
-
if handler_func is None or not callable(handler_func):
|
3722
|
-
raise ValueError("No callable function named 'handler' found in the code")
|
3723
|
-
|
3724
|
-
# Call the handler function
|
3725
|
-
last_player_idx = action.legal_action.player_idx
|
3726
|
-
last_player_shuffled_idx = game.player_idxs.index(last_player_idx)
|
3727
|
-
next_player_shuffled_idx = (last_player_shuffled_idx + 1) % len(game.player_idxs)
|
3728
|
-
result = handler_func(game, game.player_idxs[next_player_shuffled_idx])
|
3729
|
-
if log:
|
3730
|
-
pass
|
3731
|
-
# print(f"****************************** Running initialization hook 3: {hook.uuid} {result.player_idxs}")
|
3732
|
-
# print(f"****************************** Result of handler(5, 3): {result}")
|
3733
|
-
return result
|
3734
|
-
|
3735
|
-
except SyntaxError as e:
|
3736
|
-
msg = f"Syntax error in initialization hook: {str(e)}"
|
3737
|
-
logging.error(msg, exc_info=True)
|
3738
|
-
raise SyntaxError(msg) from e
|
3739
|
-
except Exception as e:
|
3740
|
-
msg = f"Error in initialization hook: {str(e)}"
|
3741
|
-
logging.error(msg, exc_info=True)
|
3742
|
-
raise Exception(msg) from e
|
3743
|
-
|
3744
|
-
|
3745
3589
|
def get_total_path_count(game):
|
3746
3590
|
return len(game.idx2path)
|
3747
3591
|
|
@@ -3859,11 +3703,7 @@ HOOK_NAMESPACE = {
|
|
3859
3703
|
'find_player_with_longest_path_card': find_player_with_longest_path_card,
|
3860
3704
|
'default_after_accept_action': default_after_accept_action,
|
3861
3705
|
'default_accept_action': default_accept_action,
|
3862
|
-
'append_default_legal_actions_for_initial_player': append_default_legal_actions_for_initial_player,
|
3863
|
-
'append_default_legal_actions_for_next_player': append_default_legal_actions_for_next_player,
|
3864
3706
|
'LegalAction': LegalAction,
|
3865
|
-
'append_to_legal_actions': append_to_legal_actions,
|
3866
|
-
'append_all_to_legal_actions': append_all_to_legal_actions,
|
3867
3707
|
'LegalActionDraw': LegalActionDraw,
|
3868
3708
|
'LegalActionDrawDiscard': LegalActionDrawDiscard,
|
3869
3709
|
'LegalActionFaceupDraw': LegalActionFaceupDraw,
|
@@ -4231,7 +4071,6 @@ def init_state(kernel):
|
|
4231
4071
|
is_terminal=False,
|
4232
4072
|
idx2path=kernel.idx2path,
|
4233
4073
|
pieceuuid2piece=kernel.pieceuuid2piece,
|
4234
|
-
edgeuuid2idx=kernel.edgeuuid2idx,
|
4235
4074
|
carduuid2card=kernel.carduuid2card,
|
4236
4075
|
)
|
4237
4076
|
state = state.set(legal_actions_3=calc_legal_actions3(kernel))
|
@@ -5348,107 +5187,10 @@ INIT_HOOK_4 = """def handler(game):
|
|
5348
5187
|
INIT_HOOK_5 = """def handler(game):
|
5349
5188
|
return flip_cards(game, 0, 5)
|
5350
5189
|
"""
|
5351
|
-
INIT_HOOK_6 = """def handler(game):
|
5352
|
-
for player in game.players:
|
5353
|
-
game = append_to_legal_actions(
|
5354
|
-
game,
|
5355
|
-
LegalAction(
|
5356
|
-
player_idx=player.idx,
|
5357
|
-
name="INITIAL-GOAL-KEEP",
|
5358
|
-
instruction="Your move. Please select the routes you want to keep.",
|
5359
|
-
allotted_seconds=INITIAL_ALLOTTED_SECONDS,
|
5360
|
-
allotted_since_action_idx=(len(game.history) - 1),
|
5361
|
-
keep=LegalActionKeep(
|
5362
|
-
deck_idx=1,
|
5363
|
-
min=2,
|
5364
|
-
)
|
5365
|
-
)
|
5366
|
-
)
|
5367
|
-
return game
|
5368
|
-
"""
|
5369
5190
|
INIT_HOOK_7 = """def handler(game):
|
5370
5191
|
return shuffle_player_order(game)
|
5371
5192
|
"""
|
5372
5193
|
|
5373
|
-
DEFAULT_LEGAL_ACTIONS_HOOK = """def handler(game, player_idx):
|
5374
|
-
allotted_seconds = DEFAULT_ALLOTTED_SECONDS
|
5375
|
-
allotted_since_action_idx = len(game.history) - 1
|
5376
|
-
|
5377
|
-
if len(game.decks[1].facedown_stack) >= 1:
|
5378
|
-
game = append_to_legal_actions(
|
5379
|
-
game,
|
5380
|
-
LegalAction(
|
5381
|
-
player_idx=player_idx,
|
5382
|
-
name="DRAW-GOAL",
|
5383
|
-
instruction="draw a route",
|
5384
|
-
allotted_seconds=allotted_seconds,
|
5385
|
-
allotted_since_action_idx=allotted_since_action_idx,
|
5386
|
-
draw_discard=LegalActionDrawDiscard(
|
5387
|
-
deck_idx=1,
|
5388
|
-
quantity=3,
|
5389
|
-
min=1,
|
5390
|
-
)
|
5391
|
-
)
|
5392
|
-
)
|
5393
|
-
|
5394
|
-
if len(game.decks[0].facedown_stack) >= 1:
|
5395
|
-
game = append_to_legal_actions(
|
5396
|
-
game,
|
5397
|
-
LegalAction(
|
5398
|
-
auto_preferred=True,
|
5399
|
-
player_idx=player_idx,
|
5400
|
-
name="DRAW",
|
5401
|
-
instruction="draw a unit",
|
5402
|
-
allotted_seconds=allotted_seconds,
|
5403
|
-
allotted_since_action_idx=allotted_since_action_idx,
|
5404
|
-
draw=LegalActionDraw(
|
5405
|
-
deck_idx=0,
|
5406
|
-
quantity=1,
|
5407
|
-
)
|
5408
|
-
)
|
5409
|
-
)
|
5410
|
-
|
5411
|
-
if len(game.decks[0].facedown_stack) >= 2:
|
5412
|
-
game = append_to_legal_actions(
|
5413
|
-
game,
|
5414
|
-
LegalAction(
|
5415
|
-
player_idx=player_idx,
|
5416
|
-
name="DRAW-DOUBLE",
|
5417
|
-
instruction="draw 2 units",
|
5418
|
-
allotted_seconds=allotted_seconds,
|
5419
|
-
allotted_since_action_idx=allotted_since_action_idx,
|
5420
|
-
draw=LegalActionDraw(
|
5421
|
-
deck_idx=0,
|
5422
|
-
quantity=2,
|
5423
|
-
)
|
5424
|
-
)
|
5425
|
-
)
|
5426
|
-
|
5427
|
-
for card_uuid in game.decks[0].faceup_spots:
|
5428
|
-
if card_uuid:
|
5429
|
-
game = append_to_legal_actions(
|
5430
|
-
game,
|
5431
|
-
LegalAction(
|
5432
|
-
player_idx=player_idx,
|
5433
|
-
name="FACEUP-DRAW",
|
5434
|
-
instruction="draw a faceup unit",
|
5435
|
-
allotted_seconds=allotted_seconds,
|
5436
|
-
allotted_since_action_idx=allotted_since_action_idx,
|
5437
|
-
faceup_draw=LegalActionFaceupDraw(
|
5438
|
-
deck_idx=0,
|
5439
|
-
card_uuid=card_uuid,
|
5440
|
-
)
|
5441
|
-
)
|
5442
|
-
)
|
5443
|
-
|
5444
|
-
game = append_all_to_legal_actions(
|
5445
|
-
game,
|
5446
|
-
get_legal_actions_for_paths(game, player_idx),
|
5447
|
-
)
|
5448
|
-
|
5449
|
-
return game
|
5450
|
-
"""
|
5451
|
-
|
5452
5194
|
INITIALIZATION_HOOKS = [
|
5453
5195
|
Hook(
|
5454
5196
|
name="SampleHook1",
|
@@ -5480,12 +5222,6 @@ INITIALIZATION_HOOKS = [
|
|
5480
5222
|
when="AFTER_GAME_STARTS",
|
5481
5223
|
code=INIT_HOOK_5,
|
5482
5224
|
),
|
5483
|
-
Hook(
|
5484
|
-
name="SampleHook6",
|
5485
|
-
uuid="e3079338-7eac-4180-979c-69dedbe1eabd",
|
5486
|
-
when="AFTER_GAME_STARTS",
|
5487
|
-
code=INIT_HOOK_6,
|
5488
|
-
),
|
5489
5225
|
Hook(
|
5490
5226
|
name="SampleHook7",
|
5491
5227
|
uuid="240b8706-7fcf-4d35-9894-276aa10f799f",
|
@@ -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=VGAFpUF4NHnQqnuLNYIc9EfNumKx49IKvg7a-8eQEDo,182032
|
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.1934.dist-info/METADATA,sha256=06szQT5VQPzcO7sGenz5Ozo0sd32urAf2ydz9mBsNhU,188
|
7
|
+
graph_games_proto-0.3.1934.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
8
|
+
graph_games_proto-0.3.1934.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
|
9
|
+
graph_games_proto-0.3.1934.dist-info/RECORD,,
|
File without changes
|
File without changes
|