graph-games-proto 0.3.1879__py3-none-any.whl → 0.3.1883__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
@@ -1960,7 +1960,6 @@ class State(PClass):
1960
1960
  decks = field(type=list) # List[Deck]
1961
1961
  game_config = field(type=GameConfig)
1962
1962
  rng = field(type=random.Random)
1963
- terminal = field(type=bool)
1964
1963
  last_to_play = field(type=(int, type(None)), initial=None)
1965
1964
  winners = field(type=list) # List[int]
1966
1965
  def __todict__(self):
@@ -1992,7 +1991,6 @@ class State(PClass):
1992
1991
  "decks": [deck.__todict__() for deck in self.decks],
1993
1992
  "game_config": self.game_config.__todict__(),
1994
1993
  "rng": rng2json(self.rng),
1995
- "terminal": self.terminal,
1996
1994
  "last_to_play": self.last_to_play,
1997
1995
  "winners": self.winners,
1998
1996
  }
@@ -2026,7 +2024,6 @@ class State(PClass):
2026
2024
  decks=[Deck.__fromdict__(deck) for deck in d["decks"]],
2027
2025
  game_config=GameConfig.__fromdict__(d["game_config"]),
2028
2026
  rng=json2rng(d["rng"]),
2029
- terminal=d["terminal"],
2030
2027
  last_to_play=d.get("last_to_play"),
2031
2028
  winners=d["winners"],
2032
2029
  )
@@ -2361,7 +2358,7 @@ def autoplay(seed, fig, num_players, policy, log=False):
2361
2358
  actions = []
2362
2359
  try:
2363
2360
 
2364
- while not s.terminal:
2361
+ while not isterminal(s):
2365
2362
  if log:
2366
2363
  printstate(s)
2367
2364
  a = getnextaction(s, policy)
@@ -2605,7 +2602,6 @@ def getinitialstate(game_config):
2605
2602
  rng=rng,
2606
2603
  last_to_play=None,
2607
2604
  winners=[],
2608
- terminal=False,
2609
2605
  )
2610
2606
 
2611
2607
  state = run_state_hooks(state, INITIALIZATION_HOOKS, True)
@@ -2721,7 +2717,7 @@ def getfinalscores(game):
2721
2717
 
2722
2718
 
2723
2719
  def handle_calc_winners(game):
2724
- if game.terminal:
2720
+ if isterminal(game):
2725
2721
  players_with_highest_score = []
2726
2722
  highest_score = -1000
2727
2723
  final_scores = getfinalscores(game)
@@ -4032,7 +4028,7 @@ def getnextstate2(s, a, log=False):
4032
4028
 
4033
4029
 
4034
4030
  def getpublicplayerscore(s, player_score):
4035
- if s.terminal:
4031
+ if isterminal(s):
4036
4032
  # Join the arrays of public and private items
4037
4033
  items = player_score.public_items + player_score.private_items
4038
4034
  else:
@@ -4106,7 +4102,7 @@ def get_deadline(s, max_allotted_time):
4106
4102
 
4107
4103
 
4108
4104
  def get_deadlines(s):
4109
- if s.terminal:
4105
+ if isterminal(s):
4110
4106
  return [None for _ in range(s.game_config.num_players)]
4111
4107
  return [
4112
4108
  get_deadline(s, max_alloted_time)
@@ -4191,7 +4187,6 @@ def imagine_state(public_state, private_state):
4191
4187
  edgeuuid2idx = public_state.edgeuuid2idx,
4192
4188
  edgetuple2uuid = public_state.edgetuple2uuid,
4193
4189
  regions = public_state.regions,
4194
- terminal = public_state.terminal,
4195
4190
  last_to_play = public_state.last_to_play,
4196
4191
  winners = public_state.winners,
4197
4192
  piles = public_state.piles,
@@ -4206,6 +4201,10 @@ def imagine_state(public_state, private_state):
4206
4201
  )
4207
4202
 
4208
4203
 
