Skip to content

Commit

Permalink
Merge branch 'main' into currcards
Browse files Browse the repository at this point in the history
  • Loading branch information
dwagon committed Dec 8, 2023
2 parents 63efc5a + 998d434 commit 2b12a39
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
6 changes: 5 additions & 1 deletion dominion/Loot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
""" https://wiki.dominionstrategy.com/index.php/Loot"""
import random
from dominion import Game, Card, CardPile, Keys, Piles
from typing import TYPE_CHECKING
from dominion import Card, CardPile, Keys, Piles

if TYPE_CHECKING:
from dominion import Game


###############################################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
""" https://wiki.dominionstrategy.com/index.php/Sack_of_Loot"""
import unittest
from dominion import Card, Game, Piles, Player
from dominion import Card, Game, Piles, Player, NoCardException


###############################################################################
Expand All @@ -20,7 +20,12 @@ def __init__(self) -> None:
self.buys = 1

def special(self, game: Game.Game, player: Player.Player) -> None:
player.gain_card("Loot")
try:
card = player.gain_card("Loot")
except NoCardException:
player.output("No more Loot")
else:
player.output(f"Gained a {card}")


###############################################################################
Expand Down
85 changes: 85 additions & 0 deletions dominion/loot/Loot_Sextant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python
""" https://wiki.dominionstrategy.com/index.php/Sextant"""
import unittest
from dominion import Loot, Card, Piles, NoCardException, Game, Player


###############################################################################
class Loot_Sextant(Loot.Loot):
"""Sextant"""

def __init__(self) -> None:
Loot.Loot.__init__(self)
self.cardtype = [Card.CardType.LOOT, Card.CardType.TREASURE]
self.base = Card.CardExpansion.PLUNDER
self.desc = """$3; +1 Buy; Look at the top 5 cards of your deck. Discard any number.
Put the rest back in any order."""
self.name = "Sextant"
self.purchasable = False
self.coin = 3
self.buys = 1
self.cost = 7
self.pile = "Loot"

def special(self, game: "Game.Game", player: "Player.Player") -> None:
"""Look at the top 5 cards of your deck. Discard any number. Put the rest back in any order."""
cards: list[Card.Card] = []
for _ in range(5):
try:
card = player.next_card()
except NoCardException:
break
cards.append(card)

if to_discard := player.card_sel(
prompt="Pick cards to discard", anynum=True, cardsrc=cards
):
for card in cards:
if card in to_discard:
player.add_card(card, Piles.DISCARD)
else:
player.add_card(card, Piles.DECK)


###############################################################################
class TestSextant(unittest.TestCase):
"""Test Sextant"""

def setUp(self) -> None:
self.g = Game.TestGame(quiet=True, numplayers=1, traits=["Cursed"])
self.g.start_game()
self.plr = self.g.player_list()[0]
# Remove all other cards from loot pile, so we know what we will draw
mods = 1
while mods > 0:
mods = 0
for loot in self.g.card_piles["Loot"]:
if loot.name != "Sextant":
self.g.card_piles["Loot"].remove(loot.name)
mods += 1

def test_playing(self) -> None:
"""Test playing a doubloon"""
self.plr.piles[Piles.DECK].set(
"Copper", "Silver", "Gold", "Province", "Duchy", "Estate"
)
sextant = self.g.get_card_from_pile("Loot", "Sextant")
self.plr.add_card(sextant, Piles.HAND)
self.plr.test_input = [
"Select Duchy",
"Select Estate",
"Select Province",
"Finish",
]
self.plr.play_card(sextant)
self.assertIn("Province", self.plr.piles[Piles.DISCARD])
self.assertIn("Duchy", self.plr.piles[Piles.DISCARD])
self.assertIn("Silver", self.plr.piles[Piles.DECK])
self.assertIn("Gold", self.plr.piles[Piles.DECK])


###############################################################################
if __name__ == "__main__": # pragma: no cover
unittest.main()

# EOF

0 comments on commit 2b12a39

Please sign in to comment.