Skip to content

Commit

Permalink
Don't use get_card_from_pile() when you mean card_instances
Browse files Browse the repository at this point in the history
  • Loading branch information
dwagon committed Oct 29, 2023
1 parent ca94375 commit 204bfe7
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 69 deletions.
16 changes: 8 additions & 8 deletions dominion/cards/Card_Captain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

import unittest
from dominion import Game, Card, Piles
from dominion import Game, Card, Piles, Player


###############################################################################
Expand All @@ -20,16 +20,16 @@ def __init__(self):
self.name = "Captain"
self.cost = 6

def special(self, game, player):
def special(self, game: "Game.Game", player: "Player.Player") -> None:
self.special_sauce(game, player)

def duration(self, game, player):
def duration(self, game: "Game.Game", player: "Player.Player") -> None:
self.special_sauce(game, player)

def special_sauce(self, game, player):
def special_sauce(self, game: "Game.Game", player: "Player.Player") -> None:
options = [("None", None)]
for name in game.get_action_piles(4):
card = game.get_card_from_pile(name)
card = game.card_instances[name]
if card.isDuration():
continue
if card.isCommand():
Expand All @@ -45,7 +45,7 @@ def special_sauce(self, game, player):

###############################################################################
class TestCaptain(unittest.TestCase):
def setUp(self):
def setUp(self) -> None:
self.g = Game.TestGame(
numplayers=1, initcards=["Captain", "Workshop", "Bureaucrat"]
)
Expand All @@ -54,13 +54,13 @@ def setUp(self):
self.card = self.g.get_card_from_pile("Captain")
self.plr.add_card(self.card, Piles.HAND)

def test_play_bureaucrat(self):
def test_play_bureaucrat(self) -> None:
"""Make the Captain be a Bureaucrat"""
self.plr.test_input = ["Bureaucrat"]
self.plr.play_card(self.card)
self.assertIn("Silver", self.plr.piles[Piles.DECK])

def test_play_market(self):
def test_play_market(self) -> None:
"""Make the Captain be a Workshop"""
self.plr.test_input = ["Play Workshop", "Get Bureaucrat"]
self.plr.play_card(self.card)
Expand Down
16 changes: 8 additions & 8 deletions dominion/cards/Card_Exorcist.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python

import unittest
from dominion import Game, Card, Piles
import dominion.Card as Card
from dominion.Player import Phase
from typing import Any

from dominion import Game, Card, Piles, Phase, Player


###############################################################################
Expand All @@ -21,18 +21,18 @@ def __init__(self):
("Card", "Will-o'-Wisp"),
]

