feat(Player): str, test_full_game()

parent 11dc9ff8
......@@ -25,6 +25,9 @@ class Player:
self.name: str = name
self.hand: Hand = Hand()
def __str__(self):
return f"Player {self.name}"
def give(self, card: Card):
self.hand.give(card)
......@@ -57,13 +60,13 @@ class Game:
loser = self.new_turn()
if self.defeats[loser] == 5:
print(f"Player {loser} is eliminated!")
print(f"{loser} is eliminated!")
self.players.remove(loser)
else:
print(f"Player {loser} lost the round, now playing with {self.defeats[loser] + 1} cards!")
print(f"{loser} lost the round, now playing with {self.defeats[loser] + 1} cards!")
winner = self.players[0]
print(f"Game over - Player {winner.name} wins with {len(winner.hand)} cards!")
print(f"Game over - {winner.name} wins with {len(winner.hand)} cards!")
def new_turn(self) -> Player:
"""
......@@ -80,13 +83,13 @@ class Game:
current_bet: Optional[Hand] = None
last_player = None
for current_player in itertools.cycle(self.players):
print(f"|Player {current_player.name}'s turn >")
print(f"| {current_player}'s turn >")
if not current_bet: # First player, has to bet something
while not current_bet:
announce = current_player.announce(current_bet)
if announce.bet:
current_bet = announce.bet
print(f"Player {current_player.name} starts the round: {current_bet}")
print(f"{current_player} starts the round: {current_bet}")
else: # Next player, announce or menteur
announce = current_player.announce(current_bet)
if announce.bet:
......@@ -94,12 +97,12 @@ class Game:
print(f"Invalid bet, {announce.bet} < {current_bet}!")
announce = current_player.announce(current_bet)
current_bet = announce.bet
print(f"Player {current_player.name} bets {current_bet}.")
print(f" {current_player} bets {current_bet}.")
else: # Menteur! Who lost the round?
menteur = self.is_menteur(current_bet)
print(f"Player {current_player.name} says Menteur... {'Bravo!' if menteur else 'FAIL!'}")
print(f"{current_player} says Menteur... {'Bravo!' if menteur else 'FAIL!'}")
loser = last_player if menteur else current_player
print(f"Player {loser.name} lost the round!")
print(f"{loser} lost the round!")
self.count_defeat(loser)
return loser
last_player = current_player
......
......@@ -6,8 +6,8 @@ from model.data import Game, Player
class TestGame(TestCase):
def setUp(self) -> None:
super().setUp()
self.player1 = Player(name="")
self.player2 = Player()
self.player1 = Player("PLN")
self.player2 = Player("Nassim")
self.game = Game([self.player1, self.player2])
def test_global_hand(self) -> None:
......@@ -28,3 +28,9 @@ class TestGame(TestCase):
self.assertEqual(1, len(self.game.defeats.values()), "There should have been one defeat.")
self.assertTrue(1 in self.game.defeats.values(), "A player should have one defeat.")
def test_full_game(self):
self.game.new_game()
self.assertGreater(len(self.game.defeats.values()), 0, "There should be at least one player with defeats.")
self.assertTrue(5 in self.game.defeats.values(), "A player should have lost five times.")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment