graph-games-proto 0.3.2031__py3-none-any.whl → 0.3.2036__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 CHANGED
@@ -2090,10 +2090,6 @@ class State(PClass):
2090
2090
  player_scores_3 = field(type=list) # List[PlayerScore2]
2091
2091
  winners = field(type=list) # List[int]
2092
2092
 
2093
- player_graphs = field(type=list) # List[PlayerGraph]
2094
- player_scores = field(type=list) # List[PlayerScore2]
2095
- bonus_statuses = field(type=list) # List[BonusStatus]
2096
-
2097
2093
  def __todict__(self):
2098
2094
  return {
2099
2095
  "kernel": self.kernel.__todict__(),
@@ -2562,24 +2558,15 @@ def getsettingvalue(s, setting_name):
2562
2558
 
2563
2559
  @dispatch(GameConfig)
2564
2560
  def getinitialstate(game_config):
2565
- fig = game_config.fig
2566
2561
  rng = getrng(game_config.seed)
2567
- unit_deck = shuffledeck(gettotaldeckcards(fig), rng)
2568
- route_deck_idx, unit_deck_idx = 0, 0
2569
- unit_deck_idx += 5
2570
- board_config = fig.board_config
2571
- deck_0_rng = getrng(1234321)
2572
- deck_1_rng = getrng(8738758)
2562
+ board_config = game_config.fig.board_config
2573
2563
  nodes = get_nodes(board_config)
2574
2564
 
2575
- pieceuuid2piece = {}
2576
2565
  piles = []
2577
2566
  for piece_template in board_config.piece_templates:
2578
2567
  if piece_template.has_player:
2579
2568
  for player_idx in range(game_config.num_players):
2580
2569
  pieces = generate_pieces(piece_template, player_idx)
2581
- for piece in pieces:
2582
- pieceuuid2piece[piece.uuid] = piece
2583
2570
  pile = Pile(
2584
2571
  player_idx=player_idx,
2585
2572
  num_pieces=piece_template.quantity,
@@ -2600,25 +2587,22 @@ def getinitialstate(game_config):
2600
2587
  )
2601
2588
  decks.append(deck_obj)
2602
2589
 
2603
- nodeuuid2idx = {node.uuid: idx for idx, node in enumerate(board_config.points)}
2604
- edges = get_edges(rng, board_config, nodeuuid2idx)
2605
-
2606
- bonuses = game_config.fig.board_config.bonuses
2607
- bonus_statuses = [
2608
- BonusStatus(
2609
- bonus_uuid=bonus.uuid,
2610
- winners=[],
2611
- player_statuses=[
2612
- BonusPlayerStatus(
2613
- player_idx=player_idx,
2614
- score=0,
2615
- longest_trail=None,
2616
- )
2617
- for player_idx in range(game_config.num_players)
2618
- ]
2619
- )
2620
- for bonus in bonuses
2621
- ]
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
+ # ]
2622
2606
 
2623
2607
  # state = State(
2624
2608
  # bonus_statuses=bonus_statuses,
@@ -2642,6 +2626,9 @@ def getinitialstate(game_config):
2642
2626
  # last_to_play=None,
2643
2627
  # winners=[],
2644
2628
  # )
2629
+
2630
+ nodeuuid2idx = {node.uuid: idx for idx, node in enumerate(board_config.points)}
2631
+ edges = get_edges(rng, board_config, nodeuuid2idx)
2645
2632
 
2646
2633
  kernel = init_state_kernel(
2647
2634
  rng=rng,
@@ -2661,15 +2648,23 @@ def getinitialstate(game_config):
2661
2648
 
2662
2649
  kernel = run_kernel_hooks(kernel, INITIALIZATION_HOOKS, True)
2663
2650
 
2651
+ return init_memoized_state(kernel)
2652
+
2653
+
2654
+ @dispatch(StateKernel)
2655
+ def init_memoized_state(kernel):
2664
2656
  state = State(
2665
2657
  kernel=kernel,
2666
2658
  legal_actions_3=calc_legal_actions3(kernel),
2667
2659
  bonus_statuses_3=calc_bonus_statuses3(kernel),
2668
2660
  )
2669
-
2661
+ return memoize_state(state)
2662
+
2663
+
2664
+ @dispatch(State)
2665
+ def memoize_state(state):
2670
2666
  state = state.set(player_scores_3=calc_player_scores3(state))
2671
2667
  state = state.set(winners=calc_winners_3(state))
2672
-
2673
2668
  return state
2674
2669
 
2675
2670
 
@@ -2864,16 +2859,17 @@ def handle_last_to_play(game):
2864
2859
  for player in game.players:
2865
2860
  if len(player.pieces) < 3:
2866
2861
  return game.set(last_to_play=player.idx)
2867
- elif game.last_to_play == game.history[-1].legal_action.player_idx:
2862
+ elif game.last_to_play == game.kernel.history[-1].legal_action.player_idx:
2868
2863
  if not game.legal_actions_3:
2869
2864
  return game.set(terminal=True)
2870
2865
  return game
2871
2866
 
2872
2867
 
2873
- def getfinalscores(game):
2868
+ @dispatch(State)
2869
+ def getfinalscores(state):
2874
2870
  return [
2875
- getpublicplayerscore(game, game.player_scores[player_idx]).total
2876
- for player_idx in range(len(game.players))
2871
+ getpublicplayerscore(state, state.player_scores_3[player_idx]).total
2872
+ for player_idx in range(len(state.kernel.players))
2877
2873
  ]
2878
2874
 
2879
2875
 
@@ -3170,14 +3166,15 @@ def handle_draw_discard_action(kernel, action):
3170
3166
  )
3171
3167
 
3172
3168
 
3173
- def get_follow_up_draw_legal_actions(game, action):
3169
+ @dispatch(State, Action2)
3170
+ def get_follow_up_draw_legal_actions(state, action):
3174
3171
  to_return = []
3175
3172
  legal_action = action.legal_action
3176
- if len(game.history) >= 2:
3177
- last_action = game.history[-2]
3173
+ if len(state.kernel.history) >= 2:
3174
+ last_action = state.kernel.history[-2]
3178
3175
  if (last_action.legal_action.player_idx != legal_action.player_idx) or last_action.legal_action.name == "INITIAL-GOAL-KEEP":
3179
3176
 
3180
- if len(game.decks[0].facedown_stack) >= 1:
3177
+ if len(state.kernel.decks[0].facedown_stack) >= 1:
3181
3178
  to_return.append(
3182
3179
  LegalAction(
3183
3180
  auto_preferred=True,
@@ -3185,7 +3182,7 @@ def get_follow_up_draw_legal_actions(game, action):
3185
3182
  name="DRAW",
3186
3183
  instruction="draw a unit",
3187
3184
  allotted_seconds=DEFAULT_ALLOTTED_SECONDS,
3188
- allotted_since_action_idx=(len(game.history) - 1),
3185
+ allotted_since_action_idx=(len(state.kernel.history) - 1),
3189
3186
  draw=LegalActionDraw(
3190
3187
  deck_idx=0,
3191
3188
  quantity=1,
@@ -3193,16 +3190,16 @@ def get_follow_up_draw_legal_actions(game, action):
3193
3190
  )
3194
3191
  )
3195
3192
 
3196
- for card_uuid in game.decks[0].faceup_spots:
3193
+ for card_uuid in state.kernel.decks[0].faceup_spots:
3197
3194
  if card_uuid:
3198
- if not game.carduuid2card[card_uuid].is_wild:
3195
+ if not state.kernel.carduuid2card[card_uuid].is_wild:
3199
3196
  to_return.append(
3200
3197
  LegalAction(
3201
3198
  player_idx=legal_action.player_idx,
3202
3199
  name="FACEUP-DRAW",
3203
3200
  instruction="draw a faceup unit",
3204
3201
  allotted_seconds=DEFAULT_ALLOTTED_SECONDS,
3205
- allotted_since_action_idx=(len(game.history) - 1),
3202
+ allotted_since_action_idx=(len(state.kernel.history) - 1),
3206
3203
  faceup_draw=LegalActionFaceupDraw(
3207
3204
  deck_idx=0,
3208
3205
  card_uuid=card_uuid,
@@ -4374,46 +4371,14 @@ def get_next_player_shuffled_idx(state_kernel, last_action):
4374
4371
  return next_player_shuffled_idx
4375
4372
 
4376
4373
 
4377
- def init_state(kernel):
4378
-
4379
- legal_actions_3 = calc_legal_actions3(kernel)
4380
-
4381
- return State(
4382
- kernel=kernel,
4383
- rng=kernel.rng,
4384
- game_config=kernel.game_config,
4385
- edges=kernel.edges,
4386
- decks=kernel.decks,
4387
- piles=kernel.piles,
4388
- players=kernel.players,
4389
- player_idxs=kernel.player_idxs,
4390
- history=kernel.history,
4391
- player_scores=kernel.player_scores,
4392
- is_terminal=False,
4393
- idx2path=kernel.idx2path,
4394
- carduuid2card=kernel.carduuid2card,
4395
- legal_actions_3=legal_actions_3,
4396
- )
4397
-
4398
-
4399
4374
  def getnextstate2(s, a, log=False):
4400
4375
  is_legal, reason = isactionlegal2(s, a)
4401
4376
  if not is_legal:
4402
4377
  raise ValueError(f"Action is not legal: {a}. Reason: {reason}")
4403
-
4404
4378
  kernel = s.kernel
4405
4379
  kernel = run_state_action_hooks(kernel, a, AFTER_ACCEPT_ACTION_HOOKS, log)
4406
4380
  kernel = run_state_action_hooks(kernel, a, HANDLE_ACTION_HOOKS, log)
4407
-
4408
- state = State(
4409
- kernel=kernel,
4410
- legal_actions_3=calc_legal_actions3(kernel),
4411
- bonus_statuses_3=calc_bonus_statuses3(kernel),
4412
- )
4413
- state = state.set(player_scores_3=calc_player_scores3(state))
4414
- state = state.set(winners=calc_winners_3(state))
4415
-
4416
- return state
4381
+ return init_memoized_state(kernel)
4417
4382
 
4418
4383
 
4419
4384
  def getpublicplayerscore(s, player_score):
@@ -4468,6 +4433,7 @@ def get_player_max_allotted_time(s, player_idx):
4468
4433
  return None
4469
4434
 
4470
4435
 
4436
+ @dispatch(State, AllottedTime)
4471
4437
  def get_deadline(s, max_allotted_time):
4472
4438
  if not max_allotted_time:
4473
4439
  return None
@@ -4478,7 +4444,7 @@ def get_deadline(s, max_allotted_time):
4478
4444
  "%Y-%m-%d %H:%M:%S"
4479
4445
  )
4480
4446
  else:
4481
- since_action = s.history[since_action_idx]
4447
+ since_action = s.kernel.history[since_action_idx]
4482
4448
  submitted_at = since_action.submitted_at
4483
4449
  allotted_since = datetime.strptime(submitted_at, "%Y-%m-%d %H:%M:%S")
4484
4450
  deadline = allotted_since + timedelta(seconds=max_allotted_time.seconds)
@@ -4500,7 +4466,7 @@ def get_deadlines(s):
4500
4466
 
4501
4467
 
4502
4468
  def get_public_player_scores(s):
4503
- return [getpublicplayerscore(s, player_score) for player_score in s.player_scores]
4469
+ return [getpublicplayerscore(s, player_score) for player_score in s.player_scores_3]
4504
4470
 
4505
4471
 
4506
4472
  # deadlines = field(type=list) # List[RemainingAllottedTime|None]
@@ -4532,8 +4498,9 @@ def get_public_player_scores(s):
4532
4498
  # goal_completions = field(type=list, initial=[]) # List[GoalCompletion]
4533
4499
 
4534
4500
 
4501
+ @dispatch(State)
4535
4502
  def get_public_history(s):
4536
- return [action.get_public(s) for action in s.history]
4503
+ return [action.get_public(s) for action in s.kernel.history]
4537
4504
 
4538
4505
 
4539
4506
  def imagine_history(public_state, private_state):
@@ -4553,19 +4520,23 @@ def imagine_decks(public_state, private_state):
4553
4520
 
4554
4521
 
4555
4522
  def imagine_state(public_state, private_state):
4523
+ game_config = public_state.game_config
4556
4524
  imagined_kernel = init_state_kernel(
4557
4525
  rng=random.Random(),
4558
- game_config=public_state.game_config,
4559
- player_idxs=public_state.player_idxs,
4560
- piles=public_state.piles,
4526
+ game_config=game_config,
4561
4527
  edges=public_state.edges,
4562
4528
  nodes=public_state.nodes,
4529
+ piles=public_state.piles,
4563
4530
  decks=imagine_decks(public_state, private_state),
4564
4531
  players=imagine_players(public_state, private_state),
4532
+ player_idxs=public_state.player_idxs,
4565
4533
  history=imagine_history(public_state, private_state),
4566
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,
4567
4538
  )
4568
- return init_state(imagined_kernel)
4539
+ return init_memoized_state(imagined_kernel)
4569
4540
 
4570
4541
 
4571
4542
  def isterminal(s):
@@ -5265,9 +5236,9 @@ def json2rng(json_str):
5265
5236
  @dispatch(State, int)
5266
5237
  def getprivatestate(s, player_idx):
5267
5238
  return PrivateState(
5268
- my_history=[a for a in s.history if a.legal_action.player_idx == player_idx],
5269
- player_score=getprivateplayerscore(s, s.player_scores[player_idx]),
5270
- player=s.players[player_idx],
5239
+ my_history=[a for a in s.kernel.history if a.legal_action.player_idx == player_idx],
5240
+ player_score=getprivateplayerscore(s, s.player_scores_3[player_idx]),
5241
+ player=s.kernel.players[player_idx],
5271
5242
  legal_actions_3 = get_legal_actions3(s, player_idx),
5272
5243
  goal_completions=get_goal_completions(s, player_idx),
5273
5244
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graph_games_proto
3
- Version: 0.3.2031
3
+ Version: 0.3.2036
4
4
  Requires-Dist: multipledispatch==1.0.0
5
5
  Requires-Dist: pyrsistent==0.20.0
6
6
  Requires-Dist: numpy==2.2.4
@@ -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=f3K8SmCxm0KTxHcsfOPI0o-JlRJv67COHyrIY1BC_FM,194428
3
+ graph_games_proto/fns.py,sha256=rWENIi9bL6YymSD7-1Z6VRl2E_nkvRR8cWDv7lQFaw0,193756
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.2031.dist-info/METADATA,sha256=d1I2BAoSsTLpv8cuwnU4tKlzPnvkLv5Fh0cce13XV4E,188
7
- graph_games_proto-0.3.2031.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
- graph_games_proto-0.3.2031.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
- graph_games_proto-0.3.2031.dist-info/RECORD,,
6
+ graph_games_proto-0.3.2036.dist-info/METADATA,sha256=YVBvzZp03PYPkKCWT2cQ3K81aTFN5U48ueJvHFuZ4jg,188
7
+ graph_games_proto-0.3.2036.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
+ graph_games_proto-0.3.2036.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
+ graph_games_proto-0.3.2036.dist-info/RECORD,,