def create_card_pack(): """ Create pack of cards: 42 movement cards and 42 rotation cards with different values and priorities. Return shuffled card pack. """ movement_cards = [ (-1, 6, 250), (1, 18, 300), (2, 12, 400), (3, 6, 500), ] rotation_cards = [ (Rotation.U_TURN, 6, 50), (Rotation.LEFT, 18, 100), (Rotation.RIGHT, 18, 200), ] card_pack = [] for movement, cards_count, first_number in movement_cards: for i in range(cards_count): # [MovementCard(690, -1)...][] card_pack.append(MovementCard(first_number + i * 5, movement)) for rotation, cards_count, first_number in rotation_cards: for i in range(cards_count): # [RotationCard(865, Rotation.LEFT)....] card_pack.append(RotationCard(first_number + i * 5, rotation)) shuffle(card_pack) return card_pack
def create_card_pack(): movement_cards = [ (-1, 6, 250), (1, 18, 300), (2, 12, 400), (3, 6, 500), ] rotation_cards = [ (Rotation.U_TURN, 6, 50), (Rotation.LEFT, 18, 100), (Rotation.RIGHT, 18, 200), ] card_pack = [] for movement, cards_count, first_number in movement_cards: for i in range(cards_count): card_pack.append( MovementCard(first_number + i * 5, movement)) # [MovementCard(690, -1)...][] for rotation, cards_count, first_number in rotation_cards: for i in range(cards_count): card_pack.append(RotationCard( first_number + i * 5, rotation)) # [RotationCard(865, Rotation.LEFT)....] shuffle(card_pack) print(card_pack) return card_pack
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
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
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 = get_start_state("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 = get_robots_ordered_by_cards_priority(state, 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 = get_robots_ordered_by_cards_priority(state, 1) assert robot_cards[0][0].program[1].priority == 350 assert robot_cards[7][0].program[1].priority == 80
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 @pytest.mark.parametrize(("direction", "card", "new_coordinates"), [(Direction.E, MovementCard(100, 1), (5, 7)), (Direction.E, MovementCard(100, 2), (6, 7)), (Direction.E, MovementCard(100, 3), (7, 7)), (Direction.E, MovementCard(100, -1), (3, 7)), (Direction.S, MovementCard(100, 1), (4, 6)), (Direction.S, MovementCard(100, 2), (4, 5)), (Direction.S, MovementCard(100, 3), (4, 4)), (Direction.S, MovementCard(100, -1), (4, 8)), (Direction.N, MovementCard(100, -1), (4, 6)), (Direction.W, MovementCard(100, -1), (5, 7)), ]) def test_move_cards(direction, card, new_coordinates): """ Give mock robot the MovementCard and check if he moved to the expected coordinates. Check if the robot's direction remained the same. """
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) @pytest.mark.parametrize(("card", "new_coordinates"), [(MovementCard(100, 1), (5, 6)), (MovementCard(100, 2), (5, 7)), (MovementCard(100, 3), (5, 8)), (MovementCard(100, -1), (5, 4)), ]) def test_move_cards(card, new_coordinates): """ Give mock robot the MovementCard and check if he moved to the expected coordinates. """ robot = Robot(Direction.N, None, None, (5, 5)) robot.program = [card] state = get_start_state("maps/test_3.json") robot.apply_card_effect(state) assert robot.coordinates == new_coordinates