graph-games-proto 0.3.1889__py3-none-any.whl → 0.3.1897__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
@@ -2484,11 +2484,6 @@ def getsettingvalue(s, setting_name):
2484
2484
  return getsettingvalue(s.game_config.fig, setting_name)
2485
2485
 
2486
2486
 
2487
- def calclegalactions3(state):
2488
- legal_actions = []
2489
- return legal_actions
2490
-
2491
-
2492
2487
  @dispatch(GameConfig)
2493
2488
  def getinitialstate(game_config):
2494
2489
  fig = game_config.fig
@@ -2617,7 +2612,19 @@ def getinitialstate(game_config):
2617
2612
  )
2618
2613
 
2619
2614
  state = run_state_hooks(state, INITIALIZATION_HOOKS, True)
2620
- state = state.set(legal_actions_3=calclegalactions3(state))
2615
+
2616
+ state_kernal = init_state_kernal(
2617
+ edges=state.edges,
2618
+ decks=state.decks,
2619
+ piles=state.piles,
2620
+ players=state.players,
2621
+ player_idxs=state.player_idxs,
2622
+ history=state.history,
2623
+ player_scores=state.player_scores,
2624
+ game_config=state.game_config,
2625
+ )
2626
+ state = state.set(legal_actions_3=calc_legal_actions3(state_kernal))
2627
+
2621
2628
  return state
2622
2629
 
2623
2630
 
@@ -4027,6 +4034,65 @@ def isactionlegal2(s, a):
4027
4034
  return run_accept_action_hooks(s, a, ACCEPT_ACTION_HOOKS, False)
4028
4035
 
4029
4036
 
4037
+ def calc_legal_actions3(state_kernal):
4038
+ history = state_kernal.history
4039
+
4040
+ if len(history) == 0:
4041
+ # Initial
4042
+ return [
4043
+ LegalAction(
4044
+ player_idx=player.idx,
4045
+ name="INITIAL-GOAL-KEEP",
4046
+ instruction="Your move. Please select the routes you want to keep.",
4047
+ allotted_seconds=INITIAL_ALLOTTED_SECONDS,
4048
+ allotted_since_action_idx=(len(history) - 1),
4049
+ keep=LegalActionKeep(
4050
+ deck_idx=1,
4051
+ min=2,
4052
+ )
4053
+ )
4054
+ for player in state_kernal.players
4055
+ ]
4056
+
4057
+ if False:
4058
+ pass
4059
+ elif True:
4060
+ last_action = history[-1]
4061
+ if last_action.legal_action.name == "INITIAL-GOAL-KEEP":
4062
+ return get_default_legal_actions(state_kernal, state_kernal.player_idxs[0])
4063
+ else:
4064
+ last_player_idx = last_action.legal_action.player_idx
4065
+ last_player_shuffled_idx = last_action.player_idxs.index(last_player_idx)
4066
+ next_player_shuffled_idx = (last_player_shuffled_idx + 1) % len(last_action.player_idxs)
4067
+ return get_default_legal_actions(state_kernal, state_kernal.player_idxs[next_player_shuffled_idx])
4068
+
4069
+ return []
4070
+
4071
+
4072
+ class StateKernal(PClass):
4073
+ edges = field(type=list) # List[BiEdge]
4074
+ decks = field(type=list) # List[Deck]
4075
+ piles = field(type=list) # List[Pile]
4076
+ players = field(type=list) # List[Player]
4077
+ player_idxs = field(type=list) # List[int]
4078
+ history = field(type=list) # List[PublicAction]
4079
+ player_scores = field(type=list) # List[PlayerScore]
4080
+ game_config = field(type=GameConfig)
4081
+
4082
+ def init_state_kernal(**kwargs):
4083
+ return StateKernal(
4084
+ edges=kwargs.get('edges'),
4085
+ decks=kwargs.get('decks'),
4086
+ piles=kwargs.get('piles'),
4087
+ players=kwargs.get('players'),
4088
+ player_idxs=kwargs.get('player_idxs'),
4089
+ history=kwargs.get('history'),
4090
+ player_scores=kwargs.get('player_scores'),
4091
+ game_config=kwargs.get('game_config'),
4092
+ )
4093
+
4094
+
4095
+
4030
4096
  def getnextstate2(s, a, log=False):
4031
4097
  is_legal, reason = isactionlegal2(s, a)
4032
4098
  if not is_legal:
@@ -4037,6 +4103,19 @@ def getnextstate2(s, a, log=False):
4037
4103
  s = run_state_hooks(s, HANDLE_TERMINAL_HOOKS, log)
4038
4104
  if not s.legal_actions_2:
4039
4105
  s = run_state_action_hooks(s, a, EMPTY_LEGAL_ACTIONS_HOOKS, log)
4106
+
4107
+ state_kernal = init_state_kernal(
4108
+ edges=s.edges,
4109
+ decks=s.decks,
4110
+ piles=s.piles,
4111
+ players=s.players,
4112
+ player_idxs=s.player_idxs,
4113
+ history=s.history,
4114
+ player_scores=s.player_scores,
4115
+ game_config=s.game_config,
4116
+ )
4117
+ s = s.set(legal_actions_3=calc_legal_actions3(state_kernal))
4118
+
4040
4119
  return s
4041
4120
 
4042
4121
 
