Skip to content
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

Idea to Factor Out Common Action Logic #110

Closed
jbw3 opened this issue Mar 21, 2024 · 2 comments
Closed

Idea to Factor Out Common Action Logic #110

jbw3 opened this issue Mar 21, 2024 · 2 comments

Comments

@jbw3
Copy link
Contributor

jbw3 commented Mar 21, 2024

I had an idea to factor out the common play logic for action classes.
Currently, every derived Action class has to copy/paste the following at the beginning of its play() function:

logger.info(f"{player} plays {self}")

if generic_play:
    super().generic_play(player)

I propose factoring this common logic out into the base Action play() method and calling the base function in derived classes:

super().play(player, game, generic_play)

It's possible we could take this a step further and have the base play() method handle the basic +cards, +actions, +money, and +buys:

def play(self, player: "Player", game: "Game", generic_play: bool = True) -> None:
    logger.info(f"{player} plays {self}")

    if generic_play:
        super().generic_play(player)

    if self.draw > 0:
        player.draw(self.draw)
    player.state.actions += self.actions
    player.state.money += self.money
    player.state.buys += self.buys

As a result, vanilla cards like Village, Market, etc. would not need to implement a play() method at all.

What are your thoughts?

@evanofslack
Copy link
Owner

Yup this would be a great addition

@evanofslack
Copy link
Owner

closed by #113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants