graph-games-proto 0.3.1831__py3-none-any.whl → 0.3.1865__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
@@ -3024,9 +3024,12 @@ def run_state_hooks(state, hooks, log=False):
3024
3024
  def run_accept_action_hooks(state, action, hooks, log=False):
3025
3025
  # Just like "run_state_action_hooks", but returns immediately returns True if any hook returns True, otherwise returns False
3026
3026
  for hook in hooks:
3027
- if run_state_action_hook(state, action, hook, log):
3028
- return True
3029
- return False
3027
+ is_accepted, reason = run_state_action_hook(state, action, hook, log)
3028
+ if is_accepted is not None and is_accepted:
3029
+ return True, reason
3030
+ elif is_accepted is not None and not is_accepted:
3031
+ return False, reason
3032
+ return False, "No hook accepted the action"
3030
3033
 
3031
3034
 
3032
3035
  def run_state_action_hooks(state, action, hooks, log=False):
@@ -3887,16 +3890,19 @@ def append_to_legal_actions(game, legal_action):
3887
3890
 
3888
3891
 
3889
3892
  def default_accept_action(game, action):
3893
+
3890
3894
  # Returns true if action.legal_action is found in game.legal_actions_2
3891
3895
  # The comparision is by value, not by reference
3892
- if not game or not action or not action.legal_action:
3893
- return False
3896
+ if action.legal_action not in game.legal_actions_2:
3897
+ return False, "Action not found in legal actions"
3894
3898
 
3895
3899
  # Check if "action.move_pieces_to_path" is not None
3896
3900
  if action.move_pieces_to_path:
3897
- return is_move_pieces_to_path_action_legal(game, action)
3898
-
3899
- return action.legal_action in game.legal_actions_2
3901
+ is_legal = is_move_pieces_to_path_action_legal(game, action)
3902
+ if not is_legal:
3903
+ return False, "Move pieces to path action is not legal"
3904
+
3905
+ return True, "Action is legal"
3900
3906
 
3901
3907
 
3902
3908
  def is_move_pieces_to_path_action_legal(game, action):
@@ -3961,11 +3967,13 @@ def append_default_legal_actions_for_initial_player(game, action, log=False):
3961
3967
  return result
3962
3968
 
3963
3969
  except SyntaxError as e:
3964
- logging.error(f"Syntax error in initialization hook --TODO--: {str(e)}", exc_info=True)
3965
- return game
3970
+ msg = f"Syntax error in initialization hook: {str(e)}"
3971
+ logging.error(msg, exc_info=True)
3972
+ raise SyntaxError(msg) from e
3966
3973
  except Exception as e:
3967
- logging.error(f"Error in initialization hook --TODO--: {str(e)}", exc_info=True)
3968
- return game
3974
+ msg = f"Error in initialization hook: {str(e)}"
3975
+ logging.error(msg, exc_info=True)
3976
+ raise Exception(msg) from e
3969
3977
 
3970
3978
 
3971
3979
  def append_default_legal_actions_for_next_player(game, action, log=False):
@@ -3995,11 +4003,13 @@ def append_default_legal_actions_for_next_player(game, action, log=False):
3995
4003
  return result
3996
4004
 
3997
4005
  except SyntaxError as e:
3998
- logging.error(f"Syntax error in initialization hook --TODO--: {str(e)}", exc_info=True)
3999
- return game
4006
+ msg = f"Syntax error in initialization hook: {str(e)}"
4007
+ logging.error(msg, exc_info=True)
4008
+ raise SyntaxError(msg) from e
4000
4009
  except Exception as e:
4001
- logging.error(f"Error in initialization hook --TODO--: {str(e)}", exc_info=True)
4002
- return game
4010
+ msg = f"Error in initialization hook: {str(e)}"
4011
+ logging.error(msg, exc_info=True)
4012
+ raise Exception(msg) from e
4003
4013
 
4004
4014
 
4005
4015
  def get_total_path_count(game):
@@ -4336,11 +4346,13 @@ def run_state_action_hook(state, action, hook, log=False):
4336
4346
  return result
4337
4347
 
4338
4348
  except SyntaxError as e:
4339
- logging.error(f"Syntax error in initialization hook {hook.uuid}: {str(e)}", exc_info=True)
4340
- return state
4349
+ msg = f"Syntax error in initialization hook {hook.uuid}: {str(e)}"
4350
+ logging.error(msg, exc_info=True)
4351
+ raise SyntaxError(msg) from e
4341
4352
  except Exception as e:
4342
- logging.error(f"Error in initialization hook {hook.uuid}: {str(e)}", exc_info=True)
4343
- return state
4353
+ msg = f"Error in initialization hook {hook.uuid}: {str(e)}"
4354
+ logging.error(msg, exc_info=True)
4355
+ raise Exception(msg) from e
4344
4356
 
4345
4357
 
4346
4358
  def run_state_hook(state, hook, log=False):
@@ -4365,11 +4377,13 @@ def run_state_hook(state, hook, log=False):
4365
4377
  return result
4366
4378
 
4367
4379
  except SyntaxError as e:
4368
- logging.error(f"Syntax error in initialization hook {hook.uuid}: {str(e)}", exc_info=True)
4369
- return state
4380
+ msg = f"Syntax error in initialization hook {hook.uuid}: {str(e)}"
4381
+ logging.error(msg, exc_info=True)
4382
+ raise SyntaxError(msg) from e
4370
4383
  except Exception as e:
4371
- logging.error(f"Error in initialization hook {hook.uuid}: {str(e)}", exc_info=True)
4372
- return state
4384
+ msg = f"Error in initialization hook {hook.uuid}: {str(e)}"
4385
+ logging.error(msg, exc_info=True)
4386
+ raise Exception(msg) from e
4373
4387
 
4374
4388
 
4375
4389
  # Implementing the following Julia function:
@@ -4402,8 +4416,9 @@ def isactionlegal2(s, a):
4402
4416
 
4403
4417
 
4404
4418
  def getnextstate2(s, a, log=False):
4405
- if not isactionlegal2(s, a):
4406
- raise ValueError(f"Action is not legal: {a}")
4419
+ is_legal, reason = isactionlegal2(s, a)
4420
+ if not is_legal:
4421
+ raise ValueError(f"Action is not legal: {a}. Reason: {reason}")
4407
4422
  s = run_state_action_hooks(s, a, AFTER_ACCEPT_ACTION_HOOKS, log)
4408
4423
  s = run_state_action_hooks(s, a, HANDLE_ACTION_HOOKS, log)
4409
4424
  s = run_state_hooks(s, HANDLE_SCORING_HOOKS, log)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: graph_games_proto
3
- Version: 0.3.1831
3
+ Version: 0.3.1865
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=O5XjRfe3DlxbJn4zezDvvy7cXvL4IzIRPZCL3Y-n7s8,776
2
2
  graph_games_proto/all_types.py,sha256=IpbwftEcHS5Ewz-saFNk0lO9FvcbuHG36odRTayCXUk,54911
3
- graph_games_proto/fns.py,sha256=G8b4U3nyB25fGUwnxviCHTInIUwEMUaEdLSXOZ4jI6g,242116
3
+ graph_games_proto/fns.py,sha256=PJUsPdN8ztl9yFVr3c2RC2M0A5gEK9IvdN1RHEauD4A,242723
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.1831.dist-info/METADATA,sha256=Uzq8yQH8ETzIAg_d50hLzfA6WyRcpJ21oTr5QSi9FSg,188
7
- graph_games_proto-0.3.1831.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
- graph_games_proto-0.3.1831.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
- graph_games_proto-0.3.1831.dist-info/RECORD,,
6
+ graph_games_proto-0.3.1865.dist-info/METADATA,sha256=WeOSB_09jBe0pkxkIF2IjrMxECzJnvismkPqD8n7obw,188
7
+ graph_games_proto-0.3.1865.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
8
+ graph_games_proto-0.3.1865.dist-info/top_level.txt,sha256=-4QSrBMf_MM4BGsr2QXBpqDx8c8k_OPnzGyFjqjakes,18
9
+ graph_games_proto-0.3.1865.dist-info/RECORD,,