예제 #1
0
    def test_deal_next_hand_retain_pila(self):
        """Player retains their pila when a new hand is dealt.
        """
        alice = Player("Alice")
        bob = Player("Bob")

        alice_cards = [Card(7, "oro"), Card(8, "oro")]

        player_cards = {}
        player_cards[alice] = {"hand": [], "pila": Pila().add(alice_cards)}
        player_cards[bob] = {"hand": [], "pila": Pila()}

        attributes = {
            "current_player": bob,
            "dealer": alice,
            "deck": Deck(Card),
            "last_pickup": alice,
            "mesa": [],
            "players": [alice, bob],
            "player_cards": player_cards
        }

        ronda = Ronda(**attributes)
        alice_pila = ronda._player_cards[alice]["pila"]
        alice_pila_cards = alice_pila.get_cards()
        self.assertEqual(2, len(alice_pila_cards["oro"]))
        self.assertEqual(0, len(alice_pila_cards["copa"]))
        self.assertEqual(0, len(alice_pila_cards["espada"]))
        self.assertEqual(0, len(alice_pila_cards["basto"]))
예제 #2
0
    def test_enumerate_possibilities_drop_only(self):
        ace = Card(1, "oro")
        tres = Card(3, "oro")
        cinco = Card(5, "oro")

        empty_mesa = enumerate_possibilities([], [ace, cinco, tres])
        self.assertEqual([], empty_mesa)
예제 #3
0
    def test_deal_next_hand_retain_escobas(self):
        """Players keep escobas when starting a new round."""
        alice = Player("Alice")
        bob = Player("Bob")

        alice_cards = [Card(7, "oro"), Card(8, "oro")]

        player_cards = {}
        player_cards[alice] = {
            "hand": [],
            "pila": Pila().add(alice_cards, True)
        }
        player_cards[bob] = {"hand": [], "pila": Pila(escobas=4)}

        attributes = {
            "current_player": bob,
            "dealer": alice,
            "deck": Deck(Card),
            "last_pickup": alice,
            "mesa": [],
            "players": [alice, bob],
            "player_cards": player_cards
        }

        ronda = Ronda(**attributes)
        alice_pila = ronda._player_cards[alice]["pila"]
        alice_escobas = alice_pila.get_escobas()
        self.assertEqual(1, alice_escobas)

        bob_pila = ronda._player_cards[bob]["pila"]
        bob_escobas = bob_pila.get_escobas()
        self.assertEqual(4, bob_escobas)
예제 #4
0
 def test_pick_up_hand(self):
     """Collects a hand of three cards from the deck (ie. at the start of each round)"""
     bob = Player('Bob')
     a = Card(3, 'oro')
     b = Card(4, 'oro')
     c = Card(5, 'oro')
     bob.pick_up_hand([a, b, c])
     self.assertEqual([a, b, c], bob.current_hand())
예제 #5
0
 def test_info(self):
     """Returns a tuple containing suit and number"""
     c = Card(4, 'basto')
     self.assertEqual((4, 'basto'), c.info())
     
     # Check that an error is raised on an invalid number
     with self.assertRaises(ValueError):
         c = Card(13, 'espada')
예제 #6
0
    def test_addEscoba(self):
        pila = Pila()
        self.assertEqual(0, pila.get_escobas())

        card1 = Card(7, 'oro')
        card2 = Card(8, 'copa')
        pila.add([card1, card2], True)

        self.assertEqual(1, pila.get_escobas())
예제 #7
0
    def test_addEscoba(self):
        pila = Pila()
        self.assertEqual(0, pila.escobas)

        card1 = Card(7, "oro")
        card2 = Card(8, "copa")
        pila2 = pila.add([card1, card2], True)

        self.assertEqual(1, pila2.escobas)
예제 #8
0
    def test_info(self):
        """Returns a tuple containing suit and value"""
        c = Card(4, "basto")
        self.assertEqual(4, c.value)
        self.assertEqual("basto", c.suit)

        # Check that an error is raised on an invalid value
        with self.assertRaises(ValueError):
            c = Card(13, "espada")
