Ejemplo n.º 1
0
    def test_apply_robot_instructions(
        self,
        robot_position,
        instructions,
        final,
    ):
        grid = Grid(5, 5)
        grid.generate_robot(*robot_position)

        grid.apply_robot_instructions(instructions)

        assert grid.robots[0].pos() == final
Ejemplo n.º 2
0
def main():
	print('*** Welcome to the Mars Robots Guide! ***\n')
	print('Here are the computed outputs:\n')

	with open('robots_guide.in.md') as f:
		lines = f.readlines()

	grid_size = lines[0]

	if not grid_size:
		return

	grid_size = grid_size.split(' ')

	max_x_axis = int(grid_size[0])
	max_y_axis = int(grid_size[1])

	if max_x_axis > 50 or max_y_axis > 50:
		raise CustomExceptions.InvalidGridRangeError(max_x_axis, max_y_axis)

	grid = Grid(
		x=max_x_axis,
		y=max_y_axis,
	)

	updated_lines = lines.pop(0) 		# upper-right coordinates of the rectangular world
	robots_seed_positions = lines[::2]	# Robots initial position
	robots_instructions = lines[1::2]	# Robots instructions

	for position, instruction in zip(robots_seed_positions, robots_instructions):
		robot_initial_pos = position.strip('\n')

		if not robot_initial_pos:
			break

		robot_instruction = instruction

		robot_initial_pos = robot_initial_pos.split(' ')
		grid.generate_robot(
			x=int(robot_initial_pos[0]),
			y=int(robot_initial_pos[1]),
			orientation=robot_initial_pos[2],
		)
		grid.apply_robot_instructions(robot_instruction)
	f.close()
Ejemplo n.º 3
0
    def test_apply_robot_instructions_with_empty_grid(self):
        grid = Grid(5, 5)

        grid.apply_robot_instructions('')

        assert not grid.robots