Exemple #1
0
 def setup_method(self, method):
     team1 = Team(0, Player("Alex"), Player("Thibaud"))
     team2 = Team(1, Player("Marie"), Player("Veltin"))
     deck = Deck()
     distributor = Distributor()
     referee = Referee()
     self.round = Round(0, team1, team2, deck, distributor,
                        referee, seed=36)
Exemple #2
0
 def setup_method(self, method):
     team1 = Team(0, Player("Alex"), Player("Thibaud"))
     team2 = Team(1, Player("Marie"), Player("Veltin"))
     deck = Deck()
     distributor = Distributor()
     referee = Referee()
     self.game = Round(0, team1, team2, deck, distributor, referee)
     self.output = StringIO()
     self.commentator = RoundCommentator(1, stream=self.output)
Exemple #3
0
 def _handle_newhand(self, data):
     hand_num = int(data[1])
     big_blind = data[2] == 'false'
     self.current_cards = data[3].split(',')
     bankroll = int(data[4])
     opponent_bankroll = int(data[5])
     self.move_history = []
     self.current_pot = Pot(
         **{
             'pip':
             self.current_game.
             big_blind if big_blind else self.current_game.big_blind / 2,
             'bets':
             0,
             'opponent_bets':
             self.current_game.
             big_blind if not big_blind else self.current_game.big_blind /
             2,
             'num_exchanges':
             0,
             'opponent_num_exchanges':
             0
         })
     self.current_round = Round(hand_num, bankroll, opponent_bankroll,
                                big_blind)
     self.bot.handle_new_round(self.current_game, self.current_round)
Exemple #4
0
async def new_round(ctx, member: discord.Member, proposed_time):
    #TODO: except if member is already in vc

    proposed_time = np.datetime64(parse(proposed_time))
    proposed_time_str = proposed_time.item().strftime("%H:%M:%S")

    start_time = np.datetime64(datetime.now())
    start_time_str = start_time.item().strftime("%H:%M:%S")

    if ctx.guild.id in bot.rounds:
        await ctx.send(embed=discord.Embed(
            Title="Error",
            description="Sorry! A round is already in progress.",
            color=0xff0000))
        return
    print("making new round")
    bot.rounds[ctx.guild.id] = Round(member, ctx.channel, start_time,
                                     proposed_time)
    print("made new round")
    embedVar = discord.Embed(
        title="New Round",
        description=f"Member {member.name} is being timed!",
        color=0x0000ff)
    embedVar.add_field(name="Promised time",
                       value=proposed_time_str,
                       inline=False)
    embedVar.add_field(name="Current time", value=start_time_str, inline=False)

    await ctx.send(embed=embedVar)
    return
Exemple #5
0
	def setUp(self):
		match = Match(['Nigeria', 'Russia'])
		self.round = Round(match)
		self.round.add('2-0 Russia', 'Pete')
		self.round.add('0-0', 'Joe')
		self.round.add('2-2', 'Amanda')
		self.round.add('2-2', 'Marcy')
		self.round.add('4-1 Nigeria', 'Anthony')
Exemple #6
0
class TestRound(unittest.TestCase):
	"Tests for round outcomes"

	def setUp(self):
		match = Match(['Nigeria', 'Russia'])
		self.round = Round(match)
		self.round.add('2-0 Russia', 'Pete')
		self.round.add('0-0', 'Joe')
		self.round.add('2-2', 'Amanda')
		self.round.add('2-2', 'Marcy')
		self.round.add('4-1 Nigeria', 'Anthony')

	def test_round_winner_exact(self):
		self.round.close('0-2 Nigeria')
		self.assertEqual(len(self.round.winners), 1)
		self.assertEqual(self.round.winners, {'Pete': 2})

	def test_round_winner_exact_multiple(self):
		self.round.close('2-2')
		self.assertEqual(len(self.round.winners), 2)
		self.assertEqual(self.round.winners, {'Amanda': 2, 'Marcy': 2})

	def test_round_winner_closest(self):
		self.round.close('7-1 Nigeria')
		self.assertEqual(len(self.round.winners), 1)
		self.assertEqual(self.round.winners, {'Anthony': 1})

	def test_round_winner_closest_multiple(self):
		self.round.close('0-1 Nigeria')
		self.assertEqual(len(self.round.winners), 2)
		self.assertEqual(self.round.winners, {'Pete': 1, 'Joe': 1})

	def test_round_winner_closest_triple(self):
		self.round.close('2-1 Russia')
		self.assertEqual(len(self.round.winners), 3)
		self.assertEqual(self.round.winners, {'Pete': 1, 'Amanda': 1, 'Marcy': 1})
