Exemplo n.º 1
0
def cosine_slope():
    turtle.setworldcoordinates(-6.2, -12, 6.2, 12)
    f = lambda x: -x + 5 * math.cos(x)
    demo = Demo(f)
    demo.start(-6)
    demo.bag([x * 0.1 for x in range(-62, 62)])
    gen = hill_climb.seek(-6, 0.1, f)
    for x, y in gen:
        demo.move(x, y, False)
Exemplo n.º 2
0
def quadratic():
    turtle.setworldcoordinates(-12, -2, 12, 102)
    f = lambda x: x**2
    demo = Demo(f)
    demo.start(-10)
    demo.bag([x * 0.5 for x in range(-20, 21)])
    gen = hill_climb.seek(-10, 0.5, f)
    for x, y in gen:
        demo.move(x, y, False)
Exemplo n.º 3
0
def sa_demo(curr_x, step, f, temperature, x_points, min_x, max_x, *setup):
    turtle.setworldcoordinates(*setup)
    demo = Demo(f)
    demo.start(curr_x)
    demo.bag(x_points)
    gen = sim_anneal.seek(curr_x, step, f, temperature, min_x, max_x)
    for x, y, t, j in gen:
        demo.move(x, y, j)
        curr_x = x
    print(curr_x, f(curr_x))
Exemplo n.º 4
0
def slanty_bag():
    turtle.setworldcoordinates(-2.2, -2, 12.2, 22)
    demo = Demo(slanty_bag_curve)
    demo.bag([x * 0.5 for x in range(-1, 22)])

    x = -0.5
    step = 0.1
    demo.start(x)
    gen = hill_climb.seek(x, step, slanty_bag_curve)
    for x, y in gen:
        demo.move(x, y, False)
Exemplo n.º 5
0
def stuck():
    turtle.setworldcoordinates(-12, -1, 12, 15)
    f = lambda x: math.fabs(x)
    demo = Demo(f)
    start = -10
    step = 3
    demo.start(start)
    demo.bag(range(-10, 11))
    gen = hill_climb.seek(start, step, f)
    for x, y in gen:
        demo.move(x, y, False)
Exemplo n.º 6
0
def background_thread():
    """Demo ball."""
    ball = Demo()
    while True:
        time.sleep(0.01)
        ball.move()
        data = 'Player "%s" (%s) moved to %s.' % (ball.nick, ball.color,
                                                  ball.short_coords())
        socketio.emit('response',
                      {
                          'data': data,
                          # 'count': count,
                      },
                      namespace='/test')