graph-games-proto 0.3.2227__py3-none-any.whl → 0.3.2274__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.
@@ -1,3 +1,3 @@
1
1
  # __init__.py
2
2
  from .main import hello
3
- from .fns import getpublicgameconfig, alpha0, isterminal, getfinalscores, get_deadlines, get_longest_path_length, get_max_allotted_times, get_legal_actions_for_path, find_player_with_longest_path, calc_player_graph, get_edges, FrozenDek, QValueLearningPolicy, Action2, getnextstate2, isactionlegal2, LegalAction, Fig, RandoPolicy, StaticBoardConfig, autoplay, getpublicstate, generate_cards, PublicState, State, Fig, getprivatescore, get_qvalue_trajectories, PlayerState, initfig, initboardconfig, gettoplay, printstate, getinitialstate, Card, PrivateState, getprivatestate, printaction, json_serializer, getrng, FrozenBoardConfig, initgameconfig, GameConfig
3
+ from .fns import getqproxy0, get_intuited_best_actions, getpublicgameconfig, alpha0, isterminal, getfinalscores, get_deadlines, get_longest_path_length, get_max_allotted_times, get_legal_actions_for_path, find_player_with_longest_path, calc_player_graph, get_edges, FrozenDek, QValueLearningPolicy, Action2, getnextstate2, isactionlegal2, LegalAction, Fig, RandoPolicy, StaticBoardConfig, autoplay, getpublicstate, generate_cards, PublicState, State, Fig, getprivatescore, get_qvalue_trajectories, PlayerState, initfig, initboardconfig, gettoplay, printstate, getinitialstate, Card, PrivateState, getprivatestate, printaction, json_serializer, getrng, FrozenBoardConfig, initgameconfig, GameConfig
graph_games_proto/fns.py CHANGED
@@ -477,15 +477,14 @@ class FrozenLinkPath(PClass):
477
477
  )
478
478
 
479
479
 
480
- @dataclass(frozen=True)
481
- class FrozenPath:
482
- num: int
483
- link_num: int
484
- start_point_uuid: str
485
- end_point_uuid: str
486
- start_point_num: int
487
- end_point_num: int
488
- path: FrozenLinkPath
480
+ class FrozenPath(PClass):
481
+ num = field(type=int)
482
+ link_num = field(type=int)
483
+ start_point_uuid = field(type=str)
484
+ end_point_uuid = field(type=str)
485
+ start_point_num = field(type=int)
486
+ end_point_num = field(type=int)
487
+ path = field(type=FrozenLinkPath)
489
488
  def __todict__(self):
490
489
  return {
491
490
  "num": self.num,
@@ -549,17 +548,6 @@ class FrozenDeckUnit2(PClass):
549
548
  )
550
549
 
551
550
 
552
- @dataclass(frozen=True)
553
- class FrozenBoardConfigDataclass:
554
- deck_units: List[FrozenDeckUnit2]
555
- len_scores: List[FrozenLenScore]
556
- links: List[FrozenLink2]
557
- clusters: List[FrozenCluster]
558
- points: List[FrozenPoint2]
559
- board_paths: List[FrozenPath]
560
- settings: List[FrozenSetting]
561
-
562
-
563
551
  class FrozenRoute(PClass):
564
552
  num = field(type=int)
565
553
  uuid = field(type=str)
@@ -1019,11 +1007,6 @@ def getpublicgameconfig(game_config):
1019
1007
  )
1020
1008
 
1021
1009
 
1022
- class ActionDrawUnit:
1023
- def __init__(self):
1024
- pass
1025
-
1026
-
1027
1010
  class PublicPlayer(PClass):
1028
1011
  idx = field(type=int)
1029
1012
  pieces = field(type=list) # List[Piece]
@@ -1053,7 +1036,7 @@ class Player(PClass):
1053
1036
  idx = field(type=int)
1054
1037
  pieces = field(type=list) # List[Piece]
1055
1038
  cards = field(type=list) # List[Card]
1056
- discard_tray = field(type=list) # List[Card]
1039
+ discard_tray = field(type=PVector) # PVector[Card]
1057
1040
  def __todict__(self):
1058
1041
  return {
1059
1042
  "idx": self.idx,
@@ -2322,7 +2305,7 @@ def init_state_kernel(game_config, **kwargs):
2322
2305
  starting_decks.append(deck_obj)
2323
2306
 
2324
2307
  default_players = [
2325
- Player(idx=idx, pieces=[], cards=[], discard_tray=[]) for idx in range(game_config.num_players)
2308
+ Player(idx=idx, pieces=[], cards=[], discard_tray=v()) for idx in range(game_config.num_players)
2326
2309
  ]
2327
2310
 
2328
2311
  return StateKernel(
@@ -2419,9 +2402,8 @@ class QValueLearningPolicy(PClass):
2419
2402
  epsilon = field(type=float, initial=0.1) # Epsilon for exploration
2420
2403
 
2421
2404
 
2422
- class RandoPolicy:
2423
- def __init__(self):
2424
- pass
2405
+ class RandoPolicy(PClass):
2406
+ pass
2425
2407
 
2426
2408
 
2427
2409
  # Functions
@@ -3853,7 +3835,7 @@ def handle_keep_action(kernel, action):
3853
3835
  # Clear the discard tray and add the kept cards back
3854
3836
  player.cards.extend([c for c in kept_cards if c is not None])
3855
3837
 
3856
- player.discard_tray.clear()
3838
+ player.set(discard_tray=v())
3857
3839
  return kernel.set(decks=kernel.decks, players=kernel.players)
3858
3840
 
3859
3841
 
@@ -3900,7 +3882,7 @@ def handle_discard_action(kernel, action):
3900
3882
  # Clear the discard tray and add the kept cards back
3901
3883
  player.cards.extend([c for c in kept_cards if c is not None])
3902
3884
 
3903
- player.discard_tray.clear()
3885
+ player.set(discard_tray=v())
3904
3886
  print("****************************** handle_discard_action 10 kept_cards: ", kept_cards)
3905
3887
 
3906
3888
  return kernel.set(decks=kernel.decks, players=kernel.players)
@@ -4595,6 +4577,11 @@ def get_next_player_shuffled_idx(state_kernel, last_action):
4595
4577
  def getnextstate2(s, a, log=False):
4596
4578
  is_legal, reason = isactionlegal2(s, a)
4597
4579
  if not is_legal:
4580
+ print("****************************** Action is not legal: ", json.dumps(a.__todict__(), indent=2))
4581
+ # print("a")
4582
+ # print("json.dumps(s.legal_actions_3): ", json.dumps([la.__todict__() for la in s.legal_actions_3], indent=2))
4583
+ # print("b")
4584
+ # print("\n\n")
4598
4585
  raise ValueError(f"Action is not legal: {a}. Reason: {reason}")
4599
4586
  kernel = s.kernel
4600
4587
  kernel = run_state_action_hooks(kernel, a, AFTER_ACCEPT_ACTION_HOOKS, log)
@@ -4734,7 +4721,7 @@ def get_candidate_decks(ps: PlayerState) -> List[CandidateDeck]:
4734
4721
  spots_to_remove = [card_uuid for card_uuid in public_deck.faceup_spread.spots if card_uuid]
4735
4722
  for card_uuid in spots_to_remove:
4736
4723
  if card_uuid:
4737
- print("************************************ spots_to_remove: ", spots_to_remove)
4724
+ # print("************************************ spots_to_remove: ", spots_to_remove)
4738
4725
  candidates.remove(card_uuid)
4739
4726
 
4740
4727
  note_lists[deck_idx].append(f"Removed {len(spots_to_remove)} candidates from deck {public_deck.idx} for faceup spots")
@@ -4746,6 +4733,7 @@ def get_candidate_decks(ps: PlayerState) -> List[CandidateDeck]:
4746
4733
  note_lists[deck_idx].append(f"Removed {len(public_deck.discard_faceup_stack.cards)} candidates from deck {public_deck.idx} for faceup discard")
4747
4734
 
4748
4735
 
4736
+ # print("ps.private.player.cards: ", len(ps.private.player.cards))
4749
4737
  for card_uuid in ps.private.player.cards:
4750
4738
  card = ps.game_config.fig.carduuid2card[card_uuid]
4751
4739
  candidate_lists[card.deck_idx].remove(card_uuid)
@@ -4762,25 +4750,25 @@ def get_candidate_decks(ps: PlayerState) -> List[CandidateDeck]:
4762
4750
 
4763
4751
 
4764
4752
  def imagine_player(p_idx: int, ps: PlayerState, candidate_decks: List[CandidateDeck]) -> Player:
4765
- print(f"imagine_player {p_idx}")
4753
+ # print(f"imagine_player {p_idx}")
4766
4754
  if ps.private.player.idx == p_idx:
4767
- print(f"No need to imagine player {p_idx}, returning private player")
4755
+ # print(f"No need to imagine player {p_idx}, returning private player")
4768
4756
  return ps.private.player
4769
- print(f"len(candidate_decks[0].candidates): ", len(candidate_decks[0].candidates))
4770
- print(f"public_player.deck_counts: ", ps.public.players[p_idx].deck_counts)
4757
+ # print(f"len(candidate_decks[0].candidates): ", len(candidate_decks[0].candidates))
4758
+ # print(f"public_player.deck_counts: ", ps.public.players[p_idx].deck_counts)
4771
4759
  public_player = ps.public.players[p_idx]
4772
- print(f"z1")
4760
+ # print(f"z1")
4773
4761
  cards = []
4774
- print(f"z2")
4762
+ # print(f"z2")
4775
4763
  for deck_idx, count in enumerate(public_player.deck_counts):
4776
- print(f"deck_idx: {deck_idx}, count: {count}")
4764
+ # print(f"deck_idx: {deck_idx}, count: {count}")
4777
4765
  candidate_deck = candidate_decks[deck_idx]
4778
- print(f"len(candidate_deck.candidates) before: {len(candidate_deck.candidates)}")
4766
+ # print(f"len(candidate_deck.candidates) before: {len(candidate_deck.candidates)}")
4779
4767
  for _ in range(count):
4780
4768
  cards.append(candidate_deck.candidates.pop())
4781
- print(f"len(candidate_deck.candidates) after: {len(candidate_deck.candidates)}")
4769
+ # print(f"len(candidate_deck.candidates) after: {len(candidate_deck.candidates)}")
4782
4770
  discard_tray = []
4783
- print(f"z4")
4771
+ # print(f"z4")
4784
4772
  for deck_idx, count in enumerate(public_player.discard_deck_counts):
4785
4773
  candidate_deck = candidate_decks[deck_idx]
4786
4774
  for _ in range(count):
@@ -4815,7 +4803,7 @@ def imagine_deck(public_deck: PublicDeck, candidate_deck: CandidateDeck) -> Deck
4815
4803
  facedown_stack_cards = [
4816
4804
  candidate_deck.candidates.pop() for _ in range(public_deck.facedown_stack.num_cards)
4817
4805
  ]
4818
- print(f"len(facedown_stack_cards) pops for deck_idx [{public_deck.idx}]: ", len(facedown_stack_cards))
4806
+ # print(f"len(facedown_stack_cards) pops for deck_idx [{public_deck.idx}]: ", len(facedown_stack_cards))
4819
4807
 
4820
4808
  imagined = Deck(
4821
4809
  idx=public_deck.idx,
@@ -4871,25 +4859,25 @@ def imagine_state(ps: PlayerState) -> State:
4871
4859
 
4872
4860
  candidate_decks = get_candidate_decks(ps)
4873
4861
 
4874
- print_public_deck_stats(ps.public.decks[0])
4862
+ # print_public_deck_stats(ps.public.decks[0])
4875
4863
 
4876
- print("\n")
4877
- print("************************************ candidate_decks[1].notes a: ", candidate_decks[1].notes)
4878
- print("************************************ len(candidate_decks[1].candidates) a: ", len(candidate_decks[1].candidates))
4879
- print("\n")
4864
+ # print("\n")
4865
+ # print("************************************ candidate_decks[1].notes a: ", "\n".join(candidate_decks[1].notes))
4866
+ # print("************************************ len(candidate_decks[1].candidates) a: ", len(candidate_decks[1].candidates))
4867
+ # print("\n")
4880
4868
 
4881
4869
  imagined_decks = imagine_decks(ps, candidate_decks)
4882
4870
 
4883
- print("\n")
4884
- print("************************************ len(candidate_decks[1].candidates) b: ", len(candidate_decks[1].candidates))
4885
- print("player deck[1] counts: ", [public_player.deck_counts[1] for public_player in ps.public.players])
4886
- print("\n")
4871
+ # print("\n")
4872
+ # print("************************************ len(candidate_decks[1].candidates) b: ", len(candidate_decks[1].candidates))
4873
+ # print("player deck[1] counts: ", [public_player.deck_counts[1] for public_player in ps.public.players])
4874
+ # print("\n")
4887
4875
 
4888
4876
  imagined_players = imagine_players(ps, candidate_decks)
4889
4877
 
4890
- print("\n")
4891
- print("************************************ len(candidate_decks[1].candidates) c: ", len(candidate_decks[1].candidates))
4892
- print("\n")
4878
+ # print("\n")
4879
+ # print("************************************ len(candidate_decks[1].candidates) c: ", len(candidate_decks[1].candidates))
4880
+ # print("\n")
4893
4881
 
4894
4882
  imagined_kernel = init_state_kernel(
4895
4883
  GameConfig(
@@ -4991,7 +4979,7 @@ def getpublicdeck(s, d):
4991
4979
  return PublicDeck(
4992
4980
  idx=d.idx,
4993
4981
  uuid=d.uuid,
4994
- all_cards=d.all_cards,
4982
+ all_cards=copy.deepcopy(d.all_cards),
4995
4983
  faceup_stack = copy.deepcopy(d.faceup_stack) if d.faceup_stack else None,
4996
4984
  faceup_spread = copy.deepcopy(d.faceup_spread) if d.faceup_spread else None,
4997
4985
  facedown_stack = PublicFacedownCardStack(num_cards=len(d.facedown_stack.cards)) if d.facedown_stack else None,
@@ -5778,7 +5766,7 @@ def get_intuited_best_actions(ps: PlayerState):
5778
5766
  ]
5779
5767
  if not possible_actions:
5780
5768
  return None
5781
- return possible_actions[:8]
5769
+ return possible_actions[:16]
5782
5770
 
5783
5771
 
5784
5772
  def get_spread(q_values, p_idx):
@@ -5806,9 +5794,8 @@ def dynamics(s, a):
5806
5794
  return next_s, rewards
5807
5795
 
5808
5796
 
5809
- def alpha0(ps: PlayerState):
5797
+ def alpha0(ps: PlayerState, td=3):
5810
5798
  # print("************************************ ps.public.decks[0].facedown_stack 8: ", ps.public.decks[0].facedown_stack)
5811
- td = 3
5812
5799
  legal_actions = ps.private.legal_actions_3
5813
5800
  if not legal_actions:
5814
5801
  return None
@@ -5826,7 +5813,7 @@ def get_max_spread_idx(q_proxies, p_idx):
5826
5813
 
5827
5814
  @dispatch(PlayerState, Action2, int)
5828
5815
  def getqproxy0(ps: PlayerState, a: LegalAction, td: int):
5829
- print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ getqproxy0 td: ", td)
5816
+ # print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ getqproxy0 td: ", td)
5830
5817
 
5831
5818
  def qproxybase():
5832
5819
  next_s, rewards = imagine_dynamics(ps, a)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graph_games_proto
3
- Version: 0.3.2227
3
+ Version: 0.3.2274
4
4
  Requires-Dist: multipledispatch==1.0.0
5
5
  Requires-Dist: pyrsistent==0.20.0
6
6
  Requires-Dist: numpy==2.2.4
@@ -0,0 +1,9 @@
1
+ graph_games_proto/__init__.py,sha256=3XawPcYk9Zk-Hj4M8eNBdGzBccKG8dWj8ZZGRkWnmA4,735
2
+ graph_games_proto/all_types.py,sha256=IpbwftEcHS5Ewz-saFNk0lO9FvcbuHG36odRTayCXUk,54911
3
+ graph_games_proto/fns.py,sha256=YsvqISYFmrU1AVc6geWcxxNwB74-Hqd-LPhnh-oej-8,211037
4
+ graph_games_proto/main.py,sha256=fj2U7KcwrpZtuUhjOX5yVxY18LZvvsxDFYZ_S5mxe04,145
5
+ graph_games_proto/state.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ graph_games_proto-0.3.2274.dist-info/METADATA,sha256=UTUbt6Q5D-LRqREehgGanaXHHqbxVFppCkZhqASLFdw,188
7
+ graph_games_proto-0.3.2274.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
+ graph_games_proto-0.3.2274.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
+ graph_games_proto-0.3.2274.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- graph_games_proto/__init__.py,sha256=BcRdYe0yElSo3vQ5eqhecM1QP-NXaV-mQtcBH6KUnN0,696
2
- graph_games_proto/all_types.py,sha256=IpbwftEcHS5Ewz-saFNk0lO9FvcbuHG36odRTayCXUk,54911
3
- graph_games_proto/fns.py,sha256=sAin1JGFkmd7aJbqCjbATF51RB-su06oetZiCu5z3yk,210890
4
- graph_games_proto/main.py,sha256=fj2U7KcwrpZtuUhjOX5yVxY18LZvvsxDFYZ_S5mxe04,145
5
- graph_games_proto/state.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- graph_games_proto-0.3.2227.dist-info/METADATA,sha256=d7lJ50z2MBW-PSXyFfkmiFtHee71Lra24iZuBOFnE9I,188
7
- graph_games_proto-0.3.2227.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
- graph_games_proto-0.3.2227.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
- graph_games_proto-0.3.2227.dist-info/RECORD,,