Exemple #7
0
class TestGameCommentator:
    def setup_method(self, method):
        team1 = Team(0, Player("Alex"), Player("Thibaud"))
        team2 = Team(1, Player("Marie"), Player("Veltin"))
        deck = Deck()
        distributor = Distributor()
        referee = Referee()
        self.game = Round(0, team1, team2, deck, distributor, referee)
        self.output = StringIO()
        self.commentator = RoundCommentator(1, stream=self.output)

    def test_commentator_should_introduce_game(self):
        self.commentator.comment_start_of_round(self.game)
        assert self.output.getvalue().strip() == """Game 0"""

    def test_commentator_should_announce_cards(self):
        regex = re.compile(r"([\w]+ plays [\w]+ of [\w]+(, )*){4}.")
        self.game.distribute_cards_and_choose_trump()
        trick = self.game.play_one_turn()
        self.commentator.comment_turn(self.game, trick)
        comment = self.output.getvalue().strip()
        assert regex.match(comment) is not None

    def test_commentator_should_comment_end_of_turn(self):
        regex = re.compile(r"[\w]+ wins.")
        self.game.distribute_cards_and_choose_trump()
        self.game.play_one_turn()
        self.commentator.comment_end_of_turn(self.game)
        comment = self.output.getvalue().strip()
        assert regex.match(comment) is not None

    def test_commentator_should_comment_end_of_game(self):
        regex = re.compile(r"(Team \w+: \d{1,3} points.\n){2}Team \w+ wins!")
        self.game.distribute_cards_and_choose_trump()
        self.game.play()
        self.game.count_points()
        self.commentator.comment_end_of_round(self.game)
        comment = self.output.getvalue().strip()
        assert regex.match(comment) is not None

    def test_commentator_should_comment_distribution(self):
        regex = re.compile(r"Trump suit will be (Clubs|Hearts|Diamonds|Spades).")
        self.game.distribute_cards_and_choose_trump()
        self.commentator.comment_distribution(self.game)
        comment = self.output.getvalue().strip()
        assert regex.match(comment) is not None
Exemple #8
0
class TestRound:
    def setup_method(self, method):
        team1 = Team(0, Player("Alex"), Player("Thibaud"))
        team2 = Team(1, Player("Marie"), Player("Veltin"))
        deck = Deck()
        distributor = Distributor()
        referee = Referee()
        self.round = Round(0, team1, team2, deck, distributor,
                           referee, seed=36)

    def test_players_should_have_no_hand_at_beginning(self):
        for player in self.round.players:
            assert len(player.hand) == 0

    def test_players_should_have_8_cards_after_distribution(self):
        self.round.distribute_cards_and_choose_trump()
        for player in self.round.players:
            assert len(player.hand) == 8

    def test_all_cards_should_be_ranked_after_distribution(self):
        self.round.distribute_cards_and_choose_trump()
        for player in self.round.players:
            for card in player.hand:
                assert isinstance(card, RankedCard)

    def test_first_distribution_should_reveal_card(self):
        revealed_card = self.round.perform_first_distribution_and_reveal_card()
        assert isinstance(revealed_card, Card)

    def test_players_should_have_5_cards_in_hand_after_first_distribution(self):
        _ = self.round.perform_first_distribution_and_reveal_card()
        for player in self.round.players:
            assert len(player.hand) == 5

    def test_deck_should_be_empty_after_distribution(self):
        self.round.distribute_cards_and_choose_trump()
        assert len(self.round.deck) == 0

    def test_players_should_have_8_minus_n_cards_in_hand_after_n_turns(self):
        self.round.distribute_cards_and_choose_trump()
        for i in range(8):
            self.round.play_one_turn()
            for player in self.round.players:
                assert len(player.hand) == 8 - (i + 1)

    def test_teams_should_have_32_cards_total_after_game_has_been_played(self):
        self.round.distribute_cards_and_choose_trump()
        print(self.round.get_team_by_id(0).player1.hand[0].owner)
        self.round.play()
        assert len(self.round.get_team_by_id(0).won_cards) + len(self.round.get_team_by_id(1).won_cards) == 32

    def test_total_points_at_the_end_should_be_162(self):
        self.round.distribute_cards_and_choose_trump()
        self.round.play()
        self.round.count_points()
        assert sum([team.current_game_points for team in self.round.teams]) == 162

    def test_play_should_not_fail(self):
        self.round.distribute_cards_and_choose_trump()
        assert self.round.play() == 0