def night(self, game, player):
def night(self, game: "Game.Game", player: "Player.Player") -> None:
if player.piles[Piles.HAND].is_empty():
player.output("No cards to trash")
return
trashed = player.plr_trash_card(prompt="Trash a card and gain a cheaper spirit")
if not trashed:
return
cost = trashed[0].cost
options = []
options: list[dict[str, Any]] = []
idx = 0
for card_name in ("Ghost", "Imp", "Will-o'-Wisp"):
card = game.get_card_from_pile(card_name)
card = game.card_instances[card_name]
if card.cost < cost:
options.append(
{
Expand All @@ -51,13 +51,13 @@ def night(self, game, player):

###############################################################################
class TestExorcist(unittest.TestCase):
def setUp(self):
def setUp(self) -> None:
self.g = Game.TestGame(numplayers=1, initcards=["Exorcist"])
self.g.start_game()
self.plr = self.g.player_list()[0]
self.card = self.g.get_card_from_pile("Exorcist")

def test_play(self):
def test_play(self) -> None:
self.plr.phase = Phase.NIGHT
self.plr.piles[Piles.HAND].set("Silver", "Gold", "Province")
self.plr.test_input = ["Silver", "Imp"]
Expand Down
16 changes: 8 additions & 8 deletions dominion/cards/Card_Lurker.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python

import unittest
from dominion import Game, Card, Piles
import dominion.Card as Card
from dominion import Game, Card, Piles, Player


###############################################################################
Expand All @@ -11,12 +10,13 @@ def __init__(self):
Card.Card.__init__(self)
self.cardtype = Card.CardType.ACTION
self.base = Card.CardExpansion.INTRIGUE
self.desc = "+1 Action; Choose one: Trash an Action card from the Supply, or gain an Action card from the trash."
self.desc = """+1 Action; Choose one: Trash an Action card from the Supply,
or gain an Action card from the trash."""
self.name = "Lurker"
self.cost = 2
self.actions = 1

def special(self, game, player):
def special(self, game: "Game.Game", player: "Player.Player") -> None:
ch = player.plr_choose_options(
"Choose one? ",
("Trash an Action from the Supply", "to"),
Expand All @@ -27,7 +27,7 @@ def special(self, game, player):
if ch == "from":
self._from_trash(game, player)

def _trash_supply(self, game, player):
def _trash_supply(self, game: "Game.Game", player: "Player.Player") -> None:
"""Trash an action from supply"""
options = []
for name, pile in game.get_card_piles():
Expand All @@ -44,18 +44,18 @@ def _trash_supply(self, game, player):
"Select Action from Supply to Trash", *options
)
card = game.get_card_from_pile(to_trash)
player.add_card(card, "played") # In order to trash
player.add_card(card, Piles.PLAYED) # In order to trash
player.trash_card(card)

def _from_trash(self, game, player):
def _from_trash(self, game: "Game.Game", player: "Player.Player") -> None:
"""Gain an action from the trash"""
acts = [_ for _ in game.trash_pile if _.isAction()]
if not acts:
player.output("No suitable cards found")
return
card = player.card_sel(cardsrc=acts, prompt="Select Action from the Trash")
game.trash_pile.remove(card[0])
player.add_card(card[0], "discard")
player.add_card(card[0], Piles.DISCARD)


###############################################################################
Expand Down
20 changes: 12 additions & 8 deletions dominion/cards/Card_Mine.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env python

import unittest
from dominion import Card, Game, Piles
from typing import Any

from dominion import Card, Game, Piles, Player


###############################################################################
Expand All @@ -14,9 +16,11 @@ def __init__(self):
self.name = "Mine"
self.cost = 5

def _generate_options(self, player):
def _generate_options(self, player: "Player.Player") -> list[dict[str, Any]]:
"""Generate the options for player dialog"""
options = [{"selector": "0", "print": "Don't trash a card", "card": None}]
options: list[dict[str, Any]] = [
{"selector": "0", "print": "Don't trash a card", "card": None}
]
index = 1
for card in player.piles[Piles.HAND]:
if card.isTreasure():
Expand All @@ -30,7 +34,7 @@ def _generate_options(self, player):
index += 1
return options

def special(self, game, player):
def special(self, game: "Game.Game", player: "Player.Player") -> None:
"""Trash a treasure card from your hand. Gain a treasure card
costing up to 3 more, put it in your hand"""
options = self._generate_options(player)
Expand All @@ -41,7 +45,7 @@ def special(self, game, player):
# Make an assumption and pick the best treasure card
# TODO - let user pick
for card_name, _ in game.get_card_piles():
card = game.get_card_from_pile(card_name)
card = game.card_instances[card_name]
if not card:
continue
if not card.isTreasure():
Expand All @@ -60,13 +64,13 @@ def special(self, game, player):

###############################################################################
class TestMine(unittest.TestCase):
def setUp(self):
def setUp(self) -> None:
self.g = Game.TestGame(numplayers=1, initcards=["Mine"])
self.g.start_game()
self.plr = self.g.player_list()[0]
self.card = self.g.get_card_from_pile("Mine")

def test_convert_copper(self):
def test_convert_copper(self) -> None:
self.plr.piles[Piles.HAND].set("Copper")
self.plr.add_card(self.card, Piles.HAND)
self.plr.test_input = ["1"]
Expand All @@ -78,7 +82,7 @@ def test_convert_copper(self):
self.assertEqual(self.plr.buys.get(), 1)
self.assertEqual(self.plr.actions.get(), 0)

def test_convert_nothing(self):
def test_convert_nothing(self) -> None:
self.plr.piles[Piles.HAND].set("Copper")
self.plr.add_card(self.card, Piles.HAND)
self.plr.test_input = ["0"]
Expand Down
12 changes: 6 additions & 6 deletions dominion/cards/Odyssey_Sunken_Treasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
""" http://wiki.dominionstrategy.com/index.php/Sunken_Treasure"""

import unittest
from dominion import Game, Card, Piles
from dominion import Game, Card, Piles, Player


###############################################################################
class Card_Sunken_Treasure(Card.Card):
"""Sunken Treasure"""

def __init__(self):
def __init__(self) -> None:
Card.Card.__init__(self)
self.cardtype = [Card.CardType.TREASURE, Card.CardType.ODYSSEY]
self.base = Card.CardExpansion.ALLIES
Expand All @@ -18,10 +18,10 @@ def __init__(self):
self.desc = """Gain an Action card you don't have a copy of in play."""
self.pile = "Odysseys"

def special(self, game, player):
def special(self, game: "Game.Game", player: "Player.Player") -> None:
options = []
for name, pile in game.get_card_piles():
card = game.get_card_from_pile(name)
card = game.card_instances[name]
if card and not card.isAction():
continue
if name in player.piles[Piles.PLAYED]:
Expand All @@ -35,13 +35,13 @@ def special(self, game, player):
class TestSunkenTreasure(unittest.TestCase):
"""Test Sunken Treasure"""

def setUp(self):
def setUp(self) -> None:
self.g = Game.TestGame(numplayers=1, initcards=["Odysseys", "Moat", "Militia"])
self.g.start_game()
self.plr = self.g.player_list()[0]
self.card = self.g.get_card_from_pile("Odysseys", "Sunken Treasure")

def test_play(self):
def test_play(self) -> None:
"""Play the card"""
self.plr.piles[Piles.PLAYED].set("Moat", "Copper")
self.plr.add_card(self.card, Piles.HAND)
Expand Down
16 changes: 8 additions & 8 deletions dominion/cards/Wizard_Sorcerer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
""" https://wiki.dominionstrategy.com/index.php/Sorcerer"""
import unittest
from dominion import Game, Card, Piles
from dominion import Game, Card, Piles, Player


###############################################################################
Expand All @@ -25,16 +25,16 @@ def __init__(self):
self.desc = """+1 Card; +1 Action; Each other player names a card,
then reveals the top card of their deck. If wrong, they gain a Curse."""

def _generate_options(self, game):
def _generate_options(self, game: "Game.Game") -> list[tuple[str, str]]:
"""Generate the options for user interaction"""
options = []
options: list[tuple[str, str]] = []
for name, card_pile in game.get_card_piles():
card = game.get_card_from_pile(name)
card = game.card_instances[name]
if card and card.purchasable:
options.append((name, name))
return options

def special(self, game, player):
def special(self, game: "Game.Game", player: "Player.Player") -> None:
for plr in player.attack_victims():
options = self._generate_options(game)
pick = plr.plr_choose_options(
Expand All @@ -59,12 +59,12 @@ def botresponse(player, kind, args=None, kwargs=None): # pragma: no cover
class TestSorcerer(unittest.TestCase):
"""Test Sorcerer"""

def setUp(self):
def setUp(self) -> None:
self.g = Game.TestGame(numplayers=2, initcards=["Wizards"])
self.g.start_game()
self.plr, self.vic = self.g.player_list()

def test_play_hit(self):
def test_play_hit(self) -> None:
card = self.g.get_card_from_pile("Wizards", "Sorcerer")
self.plr.add_card(card, Piles.HAND)
hndsz = self.plr.piles[Piles.HAND].size()
Expand All @@ -75,7 +75,7 @@ def test_play_hit(self):
self.assertEqual(self.plr.actions.get(), 1)
self.assertNotIn("Curse", self.vic.piles[Piles.DISCARD])

def test_play_miss(self):
def test_play_miss(self) -> None:
while True:
card = self.g.get_card_from_pile("Wizards")
if card.name == "Sorcerer":
Expand Down
12 changes: 6 additions & 6 deletions dominion/events/Event_Populate.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/usr/bin/env python

import unittest
from dominion import Card, Game, Piles, Event
from dominion import Card, Game, Piles, Event, Player


###############################################################################
class Event_Populate(Event.Event):
def __init__(self):
def __init__(self) -> None:
Event.Event.__init__(self)
self.base = Card.CardExpansion.MENAGERIE
self.desc = "Gain one card from each Action Supply pile."
self.name = "Populate"
self.cost = 10

def special(self, game, player):
def special(self, game: "Game.Game", player: "Player.Player") -> None:
for card_name, card_pile in game.get_card_piles():
card = game.get_card_from_pile(card_name)
card = game.card_instances[card_name]
if not card:
continue
if card.isAction() and card.insupply:
Expand All @@ -25,7 +25,7 @@ def special(self, game, player):

###############################################################################
class TestPopulate(unittest.TestCase):
def setUp(self):
def setUp(self) -> None:
self.g = Game.TestGame(
numplayers=1,
events=["Populate"],
Expand All @@ -47,7 +47,7 @@ def setUp(self):
self.plr = self.g.player_list()[0]
self.card = self.g.events["Populate"]

def test_Populate(self):
def test_Populate(self) -> None:
"""Use Populate"""
self.plr.coins.add(10)
self.plr.perform_event(self.card)
Expand Down

0 comments on commit 204bfe7

Please sign in to comment.