예제 #9
0
    def test_pick_up_from_mesa(self):
        """Plays one card from their current hand and picks up
        cards from the mesa, adding up to 15, and places them
        in their pila. If last card is taken from the mesa,
        an escoba is counted.
        
        Modifies the player's currenthand, pila, and the mesa.
        """
        alice = Player('Alice')
        bob = Player('Bob')
        card_alice1 = Card(5, 'oro')
        card_alice2 = Card(7, 'basto')
        card_alice3 = Card(8, 'espada')
        card_bob1 = Card(5, 'espada')
        card_bob2 = Card(7, 'copa')
        card_bob3 = Card(8, 'oro')
        card_mesa1 = Card(4, 'copa')
        card_mesa2 = Card(4, 'basto')
        card_mesa3 = Card(10, 'oro')

        alice.pick_up_hand([card_alice1, card_alice2, card_alice3])
        bob.pick_up_hand([card_bob1, card_bob2, card_bob3])
        mesa = [card_mesa1, card_mesa2, card_mesa3]
        
        # Alice uses her 7 to pick up two 4s from the table
        alice.pick_up_from_mesa(mesa, (7, 'basto'), [(4, 'basto'), (4,'copa')])
        self.assertEqual([card_mesa3], mesa)
        self.assertEqual([card_alice1, card_alice3], alice.current_hand())
        
        # Next, bob uses his 5 to pick up the 10 from the table and get an escoba
        bob.pick_up_from_mesa(mesa, (5, 'espada'), [(10, 'oro')])
        self.assertEqual([], mesa)
        self.assertEqual(1, bob.pila().get_escobas())
        self.assertEqual([card_bob2, card_bob3], bob.current_hand())
예제 #10
0
    def test_attributes(self):
        player = "Bob"
        oro = Card(7, "oro")
        basto = Card(7, "basto")
        copa = Card(7, "copa")
        espada = Card(7, "espada")
        winner = SetentaWinner(player, [oro, basto, copa, espada])

        self.assertEqual("Bob", winner.player)
        self.assertEqual(70, winner.points)
        self.assertEqual("Bob has 70.0 setenta pts.", str(winner))
예제 #11
0
 def test_get_move_single_choice(self):
     """Given a hand and a mesa,
     select which cards to play and what to pick up."""
     npc = NPC("name")
     a = Card(5, "oro")
     b = Card(10, "oro")
     hand = [a]
     mesa = [b]
     (from_hand, from_mesa) = npc.get_move(hand, mesa)
     self.assertEqual(a, from_hand)
     self.assertEqual([b], from_mesa)
예제 #12
0
 def test_get_move_no_choice(self):
     """Drop a card if there are no moves available."""
     npc = NPC("name")
     a = Card(1, "oro")
     b = Card(1, "basto")
     c = Card(9, "copa")
     d = Card(8, "espada")
     hand = [a]
     mesa = [b, c, d]
     (from_hand, from_mesa) = npc.get_move(hand, mesa)
     self.assertEqual(a, from_hand)
     self.assertFalse(from_mesa)
예제 #13
0
 def test_holds_card(self):
     """True if the player has the card in their current hand"""
     alice = Player('Alice')
     a = Card(3, 'oro')
     b = Card(4, 'oro')
     c = Card(5, 'espada')
     alice.pick_up_hand([a, b, c])
     
     self.assertTrue(alice.holds_card((3, 'oro')))
     self.assertTrue(alice.holds_card((5, 'espada')))
     self.assertFalse(alice.holds_card((10, 'oro')))
     self.assertFalse(alice.holds_card((4, 'copa')))
예제 #14
0
    def test_get_cards(self):
        """.get_cards() returns a copy of the dictionary"""
        pila = Pila()
        card1 = Card(9, "basto")
        card2 = Card(6, "basto")
        card3 = Card(5, "basto")
        pila2 = pila.add([card1, card2])
        cards = pila2.get_cards()
        # modifying the dictionary doesn't actually affect the pila
        cards["basto"].append(card3)

        pilaCards = pila2.get_cards()
        self.assertEqual(2, len(pilaCards["basto"]))
예제 #15
0
    def test_enumerate_possibilities_single_choice(self):
        cinco = Card(5, "oro")
        siete_velo = Card(7, "oro")
        sota_oro = Card(8, "oro")
        sota_copa = Card(8, "copa")

        siete_sota = enumerate_possibilities([sota_oro,
                                              cinco,
                                              sota_copa],
                                             [siete_velo])

        self.assertTrue((siete_velo, sota_oro) in siete_sota)
        self.assertTrue((siete_velo, sota_copa) in siete_sota)
        self.assertFalse((siete_velo, cinco) in siete_sota)
예제 #16
0
    def test_has_setenta(self):
        """Identifies whether or not the player is able to form a setenta"""
        pila1 = Pila()
        pila2 = Pila()
        basto = Card(4, 'basto')
        oro = Card(7, 'oro')
        espada = Card(10, 'espada')
        copa = Card(1, 'copa')
        
        pila1.add([basto, oro, espada, copa])
        pila2.add([basto, oro, espada])

        self.assertTrue(pila1.has_setenta())
        self.assertFalse(pila2.has_setenta())
