Exemple #1
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
Exemple #2
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
def test_state_from_dict():
    """
    Check if state.from_dict can load State from JSON.
    """
    state = State.get_start_state("maps/test_maps/test_3.json")
    data = state.whole_as_dict("maps/test_maps/test_3.json")
    state_recovered = State.whole_from_dict(data)

    assert state_recovered.robots[0].coordinates == (0, 1)
    assert state_recovered.robots[1].damages == 0
    assert state_recovered._board[0, 11][0].direction == Direction.N
    assert state_recovered._board[2, 5][0].name == "ground"
Exemple #4
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, None, None, (1, 1))
    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], 5)
    state.game_round = 1
    apply_tile_effects(state)
    assert robot.direction == Direction.S
    assert robot.coordinates == output_coordinates
Exemple #5
0
def test_robot_is_pushed_at_the_correct_round(game_round, 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 game round (1-3-5 or 2-4) according
    to the value on the tile.
    """
    robot = Robot(Direction.W, None, None, (1, 1))
    state = State({(1, 0): [Tile(None, None, None)], (1, 1): [tile]}, [robot], 2)
    state.game_round = game_round
    apply_tile_effects(state)
    assert robot.direction == Direction.W
    assert robot.coordinates == output_coordinates
Exemple #6
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, None, None, (0, 0))
    state = State({(0, 0): [tile]}, [robot], 1)
    state.game_round = 1
    apply_tile_effects(state)
    assert robot.lives == 2
    assert robot.inactive is True
    assert robot.coordinates == (-1, -1)
Exemple #7
0
    async def get_game_state(self):
        """
        Connect to server and receive messages.
        Process information from server.
        """
        task = asyncio.create_task(self.tick_log())
        async with aiohttp.ClientSession() as session:
            async with session.ws_connect('http://' + self.hostname +
                                          ':8080/receiver/') as ws:
                # for loop is finished when client disconnects from server
                async for message in ws:
                    message = message.json()
                    if "game_state" in message:
                        self.state = State.whole_from_dict(message)
                        self.reset_last_robots()
                        if self.window is None:
                            self.window = create_window(
                                self.state, self.window_draw)
                    if "available_robots" in message:
                        self.available_robots = self.state.robots_from_dict(
                            {"robots": message["available_robots"]})
                    if 'log' in message:
                        self.log_to_play.extend(message['log'])
                    if "winner" in message:
                        self.state.winners = message["winner"]
                        self.log_to_play.append(None)

        task.cancel()
def test_robot_change_direction(current_direction, towards, new_direction):
    """
    Assert that robot rotates correctly according to given rotation.
    """
    robot = Robot(current_direction, None, "bender")
    robot.rotate(towards, State.get_start_state("maps/test_maps/test_3.json"))
    assert robot.direction == new_direction
Exemple #9
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)]
Exemple #10
0
 def set_game_state(self, message, robot_name, own_robot_name):
     """
     Set game attributes using data from server message:
     - create game state, call set_robots.
     """
     self.game_state = State.whole_from_dict(message)
     self.set_robots(message["game_state"], robot_name, own_robot_name)
def test_card_priorities():
    """
    Check that robots are sorted according to their cards on hand.
    Assert first and last robot's on the list priority.
    """
    state = State.get_start_state("maps/test_maps/test_effects.json")
    cards = [[MovementCard(100, 1), MovementCard(100, 1)],
             [RotationCard(120, Rotation.U_TURN), MovementCard(200, 2)],
             [MovementCard(150, -1), MovementCard(110, 1)],
             [MovementCard(110, 1), MovementCard(140, 1)],
             [RotationCard(55, Rotation.LEFT), MovementCard(250, 2)],
             [MovementCard(300, 3), MovementCard(350, 3)],
             [MovementCard(230, 2), RotationCard(80, Rotation.RIGHT)],
             [MovementCard(150, 1), MovementCard(140, 1)],
             ]
    # create robot's programs
    i = 0
    for robot in state.get_active_robots():
        robot.program = cards[i]
        i += 1

    robot_cards = state.get_robots_ordered_by_cards_priority(0)
    print(robot_cards[0])
    assert robot_cards[0][0].program[0].priority == 300
    assert robot_cards[7][0].program[0].priority == 55

    robot_cards = state.get_robots_ordered_by_cards_priority(1)
    assert robot_cards[0][0].program[1].priority == 350
    assert robot_cards[7][0].program[1].priority == 80
def test_check_winner_2():
    """
    Assert there in no winner when no one has collected enough flags.
    """
    state = State.get_start_state("maps/test_maps/test_3.json")
    state.robots[0].flags = state.flag_count - 1
    assert state.check_winner() == []
    assert state.robots[0].winner is False
def test_check_winner():
    """
    Assert the winner when there is only one.
    """
    state = State.get_start_state("maps/test_maps/test_3.json")
    state.robots[0].flags = state.flag_count
    assert state.check_winner() == ['Bender']
    assert state.robots[0].winner
def test_confirmed_count_2():
    """
    Assert the count when all robots confirm choice selection.
    """
    state = State.get_start_state("maps/test_maps/test_3.json")
    for robot in state.robots:
        robot.selection_confirmed = True
    assert state.count_confirmed_selections() == len(state.robots)
def test_confirmed_count():
    """
    Assert the count when 2 robots confirm choice selection.
    """
    state = State.get_start_state("maps/test_maps/test_3.json")
    state.robots[0].selection_confirmed = True
    state.robots[1].selection_confirmed = True
    assert state.count_confirmed_selections() == 2
Exemple #16
0
 def set_game_state(self, message, robot_name):
     self.game_state = State.from_dict(message)
     self.state.players = self.game_state.robots
     for robot in self.state.players:
         if robot.name == robot_name:
             self.state.robot = robot
             index = self.state.players.index(robot)
             del self.state.players[index]
Exemple #17
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)
Exemple #18
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
def test_robot_walk(input_coordinates, input_direction, distance, output_coordinates):
    """
    Take robot's coordinates, direction and distance and assert robot walked
    to correct coordinates.
    """
    state = State.get_start_state("maps/test_maps/test_3.json")
    robot = Robot(input_direction, input_coordinates, "bender")
    robot.walk(distance, state, input_direction)
    assert robot.coordinates == output_coordinates
Exemple #20
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)
Exemple #21
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
Exemple #22
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
Exemple #23
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
def test_robot_move(input_coordinates, input_direction, distance, output_coordinates):
    """
    Take robot's coordinates, move's direction and distance and assert robot
    was moved to correct coordinates.
    """
    state = State.get_start_state("maps/test_maps/test_3.json")
    robot = Robot(Direction.N, input_coordinates, "bender")
    robot.move(input_direction, distance, state)
    assert robot.coordinates == output_coordinates
def test_find_another_robots_start_coordinates():
    """
    Don't change coordinates to the last ones when another robot
    stands on them, pick the previous ones.
    """
    state = State.get_start_state("maps/test_maps/test_3.json")
    state.robots[0].start_coordinates = [(3, 2), (1, 0), (5, 5)]
    state.robots[1].coordinates = (5, 5)
    state.robots[0].find_free_start(state)
    assert state.robots[0].coordinates == (1, 0)
Exemple #26
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
Exemple #27
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
Exemple #28
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
def test_robot_on_start_has_the_correct_direction():
    """
    When robot is created, his direction shoud be the same as the direction
    of start tile he stands on.
    Assert the direction is correcly initiated.
    """
    state = State.get_start_state("maps/test_maps/test_start_direction.json")
    for robot in state.robots:
        tile_direction = state.get_tiles(robot.coordinates)[0].direction
        assert robot.direction == tile_direction
def test_robots_order_on_start(robot_index, expected_coordinates):
    """
    The order of robots list should reflect their starting positions.
    First robot from the list stands on first start tile and so on.
    Assert the list is correcly created.
    Test to check the behaviour in Python 3.5.
    """
    state = State.get_start_state("maps/test_maps/test_start_direction.json")
    current_robot = state.robots[robot_index]
    assert current_robot.coordinates == expected_coordinates