graph-games-proto 0.3.1890__py3-none-any.whl → 0.3.1898__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
 
@@ -5380,4 +5459,77 @@ HANDLE_TERMINAL_HOOKS = [
5380
5459
  when="HANDLE_TERMINAL",
5381
5460
  code=HANDLE_TERMINAL_HOOK_1,
5382
5461
  ),
5383
- ]
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
+ legal_actions.append(
5503
+ LegalAction(
5504
+ player_idx=player_idx,
5505
+ name="DRAW-DOUBLE",
5506
+ instruction="draw 2 units",
5507
+ allotted_seconds=allotted_seconds,
5508
+ allotted_since_action_idx=allotted_since_action_idx,
5509
+ draw=LegalActionDraw(
5510
+ deck_idx=0,
5511
+ quantity=2,
5512
+ )
5513
+ )
5514
+ )
5515
+
5516
+ for card_uuid in state_kernal.decks[0].faceup_spots:
5517
+ if card_uuid:
5518
+ legal_actions.append(
5519
+ LegalAction(
5520
+ player_idx=player_idx,
5521
+ name="FACEUP-DRAW",
5522
+ instruction="draw a faceup unit",
5523
+ allotted_seconds=allotted_seconds,
5524
+ allotted_since_action_idx=allotted_since_action_idx,
5525
+ faceup_draw=LegalActionFaceupDraw(
5526
+ deck_idx=0,
5527
+ card_uuid=card_uuid,
5528
+ )
5529
+ )
5530
+ )
5531
+
5532
+ for legal_action in get_legal_actions_for_paths(state_kernal, player_idx):
5533
+ legal_actions.append(legal_action)
5534
+
5535
+ return legal_actions
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graph_games_proto
3
- Version: 0.3.1890
3
+ Version: 0.3.1898
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=Ps1cEaMbaSBXIJKr0xsc8wyu4CJdaTrdKWtVJ8cH10s,182134
3
+ graph_games_proto/fns.py,sha256=DJTM-VwAx-5vcXtBLGgdczV80jCGkP3_Jake_GMMw0U,187280
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.1890.dist-info/METADATA,sha256=XXk7ZSs21Gx4oN-AWXTiYNZZiDL6aTg8dWlt6RlWsuk,188
7
- graph_games_proto-0.3.1890.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
- graph_games_proto-0.3.1890.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
- graph_games_proto-0.3.1890.dist-info/RECORD,,
6
+ graph_games_proto-0.3.1898.dist-info/METADATA,sha256=j3adFTTmlHyIBV75pT5bO9GEEEN3LPvNQhgVIfPf57I,188
7
+ graph_games_proto-0.3.1898.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
+ graph_games_proto-0.3.1898.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
+ graph_games_proto-0.3.1898.dist-info/RECORD,,