예제 #17
0
    def test_play_turn(self):
        random.seed(0)

        alice = Player("Alice")
        bob = Player("Bob")
        ronda = Ronda.start([alice, bob], alice)
        # bob holds: [(6, "basto"), (8, "basto"), (4, "copa")]
        # alice holds: [(1, "oro"), (7, "copa"), (4, "oro")]
        # on table: [(10, "espada"), (9, "espada"), (1, "basto"), (6, "oro")]

        # bob drops a card
        ronda2 = ronda.play_turn(Card(8, "basto"))
        self.assertTrue(Card(8, "basto") in ronda._player_cards[bob]["hand"])
        self.assertTrue(
            Card(8, "basto") not in ronda2._player_cards[bob]["hand"])
예제 #18
0
 def test_place_card_on_mesa(self):
     """Puts down a card on the mesa"""
     alice = Player('Alice')
     card1 = Card(5, 'oro')
     card2 = Card(10, 'basto')
     card3 = Card(8, 'espada')
     alice.pick_up_hand([card1, card2, card3])
     
     mesa = []
     alice.place_card_on_mesa(mesa, (5, 'oro'))
     self.assertEqual(card1, mesa[0])
     self.assertEqual([card2, card3], alice.current_hand())
     
     alice.place_card_on_mesa(mesa, (8, 'espada'))
     self.assertEqual([card1, card3], mesa)
     self.assertEqual([card2], alice.current_hand())
예제 #19
0
 def test_add_does_not_modify(self):
     """Returns a new pila, and does not modify the existing one"""
     pila1 = Pila()
     card1 = Card(3, "basto")
     pila2 = pila1.add([card1])
     self.assertEqual(0, pila1.total_cards())
     self.assertEqual(1, pila2.total_cards())
예제 #20
0
 def test_total_oros(self):
     """Counts the total number of oros collected by the player"""
     pila = Pila()
     self.assertEqual(0, pila.total_oros())
     card1 = Card(9, 'basto')
     card2 = Card(5, 'espada')
     card3 = Card(1, 'oro')
     card4 = Card(10, 'oro')
     card5 = Card(10, 'copa')
     pila.add([card1, card2])
     self.assertEqual(0, pila.total_oros())
     
     pila.add([card3])
     self.assertEqual(1, pila.total_oros())
     
     pila.add([card4, card5])
     self.assertEqual(2, pila.total_oros())
예제 #21
0
    def test_clone(self):
        """Clones a card"""
        c = Card(1, "oro")
        d = c.clone()

        c.value = 3
        self.assertEqual(1, d.value)
        self.assertEqual("oro", d.suit)
예제 #22
0
    def test_total_oros(self):
        """Counts the total number of oros collected by the player"""
        pila = Pila()
        self.assertEqual(0, pila.total_oros())
        card1 = Card(9, "basto")
        card2 = Card(5, "espada")
        card3 = Card(1, "oro")
        card4 = Card(10, "oro")
        card5 = Card(10, "copa")
        pila2 = pila.add([card1, card2])
        self.assertEqual(0, pila2.total_oros())

        pila3 = pila2.add([card3])
        self.assertEqual(1, pila3.total_oros())

        pila4 = pila3.add([card4, card5])
        self.assertEqual(2, pila4.total_oros())
예제 #23
0
    def test_add(self):
        """Add cards to the pila, and retrieve them"""
        pila = Pila()
        card1 = Card(4, 'basto')
        card2 = Card(6, 'basto')
        card3 = Card(6, 'oro')
        card4 = Card(1, 'espada')
        
        pila.add([card1, card2])
        current_cards = pila.get_cards()
        self.assertEqual(2, len(current_cards['basto']))
        self.assertEqual(0, len(current_cards['oro']))
        self.assertEqual(0, len(current_cards['espada']))
        self.assertEqual(0, len(current_cards['copa']))

        pila.add([card3, card4])
        current_cards = pila.get_cards()
        self.assertEqual(2, len(current_cards['basto']))
        self.assertEqual(1, len(current_cards['oro']))
        self.assertEqual(1, len(current_cards['espada']))
        self.assertEqual(0, len(current_cards['copa']))
예제 #24
0
    def test_add(self):
        """Add cards to the pila, and retrieve them"""
        pila = Pila()
        card1 = Card(4, "basto")
        card2 = Card(6, "basto")
        card3 = Card(6, "oro")
        card4 = Card(1, "espada")

        pila2 = pila.add([card1, card2])
        current_cards = pila2.get_cards()
        self.assertEqual(2, len(current_cards["basto"]))
        self.assertEqual(0, len(current_cards["oro"]))
        self.assertEqual(0, len(current_cards["espada"]))
        self.assertEqual(0, len(current_cards["copa"]))

        pila3 = pila2.add([card3, card4])
        current_cards = pila3.get_cards()
        self.assertEqual(2, len(current_cards["basto"]))
        self.assertEqual(1, len(current_cards["oro"]))
        self.assertEqual(1, len(current_cards["espada"]))
        self.assertEqual(0, len(current_cards["copa"]))