@@ -4400,6 +4479,10 @@ def getfirstplayeridx(rng, num_players):
4400
4479
  return rng.randint(0, num_players-1)
4401
4480
 
4402
4481
 
4482
+ def get_legal_actions3(s, player_idx):
4483
+ return [a for a in s.legal_actions_3 if a.player_idx == player_idx]
4484
+
4485
+
4403
4486
  @dispatch(State, int)
4404
4487
  def get_legal_actions(s, player_idx):
4405
4488
  return [a for a in s.legal_actions_2 if a.player_idx == player_idx]
@@ -4894,6 +4977,7 @@ def getprivatestate(s, player_idx):
4894
4977
  player_score=getprivateplayerscore(s, s.player_scores[player_idx]),
4895
4978
  player=s.players[player_idx],
4896
4979
  legal_actions_2 = get_legal_actions(s, player_idx),
4980
+ legal_actions_3 = get_legal_actions3(s, player_idx),
4897
4981
  goal_completions=get_goal_completions(s, player_idx),
4898
4982
  )
4899
4983
 
@@ -5375,4 +5459,78 @@ HANDLE_TERMINAL_HOOKS = [
5375
5459
  when="HANDLE_TERMINAL",
5376
5460
  code=HANDLE_TERMINAL_HOOK_1,
5377
5461
  ),
5378
- ]
5462
+ ]
5463
+
5464
+ def get_default_legal_actions(state_kernal, player_idx):
5465
+ allotted_seconds = DEFAULT_ALLOTTED_SECONDS
5466
+ allotted_since_action_idx = len(state_kernal.history) - 1
5467
+ legal_actions = []
5468
+
5469
+ if len(state_kernal.decks[1].facedown_stack) >= 1:
5470
+ legal_actions.append(
5471
+ LegalAction(
5472
+ player_idx=player_idx,
5473
+ name="DRAW-GOAL",
5474
+ instruction="draw a route",
5475
+ allotted_seconds=allotted_seconds,
5476
+ allotted_since_action_idx=allotted_since_action_idx,
5477
+ draw_discard=LegalActionDrawDiscard(
5478
+ deck_idx=1,
5479
+ quantity=3,
5480
+ min=1,
5481
+ )
5482
+ )
5483
+ )
5484
+
5485
+ if len(state_kernal.decks[0].facedown_stack) >= 1:
5486
+ legal_actions.append(
5487
+ LegalAction(
5488
+ auto_preferred=True,
5489
+ player_idx=player_idx,
5490
+ name="DRAW",
5491
+ instruction="draw a unit",
5492
+ allotted_seconds=allotted_seconds,
5493
+ allotted_since_action_idx=allotted_since_action_idx,
5494
+ draw=LegalActionDraw(
5495
+ deck_idx=0,
5496
+ quantity=1,
5497
+ )
5498
+ )
5499
+ )
5500
+
5501
+ if len(state_kernal.decks[0].facedown_stack) >= 2:
5502
+ state_kernal = append_to_legal_actions(
5503
+ state_kernal,
5504
+ LegalAction(
5505
+ player_idx=player_idx,
5506
+ name="DRAW-DOUBLE",
5507
+ instruction="draw 2 units",
5508
+ allotted_seconds=allotted_seconds,
5509
+ allotted_since_action_idx=allotted_since_action_idx,
5510
+ draw=LegalActionDraw(
5511
+ deck_idx=0,
5512
+ quantity=2,
5513
+ )
5514
+ )
5515
+ )
5516
+
5517
+ for card_uuid in state_kernal.decks[0].faceup_spots:
5518
+ if card_uuid:
5519
+ legal_actions.append(
5520
+ LegalAction(
5521
+ player_idx=player_idx,
5522
+ name="FACEUP-DRAW",
5523
+ instruction="draw a faceup unit",
5524
+ allotted_seconds=allotted_seconds,
5525
+ allotted_since_action_idx=allotted_since_action_idx,
5526
+ faceup_draw=LegalActionFaceupDraw(
5527
+ deck_idx=0,
5528
+ card_uuid=card_uuid,
5529
+ )
5530
+ )
5531
+ )
5532
+
5533
+ for legal_action in get_legal_actions_for_paths(state_kernal, player_idx):
5534
+ legal_actions.append(legal_action)
5535
+
5536
+ return legal_actions
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graph_games_proto
3
- Version: 0.3.1889
3
+ Version: 0.3.1897
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=w4Hkn6z0bUuZeInMvSbbNpFjzAlp1UgZsamFBsuN2to,181960
3
+ graph_games_proto/fns.py,sha256=Aqcoiw2rungLAiTgtj4Su_BpliNWO__s70knUaWkcIE,187324
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.1889.dist-info/METADATA,sha256=F9asK6sb4QsoRU5ecRsQpSd-2kjESiDI9EfSosyE1uQ,188
7
- graph_games_proto-0.3.1889.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
- graph_games_proto-0.3.1889.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
- graph_games_proto-0.3.1889.dist-info/RECORD,,
6
+ graph_games_proto-0.3.1897.dist-info/METADATA,sha256=wPb_gd1bIy9puPul8HzXMOixr0wqyY0XIF_dV2dfePE,188
7
+ graph_games_proto-0.3.1897.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
+ graph_games_proto-0.3.1897.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
+ graph_games_proto-0.3.1897.dist-info/RECORD,,