Пример #1
0
    def test_colorwin(self):
        self.s.cards_in_play.append(ColoredCard(5, 'green'))
        self.s.cards_in_play.append(ColoredCard(6, 'green'))
        self.s.cards_in_play.append(ColoredCard(10, 'green'))
        self.s.cards_in_play.append(ColoredCard(13, 'green'))

        self.assertEqual(self.s.check_stich_winner(), self.s.player_q[3])
Пример #2
0
    def test_wizzard_win(self):
        self.s.cards_in_play.append(SpecialCard("z"))
        self.s.cards_in_play.append(ColoredCard(6, 'green'))
        self.s.cards_in_play.append(ColoredCard(10, 'green'))
        self.s.cards_in_play.append(ColoredCard(13, 'green'))

        self.assertEqual(self.s.check_stich_winner(), self.s.player_q[0])
Пример #3
0
    def test_single_atutwin(self):
        self.s.cards_in_play.append(ColoredCard(5, 'green'))
        self.s.cards_in_play.append(ColoredCard(6, 'green'))
        self.s.cards_in_play.append(ColoredCard(10, 'green'))
        self.s.cards_in_play.append(ColoredCard(5, 'red'))

        self.assertEqual(self.s.check_stich_winner(), self.s.player_q[2])
Пример #4
0
    def test_dominant_color_win(self):
        self.s.cards_in_play.append(ColoredCard(12, 'green'))
        self.s.cards_in_play.append(ColoredCard(10, 'green'))
        self.s.cards_in_play.append(ColoredCard(13, 'yellow'))
        self.s.cards_in_play.append(ColoredCard(9, 'blue'))

        self.assertEqual(self.s.check_stich_winner(), self.s.player_q[0])
Пример #5
0
    def test_multiple_atut_win(self):
        self.s.cards_in_play.append(ColoredCard(6, 'red'))
        self.s.cards_in_play.append(ColoredCard(10, 'red'))
        self.s.cards_in_play.append(ColoredCard(13, 'red'))
        self.s.cards_in_play.append(SpecialCard('n'))

        self.assertEqual(self.s.check_stich_winner(), self.s.player_q[2])
    def test_winner_new_stich(self):
        self.g.new_round()
        s = Stich(self.g.player_queue, ColoredCard(0, "yellow"))
        s.winner = self.g.players[3]
        self.g.get_current_round().stiche.append(s)

        self.assertEqual(self.g.set_stich_queue(2)[0], self.g.players[3])
    def test_farbzwang(self):
        self.s = Stich(self.g.player_queue, ColoredCard(0, "blue"))

        hand_p0 = [SpecialCard("z"), ColoredCard(5, "red")]
        hand_p1 = [ColoredCard(13, "red"), ColoredCard(11, "red")]
        hand_p2 = [ColoredCard(6, "red"), ColoredCard(1, "yellow")]
        hand_p3 = [ColoredCard(12, "red"), SpecialCard("z")]
        cards_in_play = [
            ColoredCard(1, "red"),
            ColoredCard(2, "yellow"),
            ColoredCard(3, "yellow")
        ]

        self.g.players[0].hand.extend(hand_p0)
        self.g.players[1].hand.extend(hand_p1)
        self.g.players[2].hand.extend(hand_p2)
        self.g.players[3].hand.extend(hand_p3)
        self.s.cards_in_play.extend(cards_in_play)

        self.assertFalse(
            self.s.check_if_playable(self.g.players[2].hand[1],
                                     self.g.players[2]))
Пример #8
0
    def test_score_round_3(self):
        round = Round(3)
        stich1 = Stich(self.g.player_queue, ColoredCard(0, 'red'))
        stich2 = Stich(self.g.player_queue, ColoredCard(0, 'red'))
        stich3 = Stich(self.g.player_queue, ColoredCard(0, 'red'))
        round.stiche.append(stich1)
        round.stiche.append(stich2)
        round.stiche.append(stich3)
        stich1.winner = self.g.players[0]
        stich2.winner = self.g.players[1]
        stich3.winner = self.g.players[0]
        prediction = {
            self.players[0]: 2,
            self.players[1]: 3,
            self.players[2]: 0,
            self.players[3]: 1
        }
        round.predictions = prediction

        round.calculate_score(self.g.players)
        self.assertEqual(self.g.players[0].score, 40)
        self.assertEqual(self.g.players[1].score, -20)
        self.assertEqual(self.g.players[2].score, 20)
        self.assertEqual(self.g.players[3].score, -10)
Пример #9
0
    def set_atut_manually(self, player_q):
        from game.game_board import GameBoard
        print('Player', player_q[-1].number, 'chooses atut now!')
        if GameBoard.display_mode:
            chosen_card = ask_for_card([
                ColoredCard(0, 'red'),
                ColoredCard(0, 'green'),
                ColoredCard(0, 'blue'),
                ColoredCard(0, 'yellow')
            ])

            self.atut = chosen_card
        else:
            self.atut = ColoredCard(0, 'red')
    def test_not_play_narr(self):
        self.s = Stich(self.g.player_queue, ColoredCard(7, "blue"))

        hand_p0 = [
            ColoredCard(3, "red"),
            ColoredCard(8, "green"),
            ColoredCard(9, "red"),
            ColoredCard(11, "yellow")
        ]
        hand_p1 = [
            ColoredCard(6, "blue"),
            ColoredCard(10, "blue"),
            ColoredCard(4, "red"),
            ColoredCard(11, "red")
        ]
        hand_p2 = [
            ColoredCard(13, "red"),
            ColoredCard(2, "red"),
            ColoredCard(8, "yellow")
        ]
        hand_p3 = [
            SpecialCard("n"),
            ColoredCard(6, "green"),
            ColoredCard(2, "green"),
            ColoredCard(4, "green"),
            SpecialCard("n")
        ]
        cards_in_play = [
            ColoredCard(12, "yellow"),
            ColoredCard(3, "blue"),
            SpecialCard("z")
        ]

        self.g.players[0].hand.extend(hand_p0)
        self.g.players[1].hand.extend(hand_p1)
        self.g.players[2].hand.extend(hand_p2)
        self.g.players[3].hand.extend(hand_p3)
        self.s.cards_in_play.extend(cards_in_play)

        self.assertTrue(
            self.s.check_if_playable(self.g.players[3].hand[3],
                                     self.g.players[3]))
