Exemple #1
0
    def test_over__emptyProvincePile(self):
        game = Game()
        game.addPlayer(Player(name="Player 1"))
        game.addPlayer(Player(name="Player 2"))
        game.setUpGame()

        game.SupplyArea.ProvincePile = Pile()
        self.assertTrue(game.over())
Exemple #2
0
    def test_over__threeEmptyPiles(self):
        game = Game()
        game.addPlayer(Player(name="Player 1"))
        game.addPlayer(Player(name="Player 2"))
        game.setUpGame()

        game.SupplyArea.DuchyPile = Pile()
        for i in range(2):
            game.SupplyArea.KingdomPiles[i] = Pile()
        self.assertTrue(game.over())
Exemple #3
0
    def test__setUpInitialDecks(self):
        game = Game()
        game.addPlayer(Player(name="Player 1"))
        game.addPlayer(Player(name="Player 2"))
        game.SupplyArea.EstatePile = game._makePile(dominion_data.cards['estate'], 20)
        game.SupplyArea.CopperPile = game._makePile(dominion_data.cards['copper'], 20)

        game._setUpInitialDecks()
        for player in game.Players:
            self.assertEqual(player.DrawPile.len(), 10)
        self.assertEqual(game.SupplyArea.EstatePile.len(), (20 - (dominion_rules.FIRST_DECK.ESTATE_CARDS * 2)))
        self.assertEqual(game.SupplyArea.CopperPile.len(), (20 - (dominion_rules.FIRST_DECK.COPPER_CARDS * 2)))
Exemple #4
0
    def test__drawFirstHands(self):
        game = Game()
        game.addPlayer(Player(name="Player 1"))
        game.addPlayer(Player(name="Player 2"))
        estatePile = game._makePile(dominion_data.cards['estate'], dominion_rules.FIRST_DECK.ESTATE_CARDS)
        copperPile = game._makePile(dominion_data.cards['copper'], dominion_rules.FIRST_DECK.COPPER_CARDS)
        for player in game.Players:
            firstDeck = game._combinePiles([estatePile, copperPile])
            player.DrawPile = firstDeck

        game._drawFirstHands()
        for player in game.Players:
            self.assertEqual(player.DrawPile.len(), 5)
            self.assertEqual(player.Hand.len(), 5)
Exemple #5
0
 def test_addPlayer(self):
     game = Game()
     game.addPlayer(Player(name="Test Player"))
     self.assertEqual(len(game.Players), 1)
     self.assertEqual(game.Players[0].Name, "Test Player")
Exemple #6
0
 def test_over__notOver(self):
     game = Game()
     game.addPlayer(Player(name="Player 1"))
     game.addPlayer(Player(name="Player 2"))
     game.setUpGame()
     self.assertFalse(game.over())
    def main(self):
        game = Game()

        playerOne = Player(name="Player One")
        playerTwo = Player(name="Player Two")
        game.addPlayer(playerOne)
        game.addPlayer(playerTwo)

        game.setUpGame()

        print "DEBUG: The game looks like this: %s" % game.__dict__
        print "DEBUG: The SupplyArea looks like this:"
        print "Copper (%s)" % game.SupplyArea.CopperPile.len()
        print "Silver (%s)" % game.SupplyArea.SilverPile.len()
        print "Gold (%s)" % game.SupplyArea.GoldPile.len()
        print "Estate (%s)" % game.SupplyArea.EstatePile.len()
        print "Duchy (%s)" % game.SupplyArea.DuchyPile.len()
        print "Province (%s)" % game.SupplyArea.ProvincePile.len()
        print "Curse (%s)" % game.SupplyArea.CursePile.len()
        for pileName, pile in game.SupplyArea.KingdomPiles.iteritems():
            print "%s (%s)" % (pileName, pile.len())
        print "DEBUG: Here are the players' draw piles:"
        for player in game.Players:
            print "%s:" % player.Name
            print "DECK:"
            for card in player.DrawPile.Cards:
                print card.Name
            print "HAND:"
            for card in player.Hand.Cards:
                print card.Name

        while not game.over():
            for player in game.Players:
                currentTurn = Turn()

                # Count the number of coins
                for card in player.Hand.Cards:
                    currentTurn.Coins += card.Effects.get('coins', 0)

                print "-- %s --" % player.Name
                while currentTurn.ActionsLeft > 0 or currentTurn.BuysLeft > 0:
                    # Choose a card to play
                    cardNumber = None
                    while cardNumber is None:
                        # Display the player's hand and options
                        print "You have %s actions, %s buys, and %s coins" % (currentTurn.ActionsLeft, currentTurn.BuysLeft, currentTurn.Coins)
                        print "Your hand is"
                        for i in range(player.Hand.len()):
                            print "%s: %s" % (i, player.Hand.Cards[i].Name)

                        # Get user input for the card to play
                        try:
                            cardNumber = input("Choose a card to play (enter the number), or 100 to buy, or 99 to end: ")
                        except (IndexError, NameError) as e:
                            print "That isn't an available option.  Try again."
                            cardNumber = None


                    # Player is ending the turn ...
                    if cardNumber == 99:
                        break

                    # Player is buying a card ...
                    elif cardNumber == 100:
                        # Make sure the player has enough buys
                        if currentTurn.BuysLeft == 0:
                            print "You don't have another buy"
                        else:
                            # Get player input for the card to buy
                            buyCardName = None
                            while buyCardName is None:
                                try:
                                    print "The available cards are"
                                    for cardName, pile in game.SupplyArea.allPiles().iteritems():
                                        print "%s (%s coins) (%s left)" % (cardName, pile.Cards[0].Cost, pile.len())
                                    buyCardName = raw_input("Enter the name of the card you wish to buy: ")
                                    buyCard = game.SupplyArea.allPiles()[buyCardName].Cards[0]
                                except (NameError, KeyError) as e:
                                    print "That isn't an option.  Try again"
                                    buyCardName = None

                            buyCardCost = game.SupplyArea.allPiles()[buyCardName].Cards[0].Cost
                            # Make sure the player has enough coins
                            if buyCardCost > currentTurn.Coins:
                                print "You don't have enough coins to buy that card"
                            else:
                                # Buy the card
                                currentTurn.Coins -= buyCardCost
                                currentTurn.BuysLeft -= 1
                                player.DiscardPile.drop(game.SupplyArea.allPiles()[buyCardName].draw())


                    # Player is playing a card from the hand ...
                    elif cardNumber < 100:
                        try:
                            card = player.Hand.Cards[int(cardNumber)]
                            if card.Type.startswith("Action"):
                                # Make sure the player has enough actions
                                if currentTurn.ActionsLeft == 0:
                                    print "You don't have any actions left"
                                else:
                                    currentTurn = self._applyCardEffects(card, currentTurn, player, game)
                            else:
                                currentTurn = self._applyCardEffects(card, currentTurn, player, game)

                            player.discard(card)
                        except IndexError, e:
                            print "That isn't an option.  Try again"

                print "Your turn is over"
                print ""
                player.discardHand()
                player.drawHand()