Example #1
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
Example #2
0
def move_once(t):
    """
    Move all robots according to mock cards on hand and perform tile effects.
    """

    apply_all_effects(state)
    print("After tile effects:")
    for robot in state.robots:
        print(robot)
Example #3
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_all_effects(state, 1)
    assert robot.coordinates == output_coordinates
Example #4
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_all_effects(state, 1)
    assert robot.direction == output_direction
Example #5
0
def test_robot_is_repaired_after_5th_round(damages_before, tile, damages_after):
    """
    When robot is on RepairTile he is supposed to be repaired after the 5th register.
    If he doesn't have any damages, the count remains the same as previous.
    """
    robot = Robot(Direction.N, (0, 0), "tester")
    state = State({(0, 0): [tile]}, [robot])
    robot.damages = damages_before
    robot.program = [MovementCard(100, 0) for x in range(5)]
    apply_all_effects(state)
    assert robot.damages == damages_after
Example #6
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_all_effects(state, 1)
    assert robot.coordinates == output_coordinates
Example #7
0
def test_robots_cannot_swap_places(input_coordinates_1, input_coordinates_2):
    """
    Test robots cannot swap places on belts that go against each other.
    """
    robots = [
        Robot(Direction.N, input_coordinates_1, "tester1"),
        Robot(Direction.N, input_coordinates_2, "tester2"),
    ]
    board = get_board("maps/test_belts.json")
    state = State(board, robots)
    apply_all_effects(state, 1)
    assert robots[0].coordinates == input_coordinates_1
    assert robots[1].coordinates == input_coordinates_2
Example #8
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_all_effects(state, 1)
    assert robot.direction == input_direction
Example #9
0
def play_test_game():
    """
    Play the game with given map.
    """
    commands, state = read_commands_and_state()
    robots_program = get_test_cards(commands)
    add_start_tile_number_to_robots(state)
    match_programs_to_robots(robots_program, state)

    apply_all_effects(state, registers=2)

    stop_fields = get_start_tiles(state._board, "stop")

    return state, stop_fields
Example #10
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.S, (1, 1), "tester")
    robot_obstacle2 = Robot(Direction.E, (3, 2), "tester")
    robot = Robot(Direction.W, input_coordinates, "tester")
    robot.damages = 0
    state = State(board, [robot_obstacle1, robot_obstacle2, robot])
    apply_all_effects(state, 1)
    assert robot.damages == damages_after
Example #11
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_all_effects(state, 1)
    assert robots[0].coordinates == output_coordinates_1
    assert robots[1].coordinates == output_coordinates_2
Example #12
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_all_effects(state, 1)
    assert robots[0].coordinates == output_coordinates_1
    assert robots[1].coordinates == output_coordinates_2
Example #13
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_all_effects(state, 1)
    assert robots[0].coordinates == output_coordinates_1
    assert robots[1].coordinates == output_coordinates_2
Example #14
0
def test_robot_is_pushed_to_the_correct_direction(tile, output_coordinates):
    """
    When robot is standing on a PusherTile, he should be pushed in the direction of pusher's force.
    Eg. pusher on the North tile side forces the robot's movement to the South.
    Robot's direction doesn't change, just the coordinates.
    The test asserts the coordinates change to a correct ones (in a correct direction).
    """
    robot = Robot(Direction.S, (1, 1), "tester")
    state = State(
        {
            (1, 0): [Tile(None, None, None)],
            (0, 1): [Tile(None, None, None)],
            (2, 1): [Tile(None, None, None)],
            (1, 2): [Tile(None, None, None)],
            (1, 1): [tile]
        }, [robot])
    apply_all_effects(state, 1)
    assert robot.direction == Direction.S
    assert robot.coordinates == output_coordinates
Example #15
0
def test_play_game(test_name):
    """
    Play the game with given map.
    """
    map_file = Path("tests/") / test_name / "map.json"
    commands_file = Path("tests/") / test_name / "commands.yaml"
    if not commands_file.exists():
        commands_file = None

    state = get_start_state(map_file)
    stop_fields = get_start_tiles(state._board, "stop")

    commands = read_commands(commands_file)

    assign_cards_to_robots(commands, state)
    assign_prerequisites_to_robots(commands, state)

    # Leave it here for debugging purpose :)
    # for robot in state.robots:
    #     print(robot.program)
    #     print(robot.damages)
    #     print(robot.flags)
    #     print(robot.lives)
    #     print(robot.power_down)
    #     print(robot.start_coordinates)

    apply_all_effects(state, registers=get_registers(commands))
    compare_results_with_robots(commands, state)

    # for robot in state.robots:
    #     print(robot.program)
    #     print(robot.damages)
    #     print(robot.flags)
    #     print(robot.lives)
    #     print(robot.power_down)
    #     print(robot.start_coordinates)

    for robot in state.robots:
        robot_field = state.robots.index(robot) + 1
        assert robot.coordinates == stop_fields[robot_field]["coordinates"]
        assert robot.direction == stop_fields[robot_field]["tile_direction"]