def print_atut(g: GameBoard):
    if g.get_current_round().atut is None:
        print("Atut this round: None")
    elif g.get_current_round() != g.rounds_total:
        print("Atut this round: ", end='')
        g.get_current_round().atut.print_card()
        print()
Beispiel #2
0
class TestStichWinnerAtutNone(TestCase):
    def setUp(self) -> None:
        self.g = GameBoard(4, False)
        self.g.new_round()
        # noinspection PyTypeChecker
        self.s = Stich(self.g.player_queue, None)

    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])

    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])

    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])

    def test_narr_only_win(self):
        self.s.cards_in_play.append(SpecialCard("n"))
        self.s.cards_in_play.append(SpecialCard("n"))
        self.s.cards_in_play.append(SpecialCard("n"))
        self.s.cards_in_play.append(SpecialCard("n"))

        self.assertEqual(self.s.check_stich_winner(), self.s.player_q[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_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])
Beispiel #3
0
class GameCoordinator:
    def __init__(self) -> None:
        self.player1 = Player(name='Player 1', symbol='X')
        self.player2 = Player(name='Player 2', symbol='O')
        self.game_board = GameBoard()
        self.next_turn_player = self.player1

    def start(self) -> None:
        self.player1.gather_name()
        self.player2.gather_name()

        print()
        print(f"{self.player1.name}'s symbol is {self.player1.symbol}")
        print(f"{self.player2.name}'s symbol is {self.player2.symbol}")
        print()

        self.game_board.gather_board_size()
        print()

        self.resume()

    def resume(self) -> None:
        print(self.game_board.render())

        winner, is_draw = self.game_board.check_win_state()
        if winner:
            print(f'{winner.name} wins!')
            return

        if is_draw:
            print('Draw!')
            return

        print(f"It is {self.next_turn_player.name}'s turn.")
        row, col, error_msg = self.next_turn_player.take_turn(
            self.game_board.size)
        if error_msg:
            print(error_msg)
        else:
            existing_player = self.game_board.make_player_move(
                row, col, self.next_turn_player)
            if existing_player:
                print(f'{existing_player.name} has already played there!')
            else:
                self.next_turn_player = self.player2 if self.next_turn_player == self.player1 else self.player1

        self.resume()
def user_input():
    command = input().casefold()
    if command == "h" or command == "help":
        display_help()
    elif command == "exit" or command == "x":
        exit()
    elif command == "p" or command == "player":
        change_player_count()
    elif command == "":
        welcome_message()
    elif command == "d":
        dev_options_menu()
    elif command == "n" or command == "new game" or command == "newgame":
        g = GameBoard(Options.player_count, Options.cli_inputs,
                      Options.player_names_random)
        g.start()
    else:
        print('I did not get you there. \n'
              'If you need help just type "h" and then press enter')
class MyTestCase(unittest.TestCase):
    def setUp(self) -> None:
        self.g = GameBoard(4, False)

    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_stich_round_3(self):
        self.g.current_round_count = 3
        r = [Round(1), Round(2), Round(3)]
        s = [Stich(self.g.player_queue), Stich(self.g.player_queue)]

        s[1].winner = self.g.players[2]
        r[2].stiche.extend(s)
        self.g.score_board.round_score.extend(r)
        result = tuple(self.g.set_stich_queue(3))
        expected = tuple([
            self.g.players[2], self.g.players[3], self.g.players[0],
            self.g.players[1]
        ])
        self.assertTupleEqual(result, expected)
 def setUp(self) -> None:
     self.g = GameBoard(4, False)
def test(g: GameBoard):
    test_number_of_players(g.players)

    g.game_loop()
Beispiel #8
0
 def __init__(self) -> None:
     self.player1 = Player(name='Player 1', symbol='X')
     self.player2 = Player(name='Player 2', symbol='O')
     self.game_board = GameBoard()
     self.next_turn_player = self.player1
