Beispiel #1
0
    def test_handle_command(self):
        with patch("sys.stdout", new=StringIO()) as var:
            robot.handle_command("el", "replay")
            output = var.getvalue().strip()
            self.assertEqual(
                output, """> el replayed 0 commands.
> el now at position (0,0).""")
Beispiel #2
0
def maze_runner(robot, arg):
    global mazerun_mode
    mazerun_mode = True

    if arg == '':
        arg = 'top'

    print(f' > {robot} starting maze run..')
    if arg.lower().strip() == "top" or arg.lower().strip() == "":
        for x in itertools.repeat(1):
            # if arg.lower().strip() == "top" or arg.lower().strip() == "":
            if (world.text.world.position_y == 200
                    if robot.module_to_use is False else
                    world.turtle.world.position_y == 200):
                break
            if left():
                robot.handle_command(robot, "left")
            if forward():
                robot.handle_command(robot, "forward 20")
            else:
                robot.handle_command(robot, "right")
    if arg.lower().strip() == "bottom":
        return bottom_side(robot, arg)

    if arg.lower().strip() == "right":
        return right_side(robot, arg)
    if arg.lower().strip() == "left":
        return left_side(robot, arg)

    mazerun_mode = False
    return True, " > " + robot + " I am at the " + arg + " edge."
Beispiel #3
0
def right_side(robot, arg):
    # for x in itertools.repeat(1):
    if (world.text.world.position_x == 100 if robot.module_to_use is False else
            world.turtle.world.position_x == 100):
        return True, " > " + robot + " I am at the " + arg + " edge."
    if left():
        robot.handle_command(robot, "left")
    if forward():
        robot.handle_command(robot, "forward 20")
    else:
        robot.handle_command(robot, "right")
    return right_side(robot, arg)
Beispiel #4
0
 def test_handle_command(self):
     robot_name = "KYLE"
     command = "left"
     do_next = True
     self.assertEqual(r.handle_command(robot_name, command), do_next)
Beispiel #5
0
 def test_commands_exist(self):
     self.assertFalse(robot.handle_command('hal','off'),False)
Beispiel #6
0
def start_moving(robot_name):
	global escaped
	escaped = False
	while not escaped:
		while is_pos_block() and not out_of_bounds():
			if check_been_before()
			robot.handle_command(robot_name,"forward 1")
			escaped = check_escaped()

		
		if right_not_blocked() and not check_in_right_turns():
			robot.handle_command(robot_name,"right")
			add_to_right_turns()
		elif left_not_blocked() and not check_in_left_turns():
			robot.handle_command(robot_name,"left")
		elif not left_not_blocked() and check_in_right_turns():
			robot.handle_command(robot_name,"right")
		elif check_in_left_turns() and check_in_right_turns():
			robot.handle_command(robot_name,"right")
			robot.handle_command(robot_name,"right")
			remove_pos()
Beispiel #7
0
def mazerun_y(name):
    """
    """
    print(' > ' + name + ' starting maze run..')
    while not next_blocked() and not next_out_of_bounds():
        robot.handle_command(name, 'forward 1')
    while world.position_y != end_y:
        if next_blocked() or next_out_of_bounds():
            if (world.position_x, world.position_y) not in stored_left_turns:
                stored_left_turns.add((world.position_x, world.position_y))
                robot.handle_command(name, 'left')
            elif (world.position_x, world.position_y) not in stored_right_turn:
                stored_right_turn.add((world.position_x, world.position_y))
                robot.handle_command(name, 'right')
            else:
                robot.handle_command(name, 'left')
                robot.handle_command(name, 'left')
                stored_left_turns.discard((world.position_x, world.position_y))
                stored_right_turn.discard((world.position_x, world.position_y))
        elif not right_blocked():
            if (world.position_x, world.position_y) not in stored_right_turn:
                stored_right_turn.add((world.position_x, world.position_y))
                robot.handle_command(name, 'right')
            elif (world.position_x, world.position_y) not in stored_forward:
                stored_forward.add((world.position_x, world.position_y))
                while not next_blocked() and not next_out_of_bounds():
                    robot.handle_command(name, 'forward 1')
            elif (world.position_x, world.position_y
                  ) not in stored_left_turns and not right_blocked():
                stored_left_turns.add((world.position_x, world.position_y))
                robot.handle_command(name, 'left')
            else:
                robot.handle_command(name, 'right')
                robot.handle_command(name, 'forward 1')
                stored_forward.discard((world.position_x, world.position_y))
                stored_left_turns.discard((world.position_x, world.position_y))
                stored_right_turn.discard((world.position_x, world.position_y))
        else:
            robot.handle_command(name, 'forward 1')