4204
+ def isterminal(s):
4205
+ return len(s.legal_actions_2) > 0
4206
+
4207
+
4209
4208
  @dispatch(State)
4210
4209
  def getpublicstate(s):
4211
4210
  return PublicState(
@@ -4230,7 +4229,7 @@ def getpublicstate(s):
4230
4229
  players=[getpublicplayer(s, p) for p in s.players],
4231
4230
  last_to_play=s.last_to_play,
4232
4231
  winners=s.winners,
4233
- terminal=s.terminal,
4232
+ terminal=isterminal(s),
4234
4233
  )
4235
4234
 
4236
4235
 
@@ -4462,43 +4461,7 @@ def get_goals(s, player_idx):
4462
4461
  goaluuid2goal[goal_uuid] for goal_uuid in goal_uuids if goal_uuid in goaluuid2goal
4463
4462
  ]
4464
4463
 
4465
- # @dispatch(AltState, RouteDiscardAction)
4466
- # def gettoplay(s, action_type):
4467
- # return [1]
4468
4464
 
4469
-
4470
- # @dispatch(AltState, DrawUnitDeckAction)
4471
- # def gettoplay(s, action_type):
4472
- # return [2]
4473
-
4474
- # Implementing the following Julia function:
4475
- # function getlegalactions(s::State, player_idx::Int)
4476
- # # Causal function chain: gettoplay => getlegalactions => isterminal
4477
- # if s.terminal
4478
- # return []
4479
- # end
4480
- # if !in(player_idx, gettoplay(s))
4481
- # return []
4482
- # end
4483
- # getlegalactionsforplayer(s::State, player_idx, getrepeatplayerkey(s, player_idx), getlastactionkey(s))
4484
- # end
4485
- @dispatch(State, int)
4486
- def getlegalactionspecs(s, player_idx):
4487
- # Causal function chain: gettoplay => getlegalactions => isterminal
4488
- if s.terminal:
4489
- return []
4490
- if player_idx not in gettoplay(s):
4491
- return []
4492
- return getlegalactionspecsforplayer(s, player_idx, getrepeatplayerbooltype(s, player_idx), getlastactiontype(s))
4493
-
4494
- # Implementing the following Julia function:
4495
- # function getrepeatplayerkey(s::State, player_idx)
4496
- # last_action = getlastaction(s)
4497
- # if isnothing(last_action)
4498
- # return Val(false)
4499
- # end
4500
- # Val(player_idx == last_action.player_idx)
4501
- # end
4502
4465
  def getrepeatplayerbooltype(s, player_idx):
4503
4466
  pass
4504
4467
 
@@ -4803,28 +4766,6 @@ def getunavailablepoints(s):
4803
4766
  return unavailable_points
4804
4767
 
4805
4768
 
4806
- # Implementing the following Julia function:
4807
- # function calcwinners(s::State)
4808
- # if !s.terminal
4809
- # return s
4810
- # end
4811
- # s = calcfinalscores(s)
4812
- # player_scores = [p.final_score for p in s.player_hands]
4813
- # max_score = maximum([p.total for p in player_scores])
4814
- # @reset s.winners = [h.player_idx for h in s.player_hands if h.final_score.total == max_score]
4815
- # s
4816
- # end
4817
- @dispatch(State)
4818
- def calcwinners(s):
4819
- if not s.terminal:
4820
- return s
4821
- s = calcfinalscores(s)
4822
- player_scores = [p.final_score for p in s.player_hands]
4823
- max_score = max([p.total for p in player_scores])
4824
- winners = [h.player_idx for h in s.player_hands if h.final_score.total == max_score]
4825
- return s.set(winners=winners)
4826
-
4827
-
4828
4769
  def printplayer(s, player_idx):
4829
4770
  pass
4830
4771
 
@@ -4881,31 +4822,6 @@ def getvalidspotnums(s):
4881
4822
  return [n for n in range(1, len(s.faceup_spots) + 1) if s.faceup_spots[n-1] is not None]
4882
4823
 
4883
4824
 
