graph-games-proto 0.3.2112__py3-none-any.whl → 0.3.2117__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 +137 -63
- {graph_games_proto-0.3.2112.dist-info → graph_games_proto-0.3.2117.dist-info}/METADATA +1 -1
- {graph_games_proto-0.3.2112.dist-info → graph_games_proto-0.3.2117.dist-info}/RECORD +5 -5
- {graph_games_proto-0.3.2112.dist-info → graph_games_proto-0.3.2117.dist-info}/WHEEL +0 -0
- {graph_games_proto-0.3.2112.dist-info → graph_games_proto-0.3.2117.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):
|
@@ -1234,14 +1215,12 @@ class LegalActionKeep(PClass):
|
|
1234
1215
|
]
|
1235
1216
|
num_cards = len(card_uuids_matching_deck)
|
1236
1217
|
actual_min = 0 if legal_action.keep.min is None else legal_action.keep.min
|
1237
|
-
actual_max = num_cards if legal_action.keep.max is None else min(legal_action.keep.max, num_cards)
|
1238
|
-
rand_num_chosen = state.kernel.rng.randint(actual_min, actual_max)
|
1239
|
-
card_uuids = card_uuids_matching_deck[0:rand_num_chosen]
|
1218
|
+
# actual_max = num_cards if legal_action.keep.max is None else min(legal_action.keep.max, num_cards)
|
1240
1219
|
return Action2(
|
1241
1220
|
submitted_at=submitted_at,
|
1242
1221
|
legal_action=legal_action,
|
1243
1222
|
keep=ActionKeep(
|
1244
|
-
|
1223
|
+
discard_tray_idxs=list(range(actual_min)),
|
1245
1224
|
)
|
1246
1225
|
)
|
1247
1226
|
|
@@ -1572,19 +1551,19 @@ class PublicActionDiscard(PClass):
|
|
1572
1551
|
|
1573
1552
|
|
1574
1553
|
class ActionDiscard(PClass):
|
1575
|
-
|
1554
|
+
discard_tray_idxs = field(type=list) # List[int]
|
1576
1555
|
def get_public(self, state):
|
1577
1556
|
return PublicActionDiscard(
|
1578
|
-
deck_idxs=[
|
1557
|
+
deck_idxs=[0 for card_idx in self.discard_tray_idxs] # TODO: fix this
|
1579
1558
|
)
|
1580
1559
|
def __todict__(self):
|
1581
1560
|
return {
|
1582
|
-
"
|
1561
|
+
"discard_tray_idxs": self.discard_tray_idxs,
|
1583
1562
|
}
|
1584
1563
|
@staticmethod
|
1585
1564
|
def __fromdict__(d):
|
1586
1565
|
return ActionDiscard(
|
1587
|
-
|
1566
|
+
discard_tray_idxs=d["discard_tray_idxs"]
|
1588
1567
|
)
|
1589
1568
|
|
1590
1569
|
|
@@ -1602,19 +1581,19 @@ class PublicActionKeep(PClass):
|
|
1602
1581
|
|
1603
1582
|
|
1604
1583
|
class ActionKeep(PClass):
|
1605
|
-
|
1584
|
+
discard_tray_idxs = field(type=list) # List[int]
|
1606
1585
|
def get_public(self, state):
|
1607
1586
|
return PublicActionKeep(
|
1608
|
-
deck_idxs=[
|
1587
|
+
deck_idxs=[0 for card_idx in self.discard_tray_idxs] # TODO: fix this
|
1609
1588
|
)
|
1610
1589
|
def __todict__(self):
|
1611
1590
|
return {
|
1612
|
-
"
|
1591
|
+
"discard_tray_idxs": self.discard_tray_idxs,
|
1613
1592
|
}
|
1614
1593
|
@staticmethod
|
1615
1594
|
def __fromdict__(d):
|
1616
1595
|
return ActionKeep(
|
1617
|
-
|
1596
|
+
discard_tray_idxs=d["discard_tray_idxs"]
|
1618
1597
|
)
|
1619
1598
|
|
1620
1599
|
|
@@ -1725,9 +1704,7 @@ class Deck(PClass):
|
|
1725
1704
|
facedown_stack = field(type=(CardStack, type(None)), initial=None)
|
1726
1705
|
facedown_spread = field(type=(CardSpread, type(None)), initial=None)
|
1727
1706
|
discard_faceup_stack = field(type=(CardStack, type(None)), initial=None)
|
1728
|
-
discard_faceup_spread = field(type=(CardSpread, type(None)), initial=None)
|
1729
1707
|
discard_facedown_stack = field(type=(CardStack, type(None)), initial=None)
|
1730
|
-
discard_facedown_spread = field(type=(CardSpread, type(None)), initial=None)
|
1731
1708
|
def __todict__(self):
|
1732
1709
|
return {
|
1733
1710
|
"idx": self.idx,
|
@@ -1737,9 +1714,7 @@ class Deck(PClass):
|
|
1737
1714
|
"facedown_stack": self.facedown_stack.__todict__() if self.facedown_stack else None,
|
1738
1715
|
"facedown_spread": self.facedown_spread.__todict__() if self.facedown_spread else None,
|
1739
1716
|
"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
1717
|
"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
1718
|
}
|
1744
1719
|
@staticmethod
|
1745
1720
|
def __fromdict__(d):
|
@@ -1751,12 +1726,24 @@ class Deck(PClass):
|
|
1751
1726
|
facedown_stack=CardStack.__fromdict__(d["facedown_stack"]) if d.get("facedown_stack") else None,
|
1752
1727
|
facedown_spread=CardSpread.__fromdict__(d["facedown_spread"]) if d.get("facedown_spread") else None,
|
1753
1728
|
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
1729
|
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
1730
|
)
|
1758
1731
|
|
1759
1732
|
|
1733
|
+
class CandidateDeck(PClass):
|
1734
|
+
deck_idx = field(type=int)
|
1735
|
+
candidates = field(type=list) # List[Card]
|
1736
|
+
def __todict__(self):
|
1737
|
+
return {
|
1738
|
+
'deck_idx': self.deck_idx,
|
1739
|
+
'candidates': [card.__todict__() for card in self.candidates],
|
1740
|
+
}
|
1741
|
+
@staticmethod
|
1742
|
+
def __fromdict__(d):
|
1743
|
+
return CandidateDeck(
|
1744
|
+
deck_idx=d["deck_idx"],
|
1745
|
+
candidates=[Card.__fromdict__(card) for card in d["candidates"]],
|
1746
|
+
)
|
1760
1747
|
|
1761
1748
|
|
1762
1749
|
class Card(PClass):
|
@@ -3797,11 +3784,15 @@ def handle_keep_action(kernel, action):
|
|
3797
3784
|
player = kernel.players[action.legal_action.player_idx]
|
3798
3785
|
if not player:
|
3799
3786
|
return kernel
|
3800
|
-
|
3801
|
-
|
3802
|
-
|
3803
|
-
|
3804
|
-
|
3787
|
+
|
3788
|
+
kept_cards = []
|
3789
|
+
non_kept_cards = []
|
3790
|
+
discard_tray_idxs = action.keep.discard_tray_idxs
|
3791
|
+
for i, card_uuid in enumerate(player.discard_tray):
|
3792
|
+
if i in discard_tray_idxs:
|
3793
|
+
kept_cards.append(card_uuid)
|
3794
|
+
else:
|
3795
|
+
non_kept_cards.append(card_uuid)
|
3805
3796
|
|
3806
3797
|
# Discard the non-kept cards to the deck's discard pile
|
3807
3798
|
deck.discard_faceup_stack.cards.extend(non_kept_cards)
|
@@ -3838,9 +3829,14 @@ def handle_discard_action(kernel, action):
|
|
3838
3829
|
if not player:
|
3839
3830
|
return kernel
|
3840
3831
|
|
3841
|
-
|
3842
|
-
|
3843
|
-
|
3832
|
+
non_kept_cards = []
|
3833
|
+
kept_cards = []
|
3834
|
+
discard_tray_idxs = action.discard.discard_tray_idxs
|
3835
|
+
for i, card_uuid in enumerate(player.discard_tray):
|
3836
|
+
if i in discard_tray_idxs:
|
3837
|
+
non_kept_cards.append(card_uuid)
|
3838
|
+
else:
|
3839
|
+
kept_cards.append(card_uuid)
|
3844
3840
|
|
3845
3841
|
print("****************************** handle_discard_action 5", kept_cards)
|
3846
3842
|
print("****************************** handle_discard_action 6", non_kept_cards)
|
@@ -4670,24 +4666,97 @@ def get_public_player_scores(s):
|
|
4670
4666
|
# goal_completions = field(type=list, initial=[]) # List[GoalCompletion]
|
4671
4667
|
|
4672
4668
|
|
4673
|
-
|
4674
|
-
def get_public_history(s):
|
4669
|
+
def get_public_history(s: State):
|
4675
4670
|
return [action.get_public(s) for action in s.kernel.history]
|
4676
4671
|
|
4677
4672
|
|
4678
|
-
|
4679
|
-
def imagine_history(ps) -> list[Action2]:
|
4673
|
+
def get_candidate_decks(ps: PlayerState) -> List[CandidateDeck]:
|
4680
4674
|
pass
|
4681
4675
|
|
4682
4676
|
|
4683
|
-
|
4684
|
-
|
4685
|
-
|
4677
|
+
def imagine_player(p_idx: int, ps: PlayerState, candidate_decks: List[CandidateDeck]) -> Player:
|
4678
|
+
if ps.private.player.idx == p_idx:
|
4679
|
+
return ps.private.player
|
4680
|
+
public_player = ps.public.players[p_idx]
|
4681
|
+
cards = []
|
4682
|
+
for deck_idx, count in enumerate(public_player.deck_counts):
|
4683
|
+
candidate_deck = candidate_decks[deck_idx]
|
4684
|
+
for _ in range(count):
|
4685
|
+
cards.append(candidate_deck.candidates.pop())
|
4686
|
+
discard_tray = []
|
4687
|
+
for deck_idx, count in enumerate(public_player.discard_deck_counts):
|
4688
|
+
candidate_deck = candidate_decks[deck_idx]
|
4689
|
+
for _ in range(count):
|
4690
|
+
discard_tray.append(candidate_deck.candidates.pop())
|
4691
|
+
return Player(
|
4692
|
+
idx=p_idx,
|
4693
|
+
pieces=copy.deepcopy(public_player.pieces),
|
4694
|
+
cards=cards,
|
4695
|
+
discard_tray=discard_tray,
|
4696
|
+
)
|
4686
4697
|
|
4687
4698
|
|
4688
|
-
|
4689
|
-
|
4690
|
-
|
4699
|
+
def imagine_players(ps: PlayerState, candidate_decks: List[CandidateDeck]) -> List[Player]:
|
4700
|
+
imagined = [
|
4701
|
+
imagine_player(p_idx, ps, candidate_decks)
|
4702
|
+
for p_idx in range(len(ps.public.players))
|
4703
|
+
]
|
4704
|
+
return imagined
|
4705
|
+
|
4706
|
+
|
4707
|
+
def imagine_decks(ps: PlayerState, candidate_decks: List[CandidateDeck]) -> List[Deck]:
|
4708
|
+
public = ps.public
|
4709
|
+
imagined = [
|
4710
|
+
imagine_deck(public_deck, candidate_deck)
|
4711
|
+
for public_deck in public.decks
|
4712
|
+
]
|
4713
|
+
return imagined
|
4714
|
+
|
4715
|
+
|
4716
|
+
def imagine_deck(public_deck: PublicDeck, candidate_deck: CandidateDeck) -> Deck:
|
4717
|
+
return Deck(
|
4718
|
+
idx=public_deck.idx,
|
4719
|
+
uuid=public_deck.uuid,
|
4720
|
+
faceup_stack=(
|
4721
|
+
copy.deepcopy(public_deck.faceup_stack)
|
4722
|
+
if public_deck.faceup_stack else None
|
4723
|
+
),
|
4724
|
+
faceup_spread=(
|
4725
|
+
copy.deepcopy(public_deck.faceup_spread)
|
4726
|
+
if public_deck.faceup_spread else None
|
4727
|
+
),
|
4728
|
+
facedown_stack=(
|
4729
|
+
CardStack(
|
4730
|
+
hidden=True,
|
4731
|
+
cards=[
|
4732
|
+
candidate_deck.candidates.pop() for _ in range(public_deck.facedown_stack_len)
|
4733
|
+
]
|
4734
|
+
)
|
4735
|
+
if public_deck.facedown_stack_len > 0 else None
|
4736
|
+
),
|
4737
|
+
facedown_spread=(
|
4738
|
+
CardSpread(
|
4739
|
+
hidden=True,
|
4740
|
+
spots=[
|
4741
|
+
candidate_deck.candidates.pop() for _ in range(len(public_deck.facedown_spread_len))
|
4742
|
+
]
|
4743
|
+
)
|
4744
|
+
if public_deck.facedown_spread_len > 0 else None
|
4745
|
+
),
|
4746
|
+
discard_faceup_stack=(
|
4747
|
+
copy.deepcopy(public_deck.discard_faceup_stack)
|
4748
|
+
if public_deck.discard_faceup_stack else None
|
4749
|
+
),
|
4750
|
+
discard_facedown_stack=(
|
4751
|
+
CardStack(
|
4752
|
+
hidden=True,
|
4753
|
+
cards=[
|
4754
|
+
candidate_deck.candidates.pop() for _ in range(public_deck.discard_facedown_stack_len)
|
4755
|
+
]
|
4756
|
+
)
|
4757
|
+
if public_deck.discard_facedown_stack_len > 0 else None
|
4758
|
+
),
|
4759
|
+
)
|
4691
4760
|
|
4692
4761
|
|
4693
4762
|
@dispatch(PlayerState)
|
@@ -4695,7 +4764,9 @@ def imagine_state(ps):
|
|
4695
4764
|
public = ps.public
|
4696
4765
|
game_config = public.game_config
|
4697
4766
|
|
4698
|
-
|
4767
|
+
candidate_decks = get_candadate_decks(ps)
|
4768
|
+
imagined_decks = imagine_decks(ps, candidate_decks)
|
4769
|
+
imagined_players = imagine_players(ps, candidate_decks)
|
4699
4770
|
|
4700
4771
|
imagined_kernel = init_state_kernel(
|
4701
4772
|
GameConfig(
|
@@ -4709,9 +4780,9 @@ def imagine_state(ps):
|
|
4709
4780
|
nodes=public.nodes,
|
4710
4781
|
piles=public.piles,
|
4711
4782
|
player_idxs=public.player_idxs,
|
4712
|
-
decks=
|
4713
|
-
players=
|
4714
|
-
history=
|
4783
|
+
decks=imagined_decks,
|
4784
|
+
players=imagined_players,
|
4785
|
+
history=copy.deepcopy(public.history),
|
4715
4786
|
)
|
4716
4787
|
return init_memoized_state(imagined_kernel)
|
4717
4788
|
|
@@ -4810,6 +4881,9 @@ def getpublicplayer(s, p):
|
|
4810
4881
|
deck_counts = [0 for _ in s.kernel.game_config.fig.board_config.deks]
|
4811
4882
|
for card in p.cards:
|
4812
4883
|
deck_counts[s.kernel.carduuid2card[card].deck_idx] += 1
|
4884
|
+
discard_deck_counts = [0 for _ in s.kernel.game_config.fig.board_config.deks]
|
4885
|
+
for card in p.discard_tray:
|
4886
|
+
discard_deck_counts[s.kernel.carduuid2card[card].deck_idx] += 1
|
4813
4887
|
piece_template_counts = [0 for _ in s.kernel.game_config.fig.board_config.piece_templates]
|
4814
4888
|
for piece_uuid in p.pieces:
|
4815
4889
|
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=-h-D3oVPRfVM7o_bt4DAsObBBc6dErf_I1N_6nb5f7Y,205315
|
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.2117.dist-info/METADATA,sha256=L47IoRHXE3jlzuonybqH4fLJ899bPu7yOuAuZKlSkHU,188
|
7
|
+
graph_games_proto-0.3.2117.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
8
|
+
graph_games_proto-0.3.2117.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
|
9
|
+
graph_games_proto-0.3.2117.dist-info/RECORD,,
|
File without changes
|
File without changes
|