graph-games-proto 0.3.1953__py3-none-any.whl → 0.3.1966__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 +38 -42
- {graph_games_proto-0.3.1953.dist-info → graph_games_proto-0.3.1966.dist-info}/METADATA +1 -1
- {graph_games_proto-0.3.1953.dist-info → graph_games_proto-0.3.1966.dist-info}/RECORD +5 -5
- {graph_games_proto-0.3.1953.dist-info → graph_games_proto-0.3.1966.dist-info}/WHEEL +0 -0
- {graph_games_proto-0.3.1953.dist-info → graph_games_proto-0.3.1966.dist-info}/top_level.txt +0 -0
graph_games_proto/fns.py
CHANGED
@@ -2060,7 +2060,6 @@ class State(PClass):
|
|
2060
2060
|
players = field(type=list) # List[Player]
|
2061
2061
|
player_idxs = field(type=list) # List[int]
|
2062
2062
|
decks = field(type=list) # List[Deck]
|
2063
|
-
game_config = field(type=GameConfig)
|
2064
2063
|
rng = field(type=random.Random)
|
2065
2064
|
last_to_play = field(type=(int, type(None)), initial=None)
|
2066
2065
|
winners = field(type=list) # List[int]
|
@@ -2086,7 +2085,6 @@ class State(PClass):
|
|
2086
2085
|
"players": [player.__todict__() for player in self.players],
|
2087
2086
|
"player_idxs": self.player_idxs,
|
2088
2087
|
"decks": [deck.__todict__() for deck in self.decks],
|
2089
|
-
"game_config": self.game_config.__todict__(),
|
2090
2088
|
"rng": rng2json(self.rng),
|
2091
2089
|
"last_to_play": self.last_to_play,
|
2092
2090
|
"winners": self.winners,
|
@@ -2114,7 +2112,6 @@ class State(PClass):
|
|
2114
2112
|
players=[Player.__fromdict__(p) for p in d["players"]],
|
2115
2113
|
player_idxs=d["player_idxs"],
|
2116
2114
|
decks=[Deck.__fromdict__(deck) for deck in d["decks"]],
|
2117
|
-
game_config=GameConfig.__fromdict__(d["game_config"]),
|
2118
2115
|
rng=json2rng(d["rng"]),
|
2119
2116
|
last_to_play=d.get("last_to_play"),
|
2120
2117
|
winners=d["winners"],
|
@@ -2567,7 +2564,7 @@ def getsettingvalue(f, setting_name):
|
|
2567
2564
|
|
2568
2565
|
@dispatch(State, str)
|
2569
2566
|
def getsettingvalue(s, setting_name):
|
2570
|
-
return getsettingvalue(s.game_config.fig, setting_name)
|
2567
|
+
return getsettingvalue(s.kernel.game_config.fig, setting_name)
|
2571
2568
|
|
2572
2569
|
|
2573
2570
|
@dispatch(GameConfig)
|
@@ -2669,7 +2666,6 @@ def getinitialstate(game_config):
|
|
2669
2666
|
players=[Player(idx=idx, pieces=[], cards=[], discard_tray=[]) for idx in range(game_config.num_players)],
|
2670
2667
|
player_idxs=list(range(game_config.num_players)),
|
2671
2668
|
decks=decks,
|
2672
|
-
game_config=game_config,
|
2673
2669
|
rng=rng,
|
2674
2670
|
last_to_play=None,
|
2675
2671
|
winners=[],
|
@@ -2679,7 +2675,7 @@ def getinitialstate(game_config):
|
|
2679
2675
|
|
2680
2676
|
kernel = init_state_kernel(
|
2681
2677
|
rng=rng,
|
2682
|
-
game_config=
|
2678
|
+
game_config=game_config,
|
2683
2679
|
edges=state.edges,
|
2684
2680
|
decks=state.decks,
|
2685
2681
|
piles=state.piles,
|
@@ -2722,14 +2718,14 @@ def run_state_action_hooks(state, action, hooks, log=False):
|
|
2722
2718
|
)
|
2723
2719
|
|
2724
2720
|
|
2725
|
-
def score_public_items(
|
2721
|
+
def score_public_items(state, player_idx):
|
2726
2722
|
items = []
|
2727
|
-
for edge in
|
2723
|
+
for edge in state.edges:
|
2728
2724
|
for path in edge.paths:
|
2729
2725
|
if len(path.segments) > 0:
|
2730
2726
|
first_segment = path.segments[0]
|
2731
2727
|
if first_segment.pieces and len(first_segment.pieces) > 0:
|
2732
|
-
first_piece =
|
2728
|
+
first_piece = state.pieceuuid2piece[first_segment.pieces[0]]
|
2733
2729
|
if first_piece.player_idx == player_idx:
|
2734
2730
|
items.append(
|
2735
2731
|
ScoreItem2(
|
@@ -2742,9 +2738,9 @@ def score_public_items(game, player_idx):
|
|
2742
2738
|
description="Player {} owns edge {}".format(player_idx, edge.uuid),
|
2743
2739
|
)
|
2744
2740
|
)
|
2745
|
-
for bonus_status in
|
2746
|
-
bonus_idx =
|
2747
|
-
bonus =
|
2741
|
+
for bonus_status in state.bonus_statuses:
|
2742
|
+
bonus_idx = state.bonusuuid2bonusidx.get(bonus_status.bonus_uuid)
|
2743
|
+
bonus = state.kernel.game_config.fig.board_config.bonuses[bonus_idx] if bonus_idx is not None else None
|
2748
2744
|
if bonus:
|
2749
2745
|
if player_idx in bonus_status.winners:
|
2750
2746
|
items.append(
|
@@ -2836,13 +2832,13 @@ def calc_bonus_status(game, bonus):
|
|
2836
2832
|
return None
|
2837
2833
|
|
2838
2834
|
|
2839
|
-
def get_bonus_status_longest_trail(
|
2835
|
+
def get_bonus_status_longest_trail(state, bonus):
|
2840
2836
|
longest_trail = 0
|
2841
2837
|
winners = []
|
2842
2838
|
player_longest_trail_lens = []
|
2843
2839
|
|
2844
|
-
for player_idx in range(
|
2845
|
-
trail_length = get_longest_path_length(
|
2840
|
+
for player_idx in range(state.kernel.game_config.num_players):
|
2841
|
+
trail_length = get_longest_path_length(state, player_idx)
|
2846
2842
|
player_longest_trail_lens.append(trail_length)
|
2847
2843
|
if trail_length > longest_trail:
|
2848
2844
|
longest_trail = trail_length
|
@@ -2868,14 +2864,14 @@ def get_bonus_status_longest_trail(game, bonus):
|
|
2868
2864
|
)
|
2869
2865
|
|
2870
2866
|
|
2871
|
-
def handle_bonus_statuses(
|
2867
|
+
def handle_bonus_statuses(state):
|
2872
2868
|
bonus_statuses = [
|
2873
|
-
calc_bonus_status(
|
2874
|
-
for bonus in
|
2869
|
+
calc_bonus_status(state, bonus)
|
2870
|
+
for bonus in state.kernel.game_config.fig.board_config.bonuses
|
2875
2871
|
]
|
2876
2872
|
# Remove all None bonus statuses
|
2877
2873
|
bonus_statuses = [bs for bs in bonus_statuses if bs is not None]
|
2878
|
-
return
|
2874
|
+
return state.set(bonus_statuses=bonus_statuses)
|
2879
2875
|
|
2880
2876
|
|
2881
2877
|
def default_handle_scoring(game):
|
@@ -3176,12 +3172,12 @@ def random_player_graph_walk(game, player_idx):
|
|
3176
3172
|
return walk([random_start_node_idx], set([]))
|
3177
3173
|
|
3178
3174
|
|
3179
|
-
def find_player_with_longest_path(
|
3175
|
+
def find_player_with_longest_path(state):
|
3180
3176
|
longest_path_player_idx = None
|
3181
3177
|
longest_path_length = 0
|
3182
3178
|
|
3183
|
-
for player_idx in range(
|
3184
|
-
path_length = get_longest_path_length(
|
3179
|
+
for player_idx in range(state.kernel.game_config.num_players):
|
3180
|
+
path_length = get_longest_path_length(state, player_idx)
|
3185
3181
|
if path_length > longest_path_length:
|
3186
3182
|
longest_path_length = path_length
|
3187
3183
|
longest_path_player_idx = player_idx
|
@@ -3189,7 +3185,7 @@ def find_player_with_longest_path(game):
|
|
3189
3185
|
if longest_path_player_idx is None:
|
3190
3186
|
return None
|
3191
3187
|
|
3192
|
-
return
|
3188
|
+
return state.players[longest_path_player_idx]
|
3193
3189
|
|
3194
3190
|
|
3195
3191
|
@dispatch(State, set)
|
@@ -3340,10 +3336,10 @@ def calc_player_graph(game, player_idx):
|
|
3340
3336
|
)
|
3341
3337
|
|
3342
3338
|
|
3343
|
-
def calc_player_graphs(
|
3344
|
-
game_config =
|
3339
|
+
def calc_player_graphs(state):
|
3340
|
+
game_config = state.kernel.game_config
|
3345
3341
|
return [
|
3346
|
-
calc_player_graph(
|
3342
|
+
calc_player_graph(state, player_idx)
|
3347
3343
|
for player_idx in range(game_config.num_players)
|
3348
3344
|
]
|
3349
3345
|
|
@@ -4094,7 +4090,7 @@ def getnextstate2(s, a, log=False):
|
|
4094
4090
|
|
4095
4091
|
state_kernel = init_state_kernel(
|
4096
4092
|
rng=s.rng,
|
4097
|
-
game_config=s.game_config,
|
4093
|
+
game_config=s.kernel.game_config,
|
4098
4094
|
edges=s.edges,
|
4099
4095
|
decks=s.decks,
|
4100
4096
|
piles=s.piles,
|
@@ -4140,7 +4136,7 @@ def getpublictoplay(s):
|
|
4140
4136
|
def get_max_allotted_times(s):
|
4141
4137
|
return [
|
4142
4138
|
get_player_max_allotted_time(s, player_idx)
|
4143
|
-
for player_idx in range(s.game_config.num_players)
|
4139
|
+
for player_idx in range(s.kernel.game_config.num_players)
|
4144
4140
|
]
|
4145
4141
|
|
4146
4142
|
|
@@ -4166,7 +4162,7 @@ def get_deadline(s, max_allotted_time):
|
|
4166
4162
|
since_action_idx = max_allotted_time.since_action_idx
|
4167
4163
|
if since_action_idx == -1:
|
4168
4164
|
allotted_since = datetime.strptime(
|
4169
|
-
s.game_config.started_at,
|
4165
|
+
s.kernel.game_config.started_at,
|
4170
4166
|
"%Y-%m-%d %H:%M:%S"
|
4171
4167
|
)
|
4172
4168
|
else:
|
@@ -4184,7 +4180,7 @@ def get_deadline(s, max_allotted_time):
|
|
4184
4180
|
|
4185
4181
|
def get_deadlines(s):
|
4186
4182
|
if isterminal(s):
|
4187
|
-
return [None for _ in range(s.game_config.num_players)]
|
4183
|
+
return [None for _ in range(s.kernel.game_config.num_players)]
|
4188
4184
|
return [
|
4189
4185
|
get_deadline(s, max_alloted_time)
|
4190
4186
|
for max_alloted_time in get_max_allotted_times(s)
|
@@ -4268,7 +4264,7 @@ def isterminal(s):
|
|
4268
4264
|
def getpublicstate(s):
|
4269
4265
|
return PublicState(
|
4270
4266
|
deadlines=get_deadlines(s),
|
4271
|
-
game_started_at=s.game_config.started_at,
|
4267
|
+
game_started_at=s.kernel.game_config.started_at,
|
4272
4268
|
allotted_times=get_max_allotted_times(s),
|
4273
4269
|
all_pieces=list(s.pieceuuid2piece.values()),
|
4274
4270
|
to_play_2=getpublictoplay(s),
|
@@ -4306,10 +4302,10 @@ def getpublicdeck(s, d):
|
|
4306
4302
|
|
4307
4303
|
@dispatch(State, Player)
|
4308
4304
|
def getpublicplayer(s, p):
|
4309
|
-
deck_counts = [0 for _ in s.game_config.fig.board_config.deks]
|
4305
|
+
deck_counts = [0 for _ in s.kernel.game_config.fig.board_config.deks]
|
4310
4306
|
for card in p.cards:
|
4311
4307
|
deck_counts[s.kernel.carduuid2card[card].deck_idx] += 1
|
4312
|
-
piece_template_counts = [0 for _ in s.game_config.fig.board_config.piece_templates]
|
4308
|
+
piece_template_counts = [0 for _ in s.kernel.game_config.fig.board_config.piece_templates]
|
4313
4309
|
for piece_uuid in p.pieces:
|
4314
4310
|
piece_template_counts[s.pieceuuid2piece[piece_uuid].piece_template_idx] += 1
|
4315
4311
|
return PublicPlayer(
|
@@ -4353,10 +4349,10 @@ def getpublicscore(s, player_idx):
|
|
4353
4349
|
path_lens = getplayerpathlens(s, player_idx)
|
4354
4350
|
if not path_lens:
|
4355
4351
|
return 0
|
4356
|
-
addends.append(sum(s.game_config.fig.path_scores[len] for len in path_lens))
|
4352
|
+
addends.append(sum(s.kernel.game_config.fig.path_scores[len] for len in path_lens))
|
4357
4353
|
|
4358
4354
|
if getsettingvalue(s, 'cluster_scoring'):
|
4359
|
-
clusters = s.game_config.fig.board_config.clusters
|
4355
|
+
clusters = s.kernel.game_config.fig.board_config.clusters
|
4360
4356
|
uuid2cluster = {x.uuid: x for x in clusters}
|
4361
4357
|
completed_clusters = s.player_hands[player_idx].completed_clusters
|
4362
4358
|
cluster_scores = [uuid2cluster[cluster_uuid].score for cluster_uuid in completed_clusters]
|
@@ -4379,7 +4375,7 @@ def getplayerpathlens(s, player_idx):
|
|
4379
4375
|
# Implementing the following Julia function:
|
4380
4376
|
# getpathlens(s::State) = length.(getfield.(getfield.(s.fig.board_config.board_paths, :path), :segments))
|
4381
4377
|
def getpathlens(s):
|
4382
|
-
return [len(p.path.segments) for p in s.game_config.fig.board_config.board_paths]
|
4378
|
+
return [len(p.path.segments) for p in s.kernel.game_config.fig.board_config.board_paths]
|
4383
4379
|
|
4384
4380
|
# Implementing the following Julia function:
|
4385
4381
|
# function getplayerpathidxs(s::State, player_idx::Int)
|
@@ -4419,7 +4415,7 @@ def getactiontype(action_name):
|
|
4419
4415
|
|
4420
4416
|
|
4421
4417
|
# Function implements the following Julia function:
|
4422
|
-
# getlastplayeridxplus1(s) = mod1(getlastaction(s).player_idx + 1, s.game_config.num_players)
|
4418
|
+
# getlastplayeridxplus1(s) = mod1(getlastaction(s).player_idx + 1, s.kernel.game_config.num_players)
|
4423
4419
|
def getlastplayeridxplus1(s):
|
4424
4420
|
pass
|
4425
4421
|
|
@@ -4565,7 +4561,7 @@ def combinations(a, n=None):
|
|
4565
4561
|
def getpotentialpathidxs(s, player_num):
|
4566
4562
|
num_pieces = s.player_hands[player_num-1].num_pieces
|
4567
4563
|
return list(
|
4568
|
-
set(getpathidxs(s.game_config.fig, num_pieces)) - set(getunavailablepathidxs(s, player_num))
|
4564
|
+
set(getpathidxs(s.kernel.game_config.fig, num_pieces)) - set(getunavailablepathidxs(s, player_num))
|
4569
4565
|
)
|
4570
4566
|
# return list(set(getpathidxs(s.fig, num_pieces)) - set(getunavailablepaths(s, player_num)))
|
4571
4567
|
|
@@ -4629,16 +4625,16 @@ def getunavailablepathidxs(s, player_idx):
|
|
4629
4625
|
link2paths = {}
|
4630
4626
|
path2link = {}
|
4631
4627
|
|
4632
|
-
for board_path in s.game_config.fig.board_config.board_paths:
|
4628
|
+
for board_path in s.kernel.game_config.fig.board_config.board_paths:
|
4633
4629
|
link_idx = board_path.link_num - 1
|
4634
4630
|
if link_idx not in link2paths:
|
4635
4631
|
link2paths[link_idx] = []
|
4636
4632
|
link2paths[link_idx].append(board_path.num-1)
|
4637
4633
|
path2link[board_path.num-1] = link_idx
|
4638
4634
|
|
4639
|
-
multipath_links = [(board_link.num-1) for board_link in getmultipathlinks(s.game_config.fig)]
|
4635
|
+
multipath_links = [(board_link.num-1) for board_link in getmultipathlinks(s.kernel.game_config.fig)]
|
4640
4636
|
|
4641
|
-
if s.game_config.num_players < 4:
|
4637
|
+
if s.kernel.game_config.num_players < 4:
|
4642
4638
|
blocking_hands = s.player_hands
|
4643
4639
|
else:
|
4644
4640
|
blocking_hands = [s.player_hands[player_idx]]
|
@@ -5144,7 +5140,7 @@ def getqproxy0(ps, a, td):
|
|
5144
5140
|
return rewards
|
5145
5141
|
v_proxies = [
|
5146
5142
|
getvproxy0(getprivatestate(next_s, i))
|
5147
|
-
for i in range(next_s.game_config.num_players)
|
5143
|
+
for i in range(next_s.kernel.game_config.num_players)
|
5148
5144
|
]
|
5149
5145
|
q_proxies = [
|
5150
5146
|
r + v_proxies[i]
|
@@ -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=XaDJPmMLioflSj00zzPXjdF1JfBh-hZB5dLO1OTn7lQ,182090
|
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.1966.dist-info/METADATA,sha256=4JWfsAdg8cjBPgPN1tFc6UuRWIMKSvKtceQmO5iRN4s,188
|
7
|
+
graph_games_proto-0.3.1966.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
8
|
+
graph_games_proto-0.3.1966.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
|
9
|
+
graph_games_proto-0.3.1966.dist-info/RECORD,,
|
File without changes
|
File without changes
|