4884
- # Implementing the following Julia function:
4885
- # function getlegalactions(s::State)
4886
- # getlegalactions(s, gettoplay(s))
4887
- # end
4888
- @dispatch(State)
4889
- def getlegalactionspecs(s):
4890
- return getlegalactionspecs(s, gettoplay(s))
4891
-
4892
-
4893
- # Implementing the following Julia function:
4894
- # function getlegalactions(s::State, player_idxs::Vector{Int})
4895
- # legal_actions = []
4896
- # for player_idx in player_idxs
4897
- # append!(legal_actions, getlegalactions(s, player_idx))
4898
- # end
4899
- # legal_actions
4900
- # end
4901
- @dispatch(State, list)
4902
- def getlegalactionspecs(s, player_idxs):
4903
- legal_actions = []
4904
- for player_idx in player_idxs:
4905
- legal_actions.extend(getlegalactionspecs(s, player_idx))
4906
- return legal_actions
4907
-
4908
-
4909
4825
  def json_serializer(obj):
4910
4826
  if isinstance(obj, set):
4911
4827
  return list(obj)
@@ -4961,7 +4877,7 @@ def json2rng(json_str):
4961
4877
  @dispatch(State, int)
4962
4878
  def getprivatestate(s, player_idx):
4963
4879
  return PrivateState(
4964
- my_history=[a for a in s.history if a.player_idx == player_idx],
4880
+ my_history=[a for a in s.history if a.legal_action.player_idx == player_idx],
4965
4881
  player_score=getprivateplayerscore(s, s.player_scores[player_idx]),
4966
4882
  player=s.players[player_idx],
4967
4883
  legal_actions_2 = get_legal_actions(s, player_idx),
@@ -5170,7 +5086,7 @@ def getqproxy0(ps, a, td):
5170
5086
 
5171
5087
  def qproxybase():
5172
5088
  next_s, rewards = imagine_dynamics(ps, a)
5173
- if next_s.terminal:
5089
+ if isterminal(next_s):
5174
5090
  return rewards
5175
5091
  v_proxies = [
5176
5092
  getvproxy0(getprivatestate(next_s, i))
@@ -5184,7 +5100,7 @@ def getqproxy0(ps, a, td):
5184
5100
 
5185
5101
  def qproxyrecurse():
5186
5102
  next_s, rewards = imagine_dynamics(ps, a)
5187
- if next_s.terminal:
5103
+ if isterminal(next_s):
5188
5104
  return rewards
5189
5105
  next_p_idx = get_default_toplay(next_s)
5190
5106
  next_ps = getprivatestate(next_s, next_p_idx)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graph_games_proto
3
- Version: 0.3.1879
3
+ Version: 0.3.1883
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=6JU5hcSKyQZsznafiC7ai9i-fa9U3EkuSCsWTKcKacw,655
2
2
  graph_games_proto/all_types.py,sha256=IpbwftEcHS5Ewz-saFNk0lO9FvcbuHG36odRTayCXUk,54911
3
- graph_games_proto/fns.py,sha256=S6fm3DR2C-Oirg2Jn_tdejq16yiYqny2LdYmiOB1K28,184052
3
+ graph_games_proto/fns.py,sha256=wges3b5aBKcXAU2NQE68QWiWtOVwTMSoKKFQgSlIc3k,181331
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.1879.dist-info/METADATA,sha256=azdf6XC2xVJZuIb_OG7CWmwNDmnVmLGviQfVK3XGuIk,188
7
- graph_games_proto-0.3.1879.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
- graph_games_proto-0.3.1879.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
- graph_games_proto-0.3.1879.dist-info/RECORD,,
6
+ graph_games_proto-0.3.1883.dist-info/METADATA,sha256=2x2rCMRSdtA1BpkE5dvnh8KHN8RWrUBrjWsR7J38LKI,188
7
+ graph_games_proto-0.3.1883.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
+ graph_games_proto-0.3.1883.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
+ graph_games_proto-0.3.1883.dist-info/RECORD,,