コード例 #1
0
    def test_is_equal(self):
        board1 = FishBoard(4, 3)
        board1 = board1.create_hole(2, 0)
        board1 = board1.create_hole(3, 0)
        board1 = board1.create_hole(2, 1)
        board1 = board1.create_hole(0, 1)

        board2 = FishBoard(4, 3)
        board2 = board2.create_hole(2, 0)
        board2 = board2.create_hole(3, 0)
        board2 = board2.create_hole(2, 1)
        board2 = board2.create_hole(0, 1)

        factory1 = FishGameState(board=board1,
                                 num_players=3,
                                 players=TestGameState.player_list,
                                 phase=GameStatePhase.INITIAL,
                                 current_player=TestGameState.player_list[0])
        factory1 = factory1.add_penguin(0, 0, "red")
        factory1 = factory1.add_penguin(1, 0, "white")

        factory2 = FishGameState(board=board2,
                                 num_players=3,
                                 players=TestGameState.player_list,
                                 phase=GameStatePhase.INITIAL,
                                 current_player=TestGameState.player_list[0])
        factory2 = factory2.add_penguin(0, 0, "red")
        factory2 = factory2.add_penguin(1, 0, "white")

        state1 = factory1.finalize()
        state2 = factory2.finalize()

        self.assertTrue(state1.is_equal(state2))
コード例 #2
0
    def test_is_equal_false_different_holes(self):
        board1 = FishBoard(num_rows=4, num_cols=3)
        board2 = FishBoard(num_rows=4, num_cols=3)

        board1 = board1.create_hole(row=1, col=0)
        board2 = board2.create_hole(row=1, col=1)

        self.assertFalse(board1.is_equal(board2))
コード例 #3
0
    def test_is_equal(self):
        board1 = FishBoard(num_rows=4, num_cols=3)
        board2 = FishBoard(num_rows=4, num_cols=3)

        board1 = board1.add_fish(row=0, col=0)
        board2 = board2.add_fish(row=0, col=0)

        board1 = board1.create_hole(row=1, col=0)
        board2 = board2.create_hole(row=1, col=0)

        self.assertTrue(board1.is_equal(board2))
コード例 #4
0
 def test_any_player_can_move_failure(self):
     board = FishBoard(4, 3)
     board = board.create_hole(2, 0)
     board = board.create_hole(3, 0)
     board = board.create_hole(2, 1)
     board = board.create_hole(0, 1)
     factory = FishGameState(board=board,
                             num_players=3,
                             players=TestGameState.player_list,
                             phase=GameStatePhase.INITIAL,
                             current_player=TestGameState.player_list[0])
     factory = factory.add_penguin(0, 0, "red")
     factory = factory.add_penguin(1, 0, "white")
     game_state = factory.finalize()
     self.assertFalse(game_state.check_any_player_can_move())
コード例 #5
0
def Demo3(holes: List[Coordinate]) -> FishGameController:
    """
    Given the list of holes, render a board with holes at those
    cooridates and 1 fish at every non-hole tile.
    :param holes: List of hole Coordinates
    :return: A controller to be execute in main.
    """

    hexgrid = HexGridView()
    board = FishBoard(num_rows=HEXES_ROWS, num_cols=HEXES_COLUMNS)

    for hole in holes:
        board = board.create_hole(row=hole.row, col=hole.col)

    for row in range(board.num_rows):
        for col in range(board.num_cols):
            if board.retrieve_num_fish(
                    row=row, col=col) == 0 and board.is_tile(row=row, col=col):
                board = board.add_fish(row=row, col=col)

    player_1 = Player("red", 0, 0, [])
    state = FishGameState(board=board,
                          num_players=1,
                          players=[player_1],
                          current_player=player_1)
    behavior = FishGameBehavior(state=state, view=hexgrid)

    controller = FishGameController(behavior=behavior,
                                    view=hexgrid,
                                    state=state)

    return controller
コード例 #6
0
    def test_get_player_id_success(self):
        board = FishBoard(4, 3)
        board = board.create_hole(2, 0)
        board = board.create_hole(3, 0)
        board = board.create_hole(2, 1)
        board = board.create_hole(0, 1)
        factory = FishGameState(board=board,
                                num_players=3,
                                players=TestGameState.player_list,
                                phase=GameStatePhase.INITIAL,
                                current_player=TestGameState.player_list[0])
        factory = factory.add_penguin(0, 0, "red")
        factory = factory.add_penguin(1, 0, "white")

        game_state = factory.finalize()
        self.assertEqual(game_state.get_player_color(0, 0), "red")
        self.assertEqual(game_state.get_player_color(3, 2), "")
コード例 #7
0
 def test_validate_input_invalid_row_and_col_has_hole(self):
     board = FishBoard(4, 3)
     board = board.create_hole(1, 1)
     game_state = FishGameState(board,
                                3,
                                TestGameState.player_list,
                                current_player=TestGameState.player_list[0],
                                phase=GameStatePhase.FINAL)
     is_valid, error_msg = game_state.validate_input("red", 1, 1)
     self.assertFalse(is_valid)
     self.assertEqual(error_msg, "Row and column is a hole")
コード例 #8
0
def RandomlyGenerateHole(board: FishBoard, total_num_hole=2):
    for _ in range(total_num_hole):
        not_added = True
        while not_added:
            random_row = randint(0, HEXES_ROWS - 1)
            random_col = randint(0, HEXES_COLUMNS - 1)
            if board.retrieve_num_fish(random_row,
                                       random_col) == 0 and board.is_tile(
                                           random_row, random_col):
                board = board.create_hole(random_row, random_col)
                not_added = False
    return board
コード例 #9
0
 def test_get_reachable_tiles_with_holes(self):
     model = FishBoard(num_rows=5, num_cols=4)
     model = model.create_hole(3, 1)
     expected_reachable = [
         Coordinate(row=0, col=1),
         Coordinate(row=1, col=1),
         Coordinate(row=0, col=2),
         Coordinate(row=4, col=1),
         Coordinate(row=3, col=0),
         Coordinate(row=4, col=0),
         Coordinate(row=1, col=0),
         Coordinate(row=0, col=0)
     ]
     self.assertEqual(model.get_reachable_tiles(2, 1), expected_reachable)
コード例 #10
0
 def test_create_hole(self):
     model = FishBoard(num_rows=4, num_cols=3)
     self.assertTrue(model.board[0][0].is_tile)
     model = model.create_hole(0, 0)
     self.assertFalse(model.board[0][0].is_tile)