예제 #1
0
def test_starting_coordinates():
    """
    Take board (based on JSON test_3 map) and assert correct starting coordinates are returned.
    If the test_3.json map is changed or removed, the test needs to be updated.
    """
    board = get_board("maps/test_3.json")
    assert len(get_starting_coordinates(board)) == 8
    assert isinstance(get_starting_coordinates(board), list)
예제 #2
0
def test_map_1_is_right_oriented(coordinates, tile_type):
    """
    Test maps are loaded in the right orientation.

    Uses test_1.json map for this.
    """
    board = get_board("maps/test_1.json")
    assert isinstance(board[coordinates][0], tile_type)
예제 #3
0
def test_robot_movement_on_normal_belts(input_coordinates, output_coordinates):
    """
    Test movement of robots on normal conveyor belts - 6 types of tiles.
    """
    robot = Robot(Direction.N, input_coordinates, "tester")
    board = get_board("maps/test_belts.json")
    state = State(board, [robot])
    apply_all_effects(state, 1)
    assert robot.coordinates == output_coordinates
예제 #4
0
def test_robot_movement_on_crossroad_belts(input_coordinates, output_coordinates):
    """
    Test movement of robots on crossroads from different directions.
    """
    robot = Robot(Direction.N, input_coordinates, "tester")
    board = get_board("maps/test_belts.json")
    state = State(board, [robot])
    apply_tile_effects(state, 0)
    assert robot.coordinates == output_coordinates
예제 #5
0
def test_get_flags_starts():
    """ Assert count of start and flags tiles is computed correctly. """
    board = get_board("./maps/test_maps/test_6.json")
    f = []
    s = []
    for coordinate, tiles in board.items():
        flags, starts = get_flags_and_starts(tiles, f, s)
    assert len(flags) == 1
    assert len(starts) == 1
예제 #6
0
def test_board_structure():
    """
    Take board (based on JSON test_3 map) and assert correct board structure is returned.
    If the test_3.json map is changed or removed, the test needs to be updated.
    """
    board = get_board("maps/test_3.json")
    example_tile = board[0, 0]
    assert example_tile[0].path == "./img/squares/png/ground.png"
    assert example_tile[0].direction == Direction.N
예제 #7
0
def test_robots_on_start_coordinates():
    """
    Assert that the result of create_robots is a list which contains
    Robot objects with correct attribute coordinates.
    """
    board = get_board("maps/test_3.json")
    robots = create_robots(board)
    assert isinstance(robots, list)
    assert isinstance(robots[0], Robot)
예제 #8
0
def test_change_of_robots_direction_on_rotating_belts(input_coordinates, output_direction):
    """
    Test change of robot's direction after he is moved by conveyor belt to
    rotating conveyor belt.
    """
    robot = Robot(Direction.N, input_coordinates, "tester")
    board = get_board("maps/test_belts.json")
    state = State(board, [robot])
    apply_tile_effects(state, 0)
    assert robot.direction == output_direction
예제 #9
0
    def get_start_state(cls, map_name):
        """
        Get start state of game.

        map_name: path to map file. Create board and robots on start tiles,
        initialize State object with them.
        """
        board = get_board(map_name)
        robots_start = create_robots(board)
        return cls(board, robots_start)
예제 #10
0
def check_tiles(map_name):
    """
    Change the list of tile subclasses to the letters.
    A, B and C type can be only once in type list.
    """
    board = get_board(map_name)

    for coordinate, tiles in board.items():
        tile_type_letter = []
        tile_type_and_direction = []
        for tile in tiles:
            tile_type_letter.append(get_order_tiles(type(tile).__name__))
            """
            Tiles with the same type and direction mustn't be in list of types
            """
            if (type(tile).__name__,
                    tile.direction) in tile_type_and_direction:
                return coordinate, type(tile).__name__  # (8, 9), 'wall'
            else:
                tile_type_and_direction.append(
                    (type(tile).__name__, tile.direction))

        a = 0
        b = 0
        c = 0

        for letter in tile_type_letter:
            if letter[0] == 'A':
                a += 1
            if letter[0] == 'B':
                b += 1
            if letter[0] == 'C':
                c += 1
        if a > 1 or b > 1 or c > 1:
            return coordinate, a, b, c  # ((1, 9), 1, 2, 0)
        """
        Tiles types must be in the correct order.
        ["A","B","D"] is correct ["D", "A"] is not
        A < B < C < D
        """
        letters_count = len(tile_type_letter)
        for i in range(letters_count - 1):
            if tile_type_letter[i][0] > tile_type_letter[i + 1][0]:
                return coordinate, tile_type_letter[i]  # ((7, 9), 'D')
        """
        "Flag" mustn't be over the "Hole" or "Starting tile"
        """
        for i in range(len(tile_type_letter) - 1):
            if tile_type_letter[i] == "B_hole" and tile_type_letter[
                    i + 1] == "C_flag" or tile_type_letter[
                        i] == "B_start_tile" and tile_type_letter[
                            i + 1] == "C_flag":
                return coordinate, tile_type_letter[i]

    return True
예제 #11
0
def test_robot_is_stopped_by_wall(input_coordinates, output_coordinates):
    """
    Take robot's coordinates, move's direction and distance and assert robot
    was moved to correct coordinates.
    A special map test_walls was created in order to test this feature.
    """
    board = get_board("maps/test_walls.json")
    robot = Robot(Direction.N, input_coordinates, "tester")
    state = State(board, [robot])
    robot.move(Direction.N, 2, state)
    assert robot.coordinates == output_coordinates
예제 #12
0
def test_robot_movement_on_connected_belts(input_coordinates, output_coordinates):
    """
    Test movement of robots on all conveyor belts expect for crossroads.
    Belts are connected together to test movement of express belts followed up
    by movement of all belts (according to game rules).
    """
    robot = Robot(Direction.N, input_coordinates, "tester")
    board = get_board("maps/test_belts.json")
    state = State(board, [robot])
    apply_tile_effects(state, 0)
    assert robot.coordinates == output_coordinates
예제 #13
0
def test_robots_dont_change_direction_on_rotating_belts_after_move_card(input_coordinates, input_direction):
    """
    Test robot's direction isn't changed after he is moved by card to
    rotating conveyor belt.
    """
    robot = Robot(input_direction, input_coordinates, "tester")
    robot.program = [MovementCard(100, 1)]
    board = get_board("maps/test_belts.json")
    state = State(board, [robot])
    robot.program[0].apply_effect(robot, state)
    apply_tile_effects(state, 0)
    assert robot.direction == input_direction
예제 #14
0
def test_two_robots_movements_on_belts(input_coordinates_1, input_coordinates_2, output_coordinates_1, output_coordinates_2):
    """
    Test movement of two robots in a row on belts.
    """
    robots = [Robot(Direction.N, input_coordinates_1, "tester"),
              Robot(Direction.N, input_coordinates_2, "tester"),
              ]
    board = get_board("maps/test_belts.json")
    state = State(board, robots)
    apply_tile_effects(state, 0)
    assert robots[0].coordinates == output_coordinates_1
    assert robots[1].coordinates == output_coordinates_2
예제 #15
0
def test_robots_cannot_switch_places(input_coordinates_1, input_coordinates_2):
    """
    Test robots cannot switch places on belts that go against each other.
    """
    robots = [Robot(Direction.N, input_coordinates_1, "tester"),
              Robot(Direction.N, input_coordinates_2, "tester"),
              ]
    board = get_board("maps/test_belts.json")
    state = State(board, robots)
    apply_tile_effects(state, 0)
    assert robots[0].coordinates == input_coordinates_1
    assert robots[1].coordinates == input_coordinates_2
예제 #16
0
def get_start_state(map_name):
    """
    Get start state of game.

    map_name: path to map file. Currently works only for .json files from Tiled 1.2
    Create board and robots on start tiles, initialize State object
    containing Tile and Robot object as well as the map size.
    Return State object.
    """
    board = get_board(map_name)
    robots_start = create_robots(board)
    state = State(board, robots_start)
    return state
예제 #17
0
def test_robot_does_not_move_onto_another_robot(input_coordinates_1, input_coordinates_2, output_coordinates_1, output_coordinates_2):
    """
    Test robot doesn't move to coordinates of other robot. Other robot stands
    on the end of belt but on the ground tile.
    """
    robots = [Robot(Direction.N, input_coordinates_1, "tester"),
              Robot(Direction.N, input_coordinates_2, "tester"),
              ]
    board = get_board("maps/test_belts.json")
    state = State(board, robots)
    apply_tile_effects(state, 0)
    assert robots[0].coordinates == output_coordinates_1
    assert robots[1].coordinates == output_coordinates_2
예제 #18
0
def test_robot_is_damaged_by_laser(input_coordinates, damages_after):
    """
    When robot stands on laser tile, he is damaged according to the laser strength, but only if there is no obstacle in the way.
    If there are obstacles, damage count changes accordingly.
    A special map test_laser was created in order to test this feature.
    """
    board = get_board("maps/test_laser.json")
    robot_obstacle1 = Robot(Direction.N, None, None, (1, 1))
    robot_obstacle2 = Robot(Direction.N, None, None, (3, 2))
    robot = Robot(Direction.E, None, None, input_coordinates)
    robot.damages = 0
    state = State(board, [robot_obstacle1, robot_obstacle2, robot], 16)
    apply_tile_effects(state)
    assert robot.damages == damages_after
예제 #19
0
def test_two_robots_movement_on_T_crossroad(input_coordinates_1, input_coordinates_2, output_coordinates_1, output_coordinates_2):
    """
    Test movement of two robots on T crossroads. Robots are facing each other
    across the crossroad. Both want to go through this crossroad, but none them
    move.
    """
    robots = [Robot(Direction.N, input_coordinates_1, "tester"),
              Robot(Direction.N, input_coordinates_2, "tester"),
              ]
    board = get_board("maps/test_belts.json")
    state = State(board, robots)
    apply_tile_effects(state, 0)
    assert robots[0].coordinates == output_coordinates_1
    assert robots[1].coordinates == output_coordinates_2
예제 #20
0
    def get_start_state(cls, map_name, players=None):
        """
        Get start state of game.

        map_name: path to map file. Create board and robots on start tiles,
        initialize State object with them.
        """
        board = get_board(map_name)
        robots_start, start_coordinates = create_robots(board, players)
        state = cls(board, robots_start)
        for robot in state.robots:
            state.deal_cards(robot)
        # Save the list of start tiles coordinates for robots
        # reinitialising purposes.
        state.start_coordinates = start_coordinates
        return state
예제 #21
0
def check_tiles(map_name):
    """
    Change the list of tile subclasses to the letters.
    A, B and C type can be only once in type list.
    """
    board = get_board(map_name)
    flags = []
    starts = []
    for coordinate, tiles in board.items():
        tile_type_letter = get_tiles(coordinate, tiles)
        check_count_of_tiles_types(tile_type_letter, coordinate)
        check_layers_order(tile_type_letter, coordinate)
        check_flag_is_not_on_hole_or_start(tile_type_letter, coordinate)
        laser_count = get_laser_count(tile_type_letter)
        if laser_count > 1:
            check_lasers_in_opposite_direction(tiles, coordinate)
        check_lasers_start(tiles, coordinate)
        flags_number, starts_number = get_flags_and_starts(
            tiles, flags, starts)
    sort_and_check_consecutive_numbers(flags_number)
    sort_and_check_consecutive_numbers(starts_number)

    # If none of above checks has raised an exception, validation is OK, so:
    return True
예제 #22
0
def test_pusher_on_board(coordinates, register):
    test_board = get_board("maps/test_maps/test_6.json")
    test_tile = test_board[coordinates][1]
    assert test_tile.register == register
예제 #23
0
def test_map_with_embedded_tileset():
    """
    Try to load the map with tileset directly in map file.
    Assert board exists.
    """
    assert get_board("maps/test_4.json")
예제 #24
0
def test_belts_on_board(coordinates, direction_out, express):
    test_board = get_board("maps/test_maps/test_6.json")
    test_tile = test_board[coordinates][1]
    assert test_tile.direction_out == direction_out
    assert test_tile.express == express
예제 #25
0
def test_gear_on_board(coordinates, move_direction):
    test_board = get_board("maps/test_maps/test_6.json")
    test_tile = test_board[coordinates][1]
    assert test_tile.move_direction == move_direction
예제 #26
0
def test_start_flag_on_board(coordinates, number):
    test_board = get_board("maps/test_maps/test_6.json")
    test_tile = test_board[coordinates][1]
    assert test_tile.number == number
예제 #27
0
def test_repair_on_board(coordinates, new_start):
    test_board = get_board("maps/test_maps/test_6.json")
    test_tile = test_board[coordinates][1]
    assert test_tile.new_start == new_start
예제 #28
0
def test_lasers_on_board(coordinates, laser_attribute, start_attribute):
    test_board = get_board("maps/test_maps/test_6.json")
    test_tile = test_board[coordinates][1]
    assert test_tile.laser_strength == laser_attribute
    assert test_tile.start == start_attribute