graph-games-proto 0.3.1930__py3-none-any.whl → 0.3.1932__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 -263
- {graph_games_proto-0.3.1930.dist-info → graph_games_proto-0.3.1932.dist-info}/METADATA +1 -1
- {graph_games_proto-0.3.1930.dist-info → graph_games_proto-0.3.1932.dist-info}/RECORD +5 -5
- {graph_games_proto-0.3.1930.dist-info → graph_games_proto-0.3.1932.dist-info}/WHEEL +0 -0
- {graph_games_proto-0.3.1930.dist-info → graph_games_proto-0.3.1932.dist-info}/top_level.txt +0 -0
graph_games_proto/fns.py
CHANGED
@@ -2997,8 +2997,8 @@ def handle_draw_action(game, action):
|
|
2997
2997
|
)
|
2998
2998
|
|
2999
2999
|
# TODO: extract this out to user-defined function/hook
|
3000
|
-
if draw.quantity == 1:
|
3001
|
-
|
3000
|
+
# if draw.quantity == 1:
|
3001
|
+
# game = append_follow_up_draw_legal_actions(game, action)
|
3002
3002
|
|
3003
3003
|
return game
|
3004
3004
|
|
@@ -3017,22 +3017,6 @@ def handle_draw_discard_action(game, action):
|
|
3017
3017
|
for _ in range(draw_discard.quantity):
|
3018
3018
|
drawn_card = deck.facedown_stack.pop()
|
3019
3019
|
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
3020
|
|
3037
3021
|
return game.set(
|
3038
3022
|
players=game.players,
|
@@ -3083,50 +3067,6 @@ def get_follow_up_draw_legal_actions(game, action):
|
|
3083
3067
|
return to_return
|
3084
3068
|
|
3085
3069
|
|
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
3070
|
def get_num_faceup_wilds(game, deck_idx):
|
3131
3071
|
deck = game.decks[deck_idx]
|
3132
3072
|
non_empty_spots = [spot for spot in deck.faceup_spots if spot]
|
@@ -3178,9 +3118,9 @@ def handle_faceup_draw_action(game, action):
|
|
3178
3118
|
game = replenish_faceup_spot_if_needed(game, faceup_draw.deck_idx, spot_idx)
|
3179
3119
|
|
3180
3120
|
# Prevent an extra draw if last draw was a face-wild-draw
|
3181
|
-
if not game.kernel.carduuid2card[drawn_card].is_wild:
|
3182
|
-
|
3183
|
-
|
3121
|
+
# if not game.kernel.carduuid2card[drawn_card].is_wild:
|
3122
|
+
# # TODO: extract this out to user-defined function/hook
|
3123
|
+
# game = append_follow_up_draw_legal_actions(game, action)
|
3184
3124
|
|
3185
3125
|
return game.set(
|
3186
3126
|
players=game.players,
|
@@ -3598,27 +3538,6 @@ def deal_cards_to_each_player(game, deck_idx, num_cards):
|
|
3598
3538
|
return game.set(players=game.players, decks=game.decks)
|
3599
3539
|
|
3600
3540
|
|
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
3541
|
def default_accept_action(game, action):
|
3623
3542
|
|
3624
3543
|
# Returns true if action.legal_action is found in game.legal_actions_3
|
@@ -3672,76 +3591,6 @@ def is_move_pieces_to_path_action_legal(game, action):
|
|
3672
3591
|
)
|
3673
3592
|
|
3674
3593
|
|
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
3594
|
def get_total_path_count(game):
|
3746
3595
|
return len(game.idx2path)
|
3747
3596
|
|
@@ -3859,11 +3708,7 @@ HOOK_NAMESPACE = {
|
|
3859
3708
|
'find_player_with_longest_path_card': find_player_with_longest_path_card,
|
3860
3709
|
'default_after_accept_action': default_after_accept_action,
|
3861
3710
|
'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
3711
|
'LegalAction': LegalAction,
|
3865
|
-
'append_to_legal_actions': append_to_legal_actions,
|
3866
|
-
'append_all_to_legal_actions': append_all_to_legal_actions,
|
3867
3712
|
'LegalActionDraw': LegalActionDraw,
|
3868
3713
|
'LegalActionDrawDiscard': LegalActionDrawDiscard,
|
3869
3714
|
'LegalActionFaceupDraw': LegalActionFaceupDraw,
|
@@ -5348,107 +5193,10 @@ INIT_HOOK_4 = """def handler(game):
|
|
5348
5193
|
INIT_HOOK_5 = """def handler(game):
|
5349
5194
|
return flip_cards(game, 0, 5)
|
5350
5195
|
"""
|
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
5196
|
INIT_HOOK_7 = """def handler(game):
|
5370
5197
|
return shuffle_player_order(game)
|
5371
5198
|
"""
|
5372
5199
|
|
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
5200
|
INITIALIZATION_HOOKS = [
|
5453
5201
|
Hook(
|
5454
5202
|
name="SampleHook1",
|
@@ -5480,12 +5228,6 @@ INITIALIZATION_HOOKS = [
|
|
5480
5228
|
when="AFTER_GAME_STARTS",
|
5481
5229
|
code=INIT_HOOK_5,
|
5482
5230
|
),
|
5483
|
-
Hook(
|
5484
|
-
name="SampleHook6",
|
5485
|
-
uuid="e3079338-7eac-4180-979c-69dedbe1eabd",
|
5486
|
-
when="AFTER_GAME_STARTS",
|
5487
|
-
code=INIT_HOOK_6,
|
5488
|
-
),
|
5489
5231
|
Hook(
|
5490
5232
|
name="SampleHook7",
|
5491
5233
|
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=Fe6oj26zjtA2fjKLYykDVEjTaIlB_Emqtl3pmFZd6L0,182326
|
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.1932.dist-info/METADATA,sha256=UF-G7lsx2_WwzGEGaJ_EFeOfq_PP3tDQ2OfC-ifXUFA,188
|
7
|
+
graph_games_proto-0.3.1932.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
8
|
+
graph_games_proto-0.3.1932.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
|
9
|
+
graph_games_proto-0.3.1932.dist-info/RECORD,,
|
File without changes
|
File without changes
|