Exemplo n.º 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"]))
Exemplo n.º 2
0
    def test_instantiate(self):
        alice = Player("Alice")
        bob = Player("bob")

        deck = Deck(Card)

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

        ronda = Ronda(
            **{
                "current_player": bob,
                "dealer": alice,
                "deck": deck,
                "last_pickup": bob,
                "mesa": [],
                "players": [alice, bob],
                "player_cards": player_cards
            })

        self.assertTrue(isinstance(ronda, Ronda))
Exemplo n.º 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)
Exemplo n.º 4
0
    def test_is_finished(self):
        alice = Player("Alice")
        bob = Player("bob")

        deck = Deck(Card).deal(40)[0]

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

        ronda = Ronda(
            **{
                "current_player": bob,
                "dealer": alice,
                "deck": deck,
                "last_pickup": bob,
                "mesa": [],
                "players": [alice, bob],
                "player_cards": player_cards
            })

        self.assertTrue(ronda.is_finished)
Exemplo n.º 5
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())
Exemplo n.º 6
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)
Exemplo n.º 7
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"]))
Exemplo n.º 8
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())
Exemplo n.º 9
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())
Exemplo n.º 10
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())
Exemplo n.º 11
0
    def test_total_cards(self):
        """Counts the total number of cards the player has picked up."""
        pila = Pila()
        self.assertEqual(0, pila.total_cards())

        card1 = Card(9, "basto")
        card2 = Card(6, "basto")
        card3 = Card(5, "espada")
        card4 = Card(1, "oro")
        card5 = Card(3, "copa")
        card6 = Card(5, "espada")
        pila2 = pila.add([card1, card2])
        self.assertEqual(2, pila2.total_cards())

        pila3 = pila2.add([card3])
        self.assertEqual(3, pila3.total_cards())

        pila4 = pila3.add([card4, card5, card6])
        self.assertEqual(6, pila4.total_cards())
Exemplo n.º 12
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"]))
Exemplo n.º 13
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())
Exemplo n.º 14
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)
Exemplo n.º 15
0
def deal_to_players(players, deck):
    """Perform an initial deal to a list of players.

    Args:
        players -- List of Player
        deck -- Deck object

    Returns:
        Dictionary with players as keys, and "hand" and "pila" keys.
    """
    player_cards = {}
    for player in players:
        (deck, hand) = deck.deal(3)
        player_cards[player] = {"hand": hand, "pila": Pila()}

    return (player_cards, deck)
Exemplo n.º 16
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']))
Exemplo n.º 17
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)
Exemplo n.º 18
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)
Exemplo n.º 19
0
    def test_total_cards(self):
        """Counts the total number of cards the player has picked up.Counts"""
        pila = Pila()
        self.assertEqual(0, pila.total_cards())
        
        card1 = Card(9, 'basto')
        card2 = Card(6, 'basto')
        card3 = Card(5, 'espada')
        card4 = Card(1, 'oro')
        card5 = Card(3, 'copa')
        card6 = Card(5, 'espada')
        pila.add([card1, card2])
        self.assertEqual(2, pila.total_cards())
        
        pila.add([card3])
        self.assertEqual(3, pila.total_cards())

        pila.add([card4, card5, card6])
        self.assertEqual(6, pila.total_cards())
Exemplo n.º 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())
Exemplo n.º 21
0
 def test_has_siete_de_belo(self):
     """Checks whether the 7 de belo 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')
     
     pila.add([card1, card2, card3])
     self.assertFalse(pila.has_siete_de_belo())
     
     pila.add([card4])
     self.assertTrue(pila.has_siete_de_belo())
     
     pila.add([card5, card6])
     self.assertTrue(pila.has_siete_de_belo())
Exemplo n.º 22
0
    def test_count_scores(self):
        alice = Player("Alice")
        bob = Player("Bob")
        charlie = Player("Charlie")

        alice_cards = [
            Card(1, "espada"),
            Card(10, "espada"),
            Card(4, "oro"),
            Card(1, "copa"),
            Card(9, "basto"),
            Card(2, "copa"),
            Card(1, "basto"),
            Card(3, "basto"),
            Card(8, "copa"),
            Card(8, "basto")
        ]
        bob_cards = [
            Card(6, "copa"),
            Card(9, "espada"),
            Card(3, "oro"),
            Card(5, "espada"),
            Card(7, "basto"),
            Card(7, "espada"),
            Card(6, "oro"),
            Card(3, "espada"),
            Card(8, "espada"),
            Card(9, "oro"),
            Card(8, "oro"),
            Card(2, "oro")
        ]
        charlie_cards = [
            Card(10, "basto"),
            Card(5, "basto"),
            Card(4, "basto"),
            Card(9, "copa"),
            Card(7, "copa"),
            Card(5, "oro"),
            Card(1, "oro"),
            Card(2, "basto"),
            Card(4, "copa"),
            Card(10, "copa"),
            Card(5, "copa"),
            Card(4, "espada"),
            Card(3, "copa"),
            Card(6, "espada"),
            Card(2, "espada"),
            Card(7, "oro"),
            Card(6, "basto"),
            Card(10, "oro")
        ]

        ronda = Ronda.start([alice, bob, charlie], alice)
        ronda._player_cards[alice]["pila"] = Pila().add(alice_cards)
        ronda._player_cards[bob]["pila"] = Pila().add(bob_cards, True)
        ronda._player_cards[charlie]["pila"] = Pila().add(charlie_cards)

        scores = ronda.calculate_scores()
        (most_cards, _) = scores["most_cards"]
        self.assertTrue(charlie in most_cards)
        self.assertTrue(alice not in most_cards)
        self.assertTrue(bob not in most_cards)

        (most_oros, _) = scores["most_oros"]
        self.assertTrue(bob in most_oros)
        self.assertTrue(alice not in most_oros)
        self.assertTrue(charlie not in most_oros)

        siete_de_velo = scores["7_de_velo"]
        self.assertTrue(charlie is siete_de_velo)

        setenta = [x.player for x in scores["setenta"]]
        self.assertTrue(charlie in setenta)
        self.assertTrue(bob in setenta)
        self.assertTrue(alice not in setenta)

        escobas = scores["escobas"]
        self.assertTrue((bob, 1) in escobas)
        self.assertEqual(1, len(escobas))