示例#1
0
def test_robot_and_tiles_shoot():
    """
    Robots are placed on a test_laser.json map.
    There are some walls that stop their lasers on the way.
    (In order to see the "human" version with arrows representing robots,
    check test_shoot_human_view.json),
    They should receive damages according to their and lasers' position.
    """
    board = get_board("maps/test_laser.json")

    robots = [Robot(Direction.W, (2, 2), "tester"),
              Robot(Direction.N, (1, 1), "tester"),
              Robot(Direction.E, (0, 2), "tester"),
              Robot(Direction.W, (1, 2), "tester"),
              Robot(Direction.S, (1, 3), "tester"),
              Robot(Direction.E, (0, 0), "tester"),
              Robot(Direction.N, (2, 0), "tester"),
              Robot(Direction.E, (3, 0), "tester"),
              Robot(Direction.N, (2, 1), "tester"),
              Robot(Direction.S, (3, 3), "tester"),
              ]
    for robot in robots:
        robot.damages = 0

    state = State(board, robots)
    apply_tile_effects(state, 0)
    damages_list = [0, 4, 0, 2, 0, 0, 1, 1, 1, 4]

    for robot in robots:
        assert robot.damages == damages_list[robots.index(robot)]
示例#2
0
def test_robot_changed_direction(direction_before, tile, direction_after):
    """
    When robot is on GearTile, he should be rotated according to the direction of the tile.
    Check that his direction changed after applying tile effect.
    """
    robot = Robot(direction_before, (0, 0), "tester")
    state = State({(0, 0): [tile]}, [robot])
    apply_tile_effects(state, 0)
    assert robot.direction == direction_after
示例#3
0
def test_robot_is_not_repaired(damages, tile, current_register):
    """
    When robot is on RepairTile but the register phase is not 5, he is not yet repaired. His damage count doesn't change.
    """
    robot = Robot(Direction.N, (0, 0), "tester")
    state = State({(0, 0): [tile]}, [robot])
    robot.damages = damages
    apply_tile_effects(state, current_register)
    assert robot.damages == damages
示例#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_robot_changed_coordinates(tile):
    """
    When a robot stands on FlagTile the starting coordinates change to the tile's coordinates.
    """
    robot = Robot(None, None, None, (0, 0))
    state = State({(0, 0): [tile]}, [robot], 1)
    robot.start_coordinates = (1, 1)
    apply_tile_effects(state)
    assert robot.start_coordinates == (0, 0)
示例#6
0
def test_robot_changed_coordinates(tile):
    """
    When a robot stands on FlagTile the start coordinates change to the tile's coordinates.
    """
    robot = Robot(Direction.N, (0, 0), "tester")
    state = State({(0, 0): [tile]}, [robot])
    robot.start_coordinates = (1, 1)
    apply_tile_effects(state, 0)
    assert robot.start_coordinates == (0, 0)
示例#7
0
def test_robot_movement_on_express_belts(input_coordinates, output_coordinates):
    """
    Test movement of robots on express 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_tile_effects(state, 0)
    assert robot.coordinates == output_coordinates
示例#8
0
def test_robot_collected_flags(flags_before, tile, flags_after):
    """
    When a robot stands on FlagTile with appropriate number (+1 to his current flag count), he collects it.
    He doesn't collect the flags with the other number than defined. They don't have any effect on him.
    """
    robot = Robot(Direction.N, (0, 0), "tester")
    state = State({(0, 0): [tile]}, [robot])
    robot.flags = flags_before
    apply_tile_effects(state, 0)
    assert robot.flags == flags_after
示例#9
0
def test_robot_changed_start_coordinates(tile, coordinates_after):
    """
    When robot is on RepairTile with special property, he changes his start coordinates to the tile coordinates.
    On a normal RepairTile he doesn't change the start tile.
    """
    robot = Robot(Direction.N, (0, 0), "tester")
    state = State({(0, 0): [tile]}, [robot])
    robot.start_coordinates = (1, 1)
    apply_tile_effects(state, 0)
    assert robot.start_coordinates == coordinates_after
示例#10
0
def move_once(t):
    """
    Move all robots 2 tiles forward and rotate 180 degrees.
    """

    for robot in state.robots:
        robot.walk(3, state)
    print(state.robots)
    apply_tile_effects(state)
    print(state.robots)
示例#11
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
示例#12
0
def test_robot_is_not_repaired(damages, tile, current_game_round):
    """
    When robot is on RepairTile but the game round is not 5, he is not yet repaired. His damage count doesn't change.
    """
    robot = Robot(None, None, None, (0, 0))
    state = State({(0, 0): [tile]}, [robot], 1)
    robot.damages = damages
    state.game_round = current_game_round
    apply_tile_effects(state)
    assert robot.damages == damages
示例#13
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 game round.
    If he doesn't have any damages, the count remains the same as previous.
    """
    robot = Robot(None, None, None, (0, 0))
    state = State({(0, 0): [tile]}, [robot], 1)
    robot.damages = damages_before
    state.game_round = 5
    apply_tile_effects(state)
    assert robot.damages == damages_after
示例#14
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
示例#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 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
示例#17
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
示例#18
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_tile_effects(state, 0)
    assert robot.direction == Direction.S
    assert robot.coordinates == output_coordinates
示例#19
0
def test_robot_is_pushed_out_of_the_board(tile):
    """
    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.
    If he is pushed out of a board game, he should be killed.
    The test asserts the attributes: coordinates, lives and inactive change.
    """
    robot = Robot(Direction.S, (0, 0), "tester")
    state = State({(0, 0): [tile]}, [robot])
    apply_tile_effects(state, 0, 1)
    assert robot.lives == 2
    assert robot.inactive is True
    assert robot.coordinates is None
示例#20
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
示例#21
0
def test_robot_is_pushed_at_the_correct_round(register, 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 push is performed only at the certain register (1-3-5 or 2-4) according
    to the value on the tile.
    """
    robot = Robot(Direction.W, (1, 1), "tester")
    state = State({(1, 0): [Tile(None, None, None)], (1, 1): [tile]}, [robot])
    apply_tile_effects(state, register)
    assert robot.direction == Direction.W
    assert robot.coordinates == output_coordinates
示例#22
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
示例#23
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
示例#24
0
def move_once(t):
    """
    Move all robots according to mock cards on hand and perform tile effects.
    """

    for robot in state.robots:
        #robot.apply_card_effect(state)
        robot.walk(3, state)
        print(robot)
    #state.robots[3].walk(-1, state)
    #state.robots[3].rotate(Rotation.RIGHT)
    #state.robots[3].walk(2, state)

    apply_tile_effects(state)
    print("After tile effects:")
    for robot in state.robots:
        print(robot)