Пример #11
0
class Round:
    def __init__(self, actual_round: int):
        self.round_nr = actual_round
        self.atut = ColoredCard
        self.cards_in_play = list()
        self.predictions = dict()
        self.stiche = list()
        self.stiche_won = defaultdict(int)
        self.score_result = dict()

    def input_prediction(self, player: Player) -> int:
        print('Player No.:', player.number, 'how many "Stiche" will you win?')
        print('Cards currently in your hand: ')
        for i in player.hand:
            if isinstance(i, Card):
                i.print_card()
        print()
        while True:
            try:
                input_value = int(input())
                if self.round_nr >= input_value >= 0:
                    return input_value
                else:
                    raise ValueError
            except ValueError:
                print(
                    'Please input a whole Number! How many "Stiche" will you win?'
                )

    def predict(self, player: Player, prediction=None):
        if prediction is None:
            prediction_value = self.input_prediction(player)
        else:
            prediction_value = int(prediction)
        if prediction_value > self.round_nr:
            print(
                "Called Stiche cant exceed amount of cards in game, please choose a lower number"
            )
            raise ValueError
        else:
            self.predictions[player] = prediction_value

    def set_atut_manually(self, player_q):
        from game.game_board import GameBoard
        print('Player', player_q[-1].number, 'chooses atut now!')
        if GameBoard.display_mode:
            chosen_card = ask_for_card([
                ColoredCard(0, 'red'),
                ColoredCard(0, 'green'),
                ColoredCard(0, 'blue'),
                ColoredCard(0, 'yellow')
            ])

            self.atut = chosen_card
        else:
            self.atut = ColoredCard(0, 'red')

    def set_new_atut(
        self,
        rounds_total: int,
        card_deck: list,
        player_q,
    ):
        if self.round_nr != rounds_total:
            new_atut = choice(card_deck)
            if isinstance(new_atut, ColoredCard):
                self.atut = new_atut
            elif isinstance(new_atut, SpecialCard):
                if new_atut.cardType == 'z':
                    self.set_atut_manually(player_q)
                else:
                    self.atut = None
        else:
            self.atut = None

    def calculate_score(self, players: list):
        from game.game_board import GameBoard
        self.count_win()
        for i in players:
            if isinstance(i, Player):
                prediction = self.predictions[i]
                won = self.stiche_won[i]
                if prediction == won:
                    i.score += 20 + (prediction * 10)
                else:
                    difference = abs(prediction - won)
                    i.score -= difference * 10
        if GameBoard.display_mode:
            print("*********************************")
            print("Player score are currently: ")
            for i in GameBoard.players:
                print("Player ", i.number, "has a score of: ", i.score)

    def count_win(self):
        for i in self.stiche:
            if isinstance(i, Stich):
                if isinstance(self.stiche_won[i.winner], type(int)):
                    self.stiche_won[i.winner] = 1
                else:
                    self.stiche_won[i.winner] += 1
        for i in self.stiche_won:
            if isinstance(i, int):
                for j in self.stiche[0].player_q:
                    if self.stiche[j] is None:
                        self.stiche[j] = 0

    def print_atut(self, total_rounds: int):
        if self.atut is None:
            print("Atut this round: None")
        elif self.round_nr != total_rounds:
            print("Atut this round: ", end='')
            self.atut.print_card()
            print()
Пример #12
0
 def __init__(self, player_q: deque, atut=ColoredCard(1, "red")):
     self.player_q = player_q
     self.cards_in_play = list()
     self.winner = Player
     self.atut = atut
Пример #13
0
 def test_set_stich_queue(self):
     stich1 = Stich(self.g.player_queue, ColoredCard(1, 'red'))
     stich1.winner = self.g.player_queue[1]
     self.g.get_current_round().stiche.append(stich1)
     self.assertEqual(self.g.player_queue[1], self.g.set_stich_queue(1)[0])
Пример #14
0
 def setUp(self) -> None:
     self.g = GameBoard(4, False)
     self.g.new_round()
     self.s = Stich(self.g.player_queue, ColoredCard(1, 'red'))
Пример #15
0
 def setUp(self) -> None:
     self.hand = [
         ColoredCard(3, 'red'),
         ColoredCard(1, 'blue'),
         ColoredCard(1, 'yellow'),
         ColoredCard(2, 'blue'),
         ColoredCard(10, 'yellow'),
         ColoredCard(12, 'blue'),
         ColoredCard(12, 'blue'),
         ColoredCard(12, 'blue'),
         ColoredCard(12, 'blue'),
         ColoredCard(12, 'blue'),
         ColoredCard(12, 'blue'),
         ColoredCard(12, 'blue'),
         ColoredCard(12, 'blue'),
         ColoredCard(12, 'blue'),
         ColoredCard(12, 'blue'),
         ColoredCard(12, 'blue'),
         ColoredCard(12, 'blue'),
         ColoredCard(12, 'blue'),
         ColoredCard(12, 'blue'),
         ColoredCard(12, 'blue'),
     ]