예제 #25
0
    def test_best_setenta(self):
        basto4 = Card(4, "basto")
        oro7 = Card(7, "oro")
        espada10 = Card(10, "espada")
        copa1 = Card(1, "copa")
        copa5 = Card(5, "copa")

        # Only one option
        pila1 = Pila()
        pila2 = pila1.add([basto4, oro7, espada10, copa1])
        setenta = [f"{x.value}-{x.suit}" for x in pila2.best_setenta()]
        self.assertTrue("4-basto" in setenta)
        self.assertTrue("7-oro" in setenta)
        self.assertTrue("10-espada" in setenta)
        self.assertTrue("1-copa" in setenta)

        # No setenta possible
        pila = Pila()
        pila2 = pila.add([oro7, espada10, copa1, copa5])
        setenta = pila2.best_setenta()
        self.assertFalse(setenta)
예제 #26
0
    def test_four_suits_required(self):
        pc = SetentaCounter()
        a_hand = [Card(7, "oro"), Card(7, "basto"), Card(7, "espada")]
        b_hand = [Card(2, "oro"), Card(2, "basto"),
                  Card(2, "espada"), Card(2, "copa")]

        pc.compare("alice", a_hand)
        pc.compare("bob", b_hand)
        self.assertTrue("alice" not in [x.player for x in pc.winners])
        self.assertTrue("bob" in [x.player for x in pc.winners])
예제 #27
0
    def test_pick_up_registers_escoba(self):
        """Players earn escobas when picking up."""
        alice = Player("Alice")
        bob = Player("Bob")

        player_cards = {}
        player_cards[alice] = {"hand": [], "pila": Pila()}
        player_cards[bob] = {"hand": [], "pila": Pila()}

        rey = Card(10, "oro")
        attributes = {
            "current_player": bob,
            "dealer": alice,
            "deck": Deck(Card),
            "last_pickup": alice,
            "mesa": [rey],
            "players": [alice, bob],
            "player_cards": player_cards
        }

        ronda = Ronda(**attributes)
        newronda = ronda.play_turn(Card(5, "oro"), [rey])
        escobas = newronda._player_cards[bob]["pila"].escobas
        self.assertEqual(1, escobas)
예제 #28
0
    def test_enumerate_possibilities_multiple_choices(self):
        ace = Card(1, "oro")
        tres = Card(3, "oro")
        cinco = Card(5, "oro")
        seis = Card(6, "espada")
        siete_velo = Card(7, "oro")
        sota_oro = Card(8, "oro")
        caballo = Card(9, "basto")

        complicated_options = enumerate_possibilities([sota_oro,
                                                       tres,
                                                       cinco,
                                                       caballo,
                                                       ace],
                                                      [siete_velo,
                                                       seis])

        self.assertTrue((siete_velo, sota_oro) in complicated_options)
        self.assertTrue((seis, caballo) in complicated_options)
        self.assertTrue((seis, sota_oro, ace) in complicated_options)
        self.assertTrue((seis, tres, cinco, ace) in complicated_options)
예제 #29
0
    def test_has_siete_de_velo(self):
        """Checks whether the 7 de velo is in the pile"""
        pila = Pila()
        card1 = Card(9, "basto")
        card2 = Card(5, "espada")
        card3 = Card(1, "oro")
        card4 = Card(7, "oro")
        card5 = Card(8, "oro")
        card6 = Card(7, "espada")

        pila2 = pila.add([card1, card2, card3])
        self.assertFalse(pila2.has_siete_de_velo())

        pila3 = pila2.add([card4])
        self.assertTrue(pila3.has_siete_de_velo())

        pila4 = pila3.add([card5, card6])
        self.assertTrue(pila4.has_siete_de_velo())
예제 #30
0
    def test_best_setenta2(self):
        basto4 = Card(4, "basto")
        oro7 = Card(7, "oro")
        oro4 = Card(4, "oro")
        espada10 = Card(10, "espada")
        copa1 = Card(1, "copa")
        copa5 = Card(5, "copa")

        pila1 = Pila()
        pila2 = pila1.add([basto4, oro7, espada10, copa5, copa1])
        setenta = [f"{x.value}-{x.suit}" for x in pila2.best_setenta()]
        self.assertTrue("1-copa" in setenta)

        pila1 = Pila()
        pila2 = pila1.add([copa5, basto4, oro4, espada10, oro7, copa1])
        setenta = [f"{x.value}-{x.suit}" for x in pila2.best_setenta()]
        self.assertTrue("1-copa" in setenta)
        self.assertTrue("7-oro" in setenta)