-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't run Python's documentation example #2
Comments
Hello (again)! Ok, this is weird, and if the tests worked it means tests/game/test_game.py#L58 worked, which should test exactly this. It's probably due to weird a behaviour of pybind11? Maybe things changed in the last years? It might be that I will investigate |
So, this came from a very interesting behaviour of pybind11 (most information can be found in #pybind/pybind11/pull/2839), and indeed the work-around is to store all python players in python while they are used in a game. Namely: import random
from ceramic.game import Action, Game, GameHelper, Player
from ceramic.players import RandomPlayer
from ceramic.rules import Rules
from ceramic.state import Tile
class TestPlayer(Player):
def __init__(self):
Player.__init__(self)
def play(self, state):
special_action = Action(1, Tile.from_letter("B"), 3)
if GameHelper.legal(special_action, state):
return special_action
legal_actions = GameHelper.all_legal(state)
return random.choice(legal_actions)
game = Game(Rules.BASE)
test_player = TestPlayer() # <-- here
game.add_player(test_player)
game.add_players([RandomPlayer() for i in range(0, 3)])
game.roll_game() # Plays a random game until the end
print("The winner is:", game.state.winning_player())
print(f"Game state: {game.state}") I will try to implement a better work-around directly in c++ following the comments in the thread, or take the not-yet-merged "smart_holder" branch of pybind11 in the building pipeline (will be easier to do once moved to |
It works, great! |
When trying to run this code:
I get this error:
When calling "roll_round", the code runs but the state is empty, e.g:
tox did work (although I'm using python 3.10). Any ideas about what is happening? Maybe the Python binding is failing?
The text was updated successfully, but these errors were encountered: