Skip to content

Can't run Python's documentation example #2

@RemiFabre

Description

@RemiFabre

When trying to run this code:

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)
game.add_player(TestPlayer())
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 get this error:

    game.roll_game()  # Plays a random game until the end
RuntimeError: Tried to call pure virtual function "Player::play"

When calling "roll_round", the code runs but the state is empty, e.g:

Score: 0
[abcde] [ ]
[eabcd] [  ]
[deabc] [   ]
[cdeab] [    ]
[bcdea] [     ]
Floor: 0 (-0)

tox did work (although I'm using python 3.10). Any ideas about what is happening? Maybe the Python binding is failing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions