graph-games-proto 0.3.2112__py3-none-any.whl → 0.3.2113__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 +121 -59
- {graph_games_proto-0.3.2112.dist-info → graph_games_proto-0.3.2113.dist-info}/METADATA +1 -1
- {graph_games_proto-0.3.2112.dist-info → graph_games_proto-0.3.2113.dist-info}/RECORD +5 -5
- {graph_games_proto-0.3.2112.dist-info → graph_games_proto-0.3.2113.dist-info}/WHEEL +0 -0
- {graph_games_proto-0.3.2112.dist-info → graph_games_proto-0.3.2113.dist-info}/top_level.txt +0 -0
graph_games_proto/fns.py
CHANGED
@@ -14,6 +14,7 @@ import numpy as np
|
|
14
14
|
from functools import cmp_to_key
|
15
15
|
from itertools import combinations as itertools_combinations, chain
|
16
16
|
from collections import deque
|
17
|
+
import copy
|
17
18
|
|
18
19
|
DEFAULT_ALLOTTED_SECONDS = 12
|
19
20
|
INITIAL_ALLOTTED_SECONDS = 22
|
@@ -1025,12 +1026,14 @@ class PublicPlayer(PClass):
|
|
1025
1026
|
idx = field(type=int)
|
1026
1027
|
pieces = field(type=list) # List[Piece]
|
1027
1028
|
deck_counts = field(type=list)
|
1029
|
+
discard_deck_counts = field(type=list)
|
1028
1030
|
piece_template_counts = field(type=list)
|
1029
1031
|
def __todict__(self):
|
1030
1032
|
return {
|
1031
1033
|
"idx": self.idx,
|
1032
1034
|
"pieces": self.pieces,
|
1033
1035
|
"deck_counts": list(self.deck_counts),
|
1036
|
+
"discard_deck_counts": list(self.discard_deck_counts),
|
1034
1037
|
"piece_template_counts": list(self.piece_template_counts),
|
1035
1038
|
}
|
1036
1039
|
@staticmethod
|
@@ -1039,6 +1042,7 @@ class PublicPlayer(PClass):
|
|
1039
1042
|
idx=d["idx"],
|
1040
1043
|
pieces=d["pieces"],
|
1041
1044
|
deck_counts=list(d["deck_counts"]),
|
1045
|
+
discard_deck_counts=list(d["discard_deck_counts"]),
|
1042
1046
|
piece_template_counts=list(d["piece_template_counts"]),
|
1043
1047
|
)
|
1044
1048
|
|
@@ -1065,16 +1069,6 @@ class Player(PClass):
|
|
1065
1069
|
)
|
1066
1070
|
|
1067
1071
|
|
1068
|
-
@dispatch(PublicPlayer)
|
1069
|
-
def imagine_player(public_player) -> Player:
|
1070
|
-
return Player(
|
1071
|
-
idx=public_player.idx,
|
1072
|
-
pieces=public_player.pieces,
|
1073
|
-
cards=[],
|
1074
|
-
discard_tray=[],
|
1075
|
-
)
|
1076
|
-
|
1077
|
-
|
1078
1072
|
class GoalCompletion(PClass):
|
1079
1073
|
goal_uuid = field(type=str)
|
1080
1074
|
complete = field(type=bool, initial=False)
|
@@ -1190,19 +1184,6 @@ class PublicDeck(PClass):
|
|
1190
1184
|
discard_len=d["discard_len"],
|
1191
1185
|
faceup_spots=d["faceup_spots"],
|
1192
1186
|
)
|
1193
|
-
|
1194
|
-
|
1195
|
-
class ActionKeepOptional(PClass):
|
1196
|
-
card_uuids = field(type=list) # List[int]
|
1197
|
-
def __todict__(self):
|
1198
|
-
return {
|
1199
|
-
"card_uuids": self.card_uuids,
|
1200
|
-
}
|
1201
|
-
@staticmethod
|
1202
|
-
def __fromdict__(d):
|
1203
|
-
return ActionKeepOptional(
|
1204
|
-
card_uuids=d["card_uuids"]
|
1205
|
-
)
|
1206
1187
|
|
1207
1188
|
|
1208
1189
|
class LegalActionKeep(PClass):
|
@@ -1572,19 +1553,19 @@ class PublicActionDiscard(PClass):
|
|
1572
1553
|
|
1573
1554
|
|
1574
1555
|
class ActionDiscard(PClass):
|
1575
|
-
|
1556
|
+
discard_tray_idxs = field(type=list) # List[int]
|
1576
1557
|
def get_public(self, state):
|
1577
1558
|
return PublicActionDiscard(
|
1578
|
-
deck_idxs=[
|
1559
|
+
deck_idxs=[0 for card_idx in self.discard_tray_idxs] # TODO: fix this
|
1579
1560
|
)
|
1580
1561
|
def __todict__(self):
|
1581
1562
|
return {
|
1582
|
-
"
|
1563
|
+
"discard_tray_idxs": self.discard_tray_idxs,
|
1583
1564
|
}
|
1584
1565
|
@staticmethod
|
1585
1566
|
def __fromdict__(d):
|
1586
1567
|
return ActionDiscard(
|
1587
|
-
|
1568
|
+
discard_tray_idxs=d["discard_tray_idxs"]
|
1588
1569
|
)
|
1589
1570
|
|
1590
1571
|
|
@@ -1602,19 +1583,19 @@ class PublicActionKeep(PClass):
|
|
1602
1583
|
|
1603
1584
|
|
1604
1585
|
class ActionKeep(PClass):
|
1605
|
-
|
1586
|
+
discard_tray_idxs = field(type=list) # List[int]
|
1606
1587
|
def get_public(self, state):
|
1607
1588
|
return PublicActionKeep(
|
1608
|
-
deck_idxs=[
|
1589
|
+
deck_idxs=[0 for card_idx in self.discard_tray_idxs] # TODO: fix this
|
1609
1590
|
)
|
1610
1591
|
def __todict__(self):
|
1611
1592
|
return {
|
1612
|
-
"
|
1593
|
+
"discard_tray_idxs": self.discard_tray_idxs,
|
1613
1594
|
}
|
1614
1595
|
@staticmethod
|
1615
1596
|
def __fromdict__(d):
|
1616
1597
|
return ActionKeep(
|
1617
|
-
|
1598
|
+
discard_tray_idxs=d["discard_tray_idxs"]
|
1618
1599
|
)
|
1619
1600
|
|
1620
1601
|
|
@@ -1725,9 +1706,7 @@ class Deck(PClass):
|
|
1725
1706
|
facedown_stack = field(type=(CardStack, type(None)), initial=None)
|
1726
1707
|
facedown_spread = field(type=(CardSpread, type(None)), initial=None)
|
1727
1708
|
discard_faceup_stack = field(type=(CardStack, type(None)), initial=None)
|
1728
|
-
discard_faceup_spread = field(type=(CardSpread, type(None)), initial=None)
|
1729
1709
|
discard_facedown_stack = field(type=(CardStack, type(None)), initial=None)
|
1730
|
-
discard_facedown_spread = field(type=(CardSpread, type(None)), initial=None)
|
1731
1710
|
def __todict__(self):
|
1732
1711
|
return {
|
1733
1712
|
"idx": self.idx,
|
@@ -1737,9 +1716,7 @@ class Deck(PClass):
|
|
1737
1716
|
"facedown_stack": self.facedown_stack.__todict__() if self.facedown_stack else None,
|
1738
1717
|
"facedown_spread": self.facedown_spread.__todict__() if self.facedown_spread else None,
|
1739
1718
|
"discard_faceup_stack": self.discard_faceup_stack.__todict__() if self.discard_faceup_stack else None,
|
1740
|
-
"discard_faceup_spread": self.discard_faceup_spread.__todict__() if self.discard_faceup_spread else None,
|
1741
1719
|
"discard_facedown_stack": self.discard_facedown_stack.__todict__() if self.discard_facedown_stack else None,
|
1742
|
-
"discard_facedown_spread": self.discard_facedown_spread.__todict__() if self.discard_facedown_spread else None,
|
1743
1720
|
}
|
1744
1721
|
@staticmethod
|
1745
1722
|
def __fromdict__(d):
|
@@ -1751,9 +1728,7 @@ class Deck(PClass):
|
|
1751
1728
|
facedown_stack=CardStack.__fromdict__(d["facedown_stack"]) if d.get("facedown_stack") else None,
|
1752
1729
|
facedown_spread=CardSpread.__fromdict__(d["facedown_spread"]) if d.get("facedown_spread") else None,
|
1753
1730
|
discard_faceup_stack=CardStack.__fromdict__(d["discard_faceup_stack"]) if d.get("discard_faceup_stack") else None,
|
1754
|
-
discard_faceup_spread=CardSpread.__fromdict__(d["discard_faceup_spread"]) if d.get("discard_faceup_spread") else None,
|
1755
1731
|
discard_facedown_stack=CardStack.__fromdict__(d["discard_facedown_stack"]) if d.get("discard_facedown_stack") else None,
|
1756
|
-
discard_facedown_spread=CardSpread.__fromdict__(d["discard_facedown_spread"]) if d.get("discard_facedown_spread") else None,
|
1757
1732
|
)
|
1758
1733
|
|
1759
1734
|
|
@@ -3797,11 +3772,15 @@ def handle_keep_action(kernel, action):
|
|
3797
3772
|
player = kernel.players[action.legal_action.player_idx]
|
3798
3773
|
if not player:
|
3799
3774
|
return kernel
|
3800
|
-
|
3801
|
-
|
3802
|
-
|
3803
|
-
|
3804
|
-
|
3775
|
+
|
3776
|
+
kept_cards = []
|
3777
|
+
non_kept_cards = []
|
3778
|
+
discard_tray_idxs = action.keep.discard_tray_idxs
|
3779
|
+
for i, card_uuid in enumerate(player.discard_tray):
|
3780
|
+
if i in discard_tray_idxs:
|
3781
|
+
kept_cards.append(card_uuid)
|
3782
|
+
else:
|
3783
|
+
non_kept_cards.append(card_uuid)
|
3805
3784
|
|
3806
3785
|
# Discard the non-kept cards to the deck's discard pile
|
3807
3786
|
deck.discard_faceup_stack.cards.extend(non_kept_cards)
|
@@ -3838,9 +3817,14 @@ def handle_discard_action(kernel, action):
|
|
3838
3817
|
if not player:
|
3839
3818
|
return kernel
|
3840
3819
|
|
3841
|
-
|
3842
|
-
|
3843
|
-
|
3820
|
+
non_kept_cards = []
|
3821
|
+
kept_cards = []
|
3822
|
+
discard_tray_idxs = action.discard.discard_tray_idxs
|
3823
|
+
for i, card_uuid in enumerate(player.discard_tray):
|
3824
|
+
if i in discard_tray_idxs:
|
3825
|
+
non_kept_cards.append(card_uuid)
|
3826
|
+
else:
|
3827
|
+
kept_cards.append(card_uuid)
|
3844
3828
|
|
3845
3829
|
print("****************************** handle_discard_action 5", kept_cards)
|
3846
3830
|
print("****************************** handle_discard_action 6", non_kept_cards)
|
@@ -4670,24 +4654,97 @@ def get_public_player_scores(s):
|
|
4670
4654
|
# goal_completions = field(type=list, initial=[]) # List[GoalCompletion]
|
4671
4655
|
|
4672
4656
|
|
4673
|
-
|
4674
|
-
def get_public_history(s):
|
4657
|
+
def get_public_history(s: State):
|
4675
4658
|
return [action.get_public(s) for action in s.kernel.history]
|
4676
4659
|
|
4677
4660
|
|
4678
|
-
|
4679
|
-
def imagine_history(ps) -> list[Action2]:
|
4661
|
+
def get_candidate_decks(ps: PlayerState) -> List[CandidateDeck]:
|
4680
4662
|
pass
|
4681
4663
|
|
4682
4664
|
|
4683
|
-
|
4684
|
-
|
4685
|
-
|
4665
|
+
def imagine_player(p_idx: int, ps: PlayerState, candidate_decks: List[CandidateDeck]) -> Player:
|
4666
|
+
if ps.private.player.idx ===p_idx:
|
4667
|
+
return ps.private.player
|
4668
|
+
public_player = ps.public.players[p_idx]
|
4669
|
+
cards = []
|
4670
|
+
for deck_idx, count in enumerate(public_player.deck_counts):
|
4671
|
+
candidate_deck = candidate_decks[deck_idx]
|
4672
|
+
for _ in range(count):
|
4673
|
+
cards.append(candidate_deck.candidates.pop())
|
4674
|
+
discard_tray = []
|
4675
|
+
for deck_idx, count in enumerate(public_player.discard_deck_counts):
|
4676
|
+
candidate_deck = candidate_decks[deck_idx]
|
4677
|
+
for _ in range(count):
|
4678
|
+
discard_tray.append(candidate_deck.candidates.pop())
|
4679
|
+
return Player(
|
4680
|
+
idx=p_idx,
|
4681
|
+
pieces=copy.deepcopy(public_player.pieces),
|
4682
|
+
cards=cards,
|
4683
|
+
discard_tray=discard_tray,
|
4684
|
+
)
|
4686
4685
|
|
4687
4686
|
|
4688
|
-
|
4689
|
-
|
4690
|
-
|
4687
|
+
def imagine_players(ps: PlayerState, candidate_decks: List[CandidateDeck]) -> List[Player]:
|
4688
|
+
imagined = [
|
4689
|
+
imagine_player(p_idx, ps, candidate_decks)
|
4690
|
+
for p_idx in range(len(ps.public.players))
|
4691
|
+
]
|
4692
|
+
return imagined
|
4693
|
+
|
4694
|
+
|
4695
|
+
def imagine_decks(ps: PlayerState, candidate_decks: List[CandidateDeck]) -> List[Deck]:
|
4696
|
+
public = ps.public
|
4697
|
+
imagined = [
|
4698
|
+
imagine_deck(public_deck, candidate_deck)
|
4699
|
+
for public_deck in public.decks
|
4700
|
+
]
|
4701
|
+
return imagined
|
4702
|
+
|
4703
|
+
|
4704
|
+
def imagine_deck(public_deck: PublicDeck, candidate_deck: CandidateDeck) -> Deck:
|
4705
|
+
return Deck(
|
4706
|
+
idx=public_deck.idx,
|
4707
|
+
uuid=public_deck.uuid,
|
4708
|
+
faceup_stack=(
|
4709
|
+
copy.deepcopy(public_deck.faceup_stack)
|
4710
|
+
if public_deck.faceup_stack else None
|
4711
|
+
),
|
4712
|
+
faceup_spread=(
|
4713
|
+
copy.deepcopy(public_deck.faceup_spread)
|
4714
|
+
if public_deck.faceup_spread else None
|
4715
|
+
),
|
4716
|
+
facedown_stack=(
|
4717
|
+
CardStack(
|
4718
|
+
hidden=True,
|
4719
|
+
cards=[
|
4720
|
+
candidate_deck.candidates.pop() for _ in range(public_deck.facedown_stack_len)
|
4721
|
+
]
|
4722
|
+
)
|
4723
|
+
if public_deck.facedown_stack_len > 0 else None
|
4724
|
+
),
|
4725
|
+
facedown_spread=(
|
4726
|
+
CardSpread(
|
4727
|
+
hidden=True,
|
4728
|
+
spots=[
|
4729
|
+
candidate_deck.candidates.pop() for _ in range(len(public_deck.facedown_spread_len))
|
4730
|
+
]
|
4731
|
+
)
|
4732
|
+
if public_deck.facedown_spread_len > 0 else None
|
4733
|
+
),
|
4734
|
+
discard_faceup_stack=(
|
4735
|
+
copy.deepcopy(public_deck.discard_faceup_stack)
|
4736
|
+
if public_deck.discard_faceup_stack else None
|
4737
|
+
),
|
4738
|
+
discard_facedown_stack=(
|
4739
|
+
CardStack(
|
4740
|
+
hidden=True,
|
4741
|
+
cards=[
|
4742
|
+
candidate_deck.candidates.pop() for _ in range(public_deck.discard_facedown_stack_len)
|
4743
|
+
]
|
4744
|
+
)
|
4745
|
+
if public_deck.discard_facedown_stack_len > 0 else None
|
4746
|
+
),
|
4747
|
+
)
|
4691
4748
|
|
4692
4749
|
|
4693
4750
|
@dispatch(PlayerState)
|
@@ -4695,7 +4752,9 @@ def imagine_state(ps):
|
|
4695
4752
|
public = ps.public
|
4696
4753
|
game_config = public.game_config
|
4697
4754
|
|
4698
|
-
|
4755
|
+
candidate_decks = get_candadate_decks(ps)
|
4756
|
+
imagined_decks = imagine_decks(ps, candidate_decks)
|
4757
|
+
imagined_players = imagine_players(ps, candidate_decks)
|
4699
4758
|
|
4700
4759
|
imagined_kernel = init_state_kernel(
|
4701
4760
|
GameConfig(
|
@@ -4709,9 +4768,9 @@ def imagine_state(ps):
|
|
4709
4768
|
nodes=public.nodes,
|
4710
4769
|
piles=public.piles,
|
4711
4770
|
player_idxs=public.player_idxs,
|
4712
|
-
decks=
|
4713
|
-
players=
|
4714
|
-
history=
|
4771
|
+
decks=imagined_decks,
|
4772
|
+
players=imagined_players,
|
4773
|
+
history=copy.deepcopy(public.history),
|
4715
4774
|
)
|
4716
4775
|
return init_memoized_state(imagined_kernel)
|
4717
4776
|
|
@@ -4810,6 +4869,9 @@ def getpublicplayer(s, p):
|
|
4810
4869
|
deck_counts = [0 for _ in s.kernel.game_config.fig.board_config.deks]
|
4811
4870
|
for card in p.cards:
|
4812
4871
|
deck_counts[s.kernel.carduuid2card[card].deck_idx] += 1
|
4872
|
+
discard_deck_counts = [0 for _ in s.kernel.game_config.fig.board_config.deks]
|
4873
|
+
for card in p.discard_tray:
|
4874
|
+
discard_deck_counts[s.kernel.carduuid2card[card].deck_idx] += 1
|
4813
4875
|
piece_template_counts = [0 for _ in s.kernel.game_config.fig.board_config.piece_templates]
|
4814
4876
|
for piece_uuid in p.pieces:
|
4815
4877
|
piece_template_counts[s.kernel.pieceuuid2piece[piece_uuid].piece_template_idx] += 1
|
@@ -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=t0ghADefUKH3eq4SjRPeuQ-fxQxz4HvuioYrPzBsAqU,204955
|
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.2113.dist-info/METADATA,sha256=hRb9YGXOkZ1D0j0Ix5Z8III2hBXE7_ShDdGUPS-SBu8,188
|
7
|
+
graph_games_proto-0.3.2113.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
8
|
+
graph_games_proto-0.3.2113.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
|
9
|
+
graph_games_proto-0.3.2113.dist-info/RECORD,,
|
File without changes
|
File without changes
|