graph-games-proto 0.3.2035__py3-none-any.whl → 0.3.2039__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 +47 -75
- {graph_games_proto-0.3.2035.dist-info → graph_games_proto-0.3.2039.dist-info}/METADATA +1 -1
- {graph_games_proto-0.3.2035.dist-info → graph_games_proto-0.3.2039.dist-info}/RECORD +5 -5
- {graph_games_proto-0.3.2035.dist-info → graph_games_proto-0.3.2039.dist-info}/WHEEL +0 -0
- {graph_games_proto-0.3.2035.dist-info → graph_games_proto-0.3.2039.dist-info}/top_level.txt +0 -0
graph_games_proto/fns.py
CHANGED
@@ -2353,7 +2353,7 @@ class PublicState(PClass):
|
|
2353
2353
|
goals = field(type=list) # List[Goal]
|
2354
2354
|
nodes = field(type=list) # List[Node]
|
2355
2355
|
edges = field(type=list) # List[BiEdge]
|
2356
|
-
regions = field(type=list)
|
2356
|
+
regions = field(type=list, initial=[])
|
2357
2357
|
decks = field(type=list) # List[PublicDeck]
|
2358
2358
|
piles = field(type=list) # List[Pile]
|
2359
2359
|
player_idxs = field(type=list) # List[int]
|
@@ -2558,24 +2558,15 @@ def getsettingvalue(s, setting_name):
|
|
2558
2558
|
|
2559
2559
|
@dispatch(GameConfig)
|
2560
2560
|
def getinitialstate(game_config):
|
2561
|
-
fig = game_config.fig
|
2562
2561
|
rng = getrng(game_config.seed)
|
2563
|
-
|
2564
|
-
route_deck_idx, unit_deck_idx = 0, 0
|
2565
|
-
unit_deck_idx += 5
|
2566
|
-
board_config = fig.board_config
|
2567
|
-
deck_0_rng = getrng(1234321)
|
2568
|
-
deck_1_rng = getrng(8738758)
|
2562
|
+
board_config = game_config.fig.board_config
|
2569
2563
|
nodes = get_nodes(board_config)
|
2570
2564
|
|
2571
|
-
pieceuuid2piece = {}
|
2572
2565
|
piles = []
|
2573
2566
|
for piece_template in board_config.piece_templates:
|
2574
2567
|
if piece_template.has_player:
|
2575
2568
|
for player_idx in range(game_config.num_players):
|
2576
2569
|
pieces = generate_pieces(piece_template, player_idx)
|
2577
|
-
for piece in pieces:
|
2578
|
-
pieceuuid2piece[piece.uuid] = piece
|
2579
2570
|
pile = Pile(
|
2580
2571
|
player_idx=player_idx,
|
2581
2572
|
num_pieces=piece_template.quantity,
|
@@ -2596,25 +2587,22 @@ def getinitialstate(game_config):
|
|
2596
2587
|
)
|
2597
2588
|
decks.append(deck_obj)
|
2598
2589
|
|
2599
|
-
|
2600
|
-
|
2601
|
-
|
2602
|
-
|
2603
|
-
|
2604
|
-
|
2605
|
-
|
2606
|
-
|
2607
|
-
|
2608
|
-
|
2609
|
-
|
2610
|
-
|
2611
|
-
|
2612
|
-
|
2613
|
-
|
2614
|
-
|
2615
|
-
)
|
2616
|
-
for bonus in bonuses
|
2617
|
-
]
|
2590
|
+
# bonuses = game_config.fig.board_config.bonuses
|
2591
|
+
# bonus_statuses = [
|
2592
|
+
# BonusStatus(
|
2593
|
+
# bonus_uuid=bonus.uuid,
|
2594
|
+
# winners=[],
|
2595
|
+
# player_statuses=[
|
2596
|
+
# BonusPlayerStatus(
|
2597
|
+
# player_idx=player_idx,
|
2598
|
+
# score=0,
|
2599
|
+
# longest_trail=None,
|
2600
|
+
# )
|
2601
|
+
# for player_idx in range(game_config.num_players)
|
2602
|
+
# ]
|
2603
|
+
# )
|
2604
|
+
# for bonus in bonuses
|
2605
|
+
# ]
|
2618
2606
|
|
2619
2607
|
# state = State(
|
2620
2608
|
# bonus_statuses=bonus_statuses,
|
@@ -2638,6 +2626,9 @@ def getinitialstate(game_config):
|
|
2638
2626
|
# last_to_play=None,
|
2639
2627
|
# winners=[],
|
2640
2628
|
# )
|
2629
|
+
|
2630
|
+
nodeuuid2idx = {node.uuid: idx for idx, node in enumerate(board_config.points)}
|
2631
|
+
edges = get_edges(rng, board_config, nodeuuid2idx)
|
2641
2632
|
|
2642
2633
|
kernel = init_state_kernel(
|
2643
2634
|
rng=rng,
|
@@ -2657,15 +2648,23 @@ def getinitialstate(game_config):
|
|
2657
2648
|
|
2658
2649
|
kernel = run_kernel_hooks(kernel, INITIALIZATION_HOOKS, True)
|
2659
2650
|
|
2651
|
+
return init_memoized_state(kernel)
|
2652
|
+
|
2653
|
+
|
2654
|
+
@dispatch(StateKernel)
|
2655
|
+
def init_memoized_state(kernel):
|
2660
2656
|
state = State(
|
2661
2657
|
kernel=kernel,
|
2662
2658
|
legal_actions_3=calc_legal_actions3(kernel),
|
2663
2659
|
bonus_statuses_3=calc_bonus_statuses3(kernel),
|
2664
2660
|
)
|
2665
|
-
|
2661
|
+
return memoize_state(state)
|
2662
|
+
|
2663
|
+
|
2664
|
+
@dispatch(State)
|
2665
|
+
def memoize_state(state):
|
2666
2666
|
state = state.set(player_scores_3=calc_player_scores3(state))
|
2667
2667
|
state = state.set(winners=calc_winners_3(state))
|
2668
|
-
|
2669
2668
|
return state
|
2670
2669
|
|
2671
2670
|
|
@@ -2866,10 +2865,11 @@ def handle_last_to_play(game):
|
|
2866
2865
|
return game
|
2867
2866
|
|
2868
2867
|
|
2869
|
-
|
2868
|
+
@dispatch(State)
|
2869
|
+
def getfinalscores(state):
|
2870
2870
|
return [
|
2871
|
-
getpublicplayerscore(
|
2872
|
-
for player_idx in range(len(
|
2871
|
+
getpublicplayerscore(state, state.player_scores_3[player_idx]).total
|
2872
|
+
for player_idx in range(len(state.kernel.players))
|
2873
2873
|
]
|
2874
2874
|
|
2875
2875
|
|
@@ -4371,46 +4371,14 @@ def get_next_player_shuffled_idx(state_kernel, last_action):
|
|
4371
4371
|
return next_player_shuffled_idx
|
4372
4372
|
|
4373
4373
|
|
4374
|
-
def init_state(kernel):
|
4375
|
-
|
4376
|
-
legal_actions_3 = calc_legal_actions3(kernel)
|
4377
|
-
|
4378
|
-
return State(
|
4379
|
-
kernel=kernel,
|
4380
|
-
rng=kernel.rng,
|
4381
|
-
game_config=kernel.game_config,
|
4382
|
-
edges=kernel.edges,
|
4383
|
-
decks=kernel.decks,
|
4384
|
-
piles=kernel.piles,
|
4385
|
-
players=kernel.players,
|
4386
|
-
player_idxs=kernel.player_idxs,
|
4387
|
-
history=kernel.history,
|
4388
|
-
player_scores=kernel.player_scores,
|
4389
|
-
is_terminal=False,
|
4390
|
-
idx2path=kernel.idx2path,
|
4391
|
-
carduuid2card=kernel.carduuid2card,
|
4392
|
-
legal_actions_3=legal_actions_3,
|
4393
|
-
)
|
4394
|
-
|
4395
|
-
|
4396
4374
|
def getnextstate2(s, a, log=False):
|
4397
4375
|
is_legal, reason = isactionlegal2(s, a)
|
4398
4376
|
if not is_legal:
|
4399
4377
|
raise ValueError(f"Action is not legal: {a}. Reason: {reason}")
|
4400
|
-
|
4401
4378
|
kernel = s.kernel
|
4402
4379
|
kernel = run_state_action_hooks(kernel, a, AFTER_ACCEPT_ACTION_HOOKS, log)
|
4403
4380
|
kernel = run_state_action_hooks(kernel, a, HANDLE_ACTION_HOOKS, log)
|
4404
|
-
|
4405
|
-
state = State(
|
4406
|
-
kernel=kernel,
|
4407
|
-
legal_actions_3=calc_legal_actions3(kernel),
|
4408
|
-
bonus_statuses_3=calc_bonus_statuses3(kernel),
|
4409
|
-
)
|
4410
|
-
state = state.set(player_scores_3=calc_player_scores3(state))
|
4411
|
-
state = state.set(winners=calc_winners_3(state))
|
4412
|
-
|
4413
|
-
return state
|
4381
|
+
return init_memoized_state(kernel)
|
4414
4382
|
|
4415
4383
|
|
4416
4384
|
def getpublicplayerscore(s, player_score):
|
@@ -4498,7 +4466,7 @@ def get_deadlines(s):
|
|
4498
4466
|
|
4499
4467
|
|
4500
4468
|
def get_public_player_scores(s):
|
4501
|
-
return [getpublicplayerscore(s, player_score) for player_score in s.
|
4469
|
+
return [getpublicplayerscore(s, player_score) for player_score in s.player_scores_3]
|
4502
4470
|
|
4503
4471
|
|
4504
4472
|
# deadlines = field(type=list) # List[RemainingAllottedTime|None]
|
@@ -4552,19 +4520,23 @@ def imagine_decks(public_state, private_state):
|
|
4552
4520
|
|
4553
4521
|
|
4554
4522
|
def imagine_state(public_state, private_state):
|
4523
|
+
game_config = public_state.game_config
|
4555
4524
|
imagined_kernel = init_state_kernel(
|
4556
4525
|
rng=random.Random(),
|
4557
|
-
game_config=
|
4558
|
-
player_idxs=public_state.player_idxs,
|
4559
|
-
piles=public_state.piles,
|
4526
|
+
game_config=game_config,
|
4560
4527
|
edges=public_state.edges,
|
4561
4528
|
nodes=public_state.nodes,
|
4529
|
+
piles=public_state.piles,
|
4562
4530
|
decks=imagine_decks(public_state, private_state),
|
4563
4531
|
players=imagine_players(public_state, private_state),
|
4532
|
+
player_idxs=public_state.player_idxs,
|
4564
4533
|
history=imagine_history(public_state, private_state),
|
4565
4534
|
player_scores=imagine_player_scores(public_state, private_state),
|
4535
|
+
starting_decks=[Deck.__fromdict__(x.__todict__()) for x in decks],
|
4536
|
+
starting_piles=[Pile.__fromdict__(x.__todict__()) for x in public_state.piles],
|
4537
|
+
goals=game_config.fig.board_config.goals,
|
4566
4538
|
)
|
4567
|
-
return
|
4539
|
+
return init_memoized_state(imagined_kernel)
|
4568
4540
|
|
4569
4541
|
|
4570
4542
|
def isterminal(s):
|
@@ -5265,8 +5237,8 @@ def json2rng(json_str):
|
|
5265
5237
|
def getprivatestate(s, player_idx):
|
5266
5238
|
return PrivateState(
|
5267
5239
|
my_history=[a for a in s.kernel.history if a.legal_action.player_idx == player_idx],
|
5268
|
-
player_score=getprivateplayerscore(s, s.
|
5269
|
-
player=s.players[player_idx],
|
5240
|
+
player_score=getprivateplayerscore(s, s.player_scores_3[player_idx]),
|
5241
|
+
player=s.kernel.players[player_idx],
|
5270
5242
|
legal_actions_3 = get_legal_actions3(s, player_idx),
|
5271
5243
|
goal_completions=get_goal_completions(s, player_idx),
|
5272
5244
|
)
|
@@ -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=xzSeQYeahx_uSrtHTJe39hKi3Yr62nbP8TqSfLI8hqo,193768
|
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.2039.dist-info/METADATA,sha256=grOQHZLAL8ZQuABz0vYugwNOAcBE15jFo58975fsJi0,188
|
7
|
+
graph_games_proto-0.3.2039.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
8
|
+
graph_games_proto-0.3.2039.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
|
9
|
+
graph_games_proto-0.3.2039.dist-info/RECORD,,
|
File without changes
|
File without changes
|