Skip to content

Commit

Permalink
Fixing possession trash
Browse files Browse the repository at this point in the history
  • Loading branch information
jbw3 committed Aug 10, 2024
1 parent 785d40a commit c1d47d4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
10 changes: 9 additions & 1 deletion pyminion/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(
self.take_extra_turn: bool = False
self.take_possession_turn: bool = False
self.possessing_player: Player|None = None
self.possession_trash = Trash()
self.next_turn_draw: int = 5

def __repr__(self):
Expand Down Expand Up @@ -323,7 +324,11 @@ def trash(

for card in source.cards:
if card == target_card:
game.trash.add(source.remove(card))
source.remove(card)
if self.possessing_player is None:
game.trash.add(card)
else:
self.possession_trash.add(card)
logger.info(f"{self} trashes {card}")
game.effect_registry.on_trash(self, card, game)

Expand Down Expand Up @@ -505,6 +510,9 @@ def possess(self, game: "Game") -> None:

opponent.take_turn(game, is_extra_turn=True)

if len(opponent.possession_trash) > 0:
opponent.possession_trash.move_to(opponent.discard_pile)

# reset opponent's state
opponent.decider = original_decider
opponent.possessing_player = None
Expand Down
32 changes: 30 additions & 2 deletions tests/test_cards/test_actions/test_possession.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyminion.expansions.base import copper
from pyminion.expansions.base import chapel, copper, silver
from pyminion.expansions.alchemy import possession
from pyminion.game import Game

Expand All @@ -7,7 +7,7 @@ def test_possession(multiplayer_game: Game, monkeypatch):
responses = [
"possession", # player's turn: play possession
"", # player's turn: no treasures to play
"copper,copper,copper", # possession turn play treasures
"copper,copper,copper", # possession turn: play treasures
"silver", # possession turn: buy silver
]
monkeypatch.setattr("builtins.input", lambda _: responses.pop(0))
Expand All @@ -29,3 +29,31 @@ def test_possession(multiplayer_game: Game, monkeypatch):
assert len(responses) == 0
assert "Silver" in (card.name for card in player.get_all_cards())
assert "Silver" not in (card.name for card in opponent.get_all_cards())


def test_possession_trash(multiplayer_game: Game, monkeypatch):
responses = [
"possession", # player's turn: play possession
"", # player's turn: no treasures to play
"chapel", # possession turn: play chapel
"silver", # possession turn: trash silver
"", # possession turn: do not buy anything
]
monkeypatch.setattr("builtins.input", lambda _: responses.pop(0))

player = multiplayer_game.players[0]
player.hand.cards.clear()
player.hand.add(possession)

opponent = multiplayer_game.players[1]
opponent.hand.cards.clear()
opponent.hand.add(silver)
opponent.hand.add(chapel)

assert "Silver" in (card.name for card in opponent.hand)

multiplayer_game.play_turn(player)

assert len(responses) == 0
assert len(multiplayer_game.trash) == 0
assert "Silver" in (card.name for card in opponent.discard_pile)

0 comments on commit c1d47d4

Please sign in to comment.