예제 #1
0
def test_run_part_1():
    example = [0, 3, 0, 1, -3]
    runner = run(example, part_1_modifier)

    # First step
    assert next(runner) == (0, 0)
    assert example == [1, 3, 0, 1, -3]

    # Second step
    assert next(runner) == (0, 1)
    assert example == [2, 3, 0, 1, -3]

    # third step
    assert next(runner) == (1, 3)
    assert example == [2, 4, 0, 1, -3]

    # fourth step
    assert next(runner) == (4, -3)
    assert example == [2, 4, 0, 1, -2]

    # fifth, and final step
    assert next(runner) == (1, 4)
    assert example == [2, 5, 0, 1, -2]

    # there should not be any other operations at this point
    assert list(runner) == []
예제 #2
0
파일: lego.py 프로젝트: s4ln1x/uag
def server():
    """Server that waits for instructions

    """
    kill = False
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        lego = lego_tank()
        s.bind((HOST, PORT))
        s.listen()
        conn, addr = s.accept()
        with conn:
            print("Connected by", addr)
            while True:
                data = conn.recv(1024)
                for s in data.decode('utf-8').split():
                    if s == 'left':
                        lego.left()
                    elif s == 'right':
                        lego.right()
                    elif s == 'forward':
                        lego.forward()
                    elif s == 'backward':
                        lego.backward()
                    elif s == 'run':
                        commands = run(True)
                        for command in commands:
                            comando = command.decode('utf-8')
                            if comando == 'left':
                                lego.left()
                            elif comando == 'right':
                                lego.right()
                            elif comando == 'forward':
                                lego.forward()
                            elif comando == 'backward':
                                lego.backward()
                            elif comando == 'finish':
                                break
                        kill = True
                    elif s == 'finish':
                        break
                try:
                    if kill:
                        conn.sendall(b"kill")
                        break
                    else:
                        conn.sendall(b"done")
                except:
                    print("Connection finished")
                    break
            try:
                lego.sound.speak(
                    "I finished with my orders commander in chief")
            except:
                print("I finished with my orders commander in chief")
예제 #3
0
def test_run():
    simple = [1, 1, 1]
    copy = simple[:]
    runner = run(copy)

    # first step, index 0, jump one ahead (to 1)
    assert next(runner) == (0, 1)

    # second step, index 1, jump one ahead (to 2)
    assert next(runner) == (1, 1)

    # One instruction left: index 2, jump one ahead (done)
    assert list(runner) == [
        (2, 1),
    ]

    # The program should not have been modified
    assert simple == copy
예제 #4
0
#import rgb
count = 1
robot.compass.Start()
robot.camera.start()
maxSpeed = 1
try:
    while True:
        count -= 1
        if count == 0:
            print("attempting initiation")
            count = 100000
        if robot.controller.A():
            if robot.controller.dpadDown():
                reverse = robot.reverse
                robot.reverse = 0
                maze.run()
                robot.reverse = reverse
            elif robot.controller.dpadLeft():
                robot.reverse = 0
                nebula.run()
            elif robot.controller.dpadRight():
                robot.reverse = 0
                speedTest.run()
            elif robot.controller.dpadUp():
                #rgb.toggle()
                #gun stuff
                pass

        if robot.controller.connected():
            if robot.controller.dpadUp():
                maxSpeed = min(1, maxSpeed + 0.1)
예제 #5
0
def test_run_part_2():
    example = [0, 3, 0, 1, -3]
    runner = run(example, part_2_modifier)

    assert count_steps(runner) == 10
    assert example == [2, 3, 2, 3, -1]