Beispiel #9
0
class TestGameBoard(unittest.TestCase):
    def setUp(self):
        self.game_board = GameBoard(size=3)

    def test_init(self):
        self.assertEqual(self.game_board.size, 3)
        self.assertTupleEqual(np.shape(self.game_board.grid), (3, 3))
        self.assertTrue(np.all(self.game_board.grid == None))

    def test_clear(self):
        self.game_board.clear(size=4)

        self.assertEqual(self.game_board.size, 4)
        self.assertTupleEqual(np.shape(self.game_board.grid), (4, 4))
        self.assertTrue(np.all(self.game_board.grid == None))

    @input_cases({
        '4': 4,
        '9': 9,
        '-1': 3,
        'abc': 3,
        '2': 3,
        '10': 3,
        ' ': 3})
    def test_gather_board_size(self, expected_size):
        self.game_board.gather_board_size()

        self.assertEqual(self.game_board.size, expected_size)
        self.assertTupleEqual(np.shape(self.game_board.grid),
                              (expected_size, expected_size))
        self.assertTrue(np.all(self.game_board.grid == None))

    def test_render_at_start(self):
        render_result = self.game_board.render()

        self.assertEqual(render_result,
                         "    A   B   C   \n"
                         "1 | - | - | - | \n"
                         "2 | - | - | - | \n"
                         "3 | - | - | - | \n")

    def test_render_two_player_moves(self):
        self.game_board.make_player_move(0, 0, Player('Player1', 'X'))
        self.game_board.make_player_move(1, 1, Player('Player2', 'O'))

        render_result = self.game_board.render()

        self.assertEqual(render_result,
                         "    A   B   C   \n"
                         "1 | X | - | - | \n"
                         "2 | - | O | - | \n"
                         "3 | - | - | - | \n")

    def test_make_player_move_new_cell(self):
        player = Player('Player1', 'X')
        existing_player = self.game_board.make_player_move(0, 0, player)
        self.assertIsNone(existing_player)

    def test_make_player_move_existing_cell(self):
        player = Player('Player1', 'X')

        self.game_board.make_player_move(0, 0, player)
        existing_player = self.game_board.make_player_move(0, 0, player)

        self.assertEqual(existing_player, player)

    def test_check_win_state_at_start(self):
        winning_player, is_draw = self.game_board.check_win_state()
        self.assertTupleEqual((None, False), (winning_player, is_draw))

    def test_check_win_state_row_same(self):
        player = Player('Player1', 'X')

        self.game_board.make_player_move(0, 0, player)
        self.game_board.make_player_move(0, 1, player)
        self.game_board.make_player_move(0, 2, player)
        winning_player, is_draw = self.game_board.check_win_state()

        self.assertTupleEqual((player, False), (winning_player, is_draw))

    def test_check_win_state_column_same(self):
        player = Player('Player1', 'X')

        self.game_board.make_player_move(0, 0, player)
        self.game_board.make_player_move(1, 0, player)
        self.game_board.make_player_move(2, 0, player)
        winning_player, is_draw = self.game_board.check_win_state()

        self.assertTupleEqual((player, False), (winning_player, is_draw))

    def test_check_win_state_left_to_right_diagonal_same(self):
        player = Player('Player1', 'X')

        self.game_board.make_player_move(0, 0, player)
        self.game_board.make_player_move(1, 1, player)
        self.game_board.make_player_move(2, 2, player)
        winning_player, is_draw = self.game_board.check_win_state()

        self.assertTupleEqual((player, False), (winning_player, is_draw))

    def test_check_win_state_right_to_left_diagonal_same(self):
        player = Player('Player1', 'X')

        self.game_board.make_player_move(0, 2, player)
        self.game_board.make_player_move(1, 1, player)
        self.game_board.make_player_move(2, 0, player)
        winning_player, is_draw = self.game_board.check_win_state()

        self.assertTupleEqual((player, False), (winning_player, is_draw))

    def test_check_win_state_draw_state(self):
        player1 = Player('Player1', 'X')
        player2 = Player('Player1', 'O')

        self.game_board.make_player_move(0, 0, player1)
        self.game_board.make_player_move(0, 1, player2)
        self.game_board.make_player_move(1, 0, player1)
        self.game_board.make_player_move(2, 0, player2)
        self.game_board.make_player_move(1, 1, player1)
        self.game_board.make_player_move(2, 2, player2)
        self.game_board.make_player_move(2, 1, player1)
        self.game_board.make_player_move(1, 2, player2)
        self.game_board.make_player_move(0, 2, player1)

        winning_player, is_draw = self.game_board.check_win_state()
        self.assertTupleEqual((None, True), (winning_player, is_draw))
Beispiel #10
0
 def setUp(self):
     self.game_board = GameBoard(size=3)
Beispiel #11
0
 def setUp(self) -> None:
     self.g = GameBoard(4, False)
     self.g.new_round()
     self.s = Stich(self.g.player_queue, ColoredCard(1, 'red'))
Beispiel #12
0
 def setUp(self) -> None:
     self.g = GameBoard(4, False)
     self.g.new_round()
     # noinspection PyTypeChecker
     self.s = Stich(self.g.player_queue, None)
 def setUp(self) -> None:
     self.g = GameBoard(4, True)
     self.players = self.g.players