Example #1
0
def main(Expected1, Expected2, Dispersion1, Dispersion2, Number1, Number2,
         accuracy):
    fig = pb.figure()
    data, axes = support.gen_data1(Expected1, Expected2, Dispersion1,
                                   Dispersion2, Number1, Number2, fig)
    l_regression = reg.LogisticRegression()
    l_regression.fit(data)

    weights_by_grad = np.zeros(Expected1.shape[0] + 1)
    weights_by_grad, N = l_regression.find_weights(weights_by_grad, accuracy)

    weights_by_scipy = np.zeros(Expected1.shape[0] + 1)
    weights_by_scipy = minimize(l_regression.Q,
                                weights_by_scipy,
                                method='nelder-mead')

    norma2 = map(lambda x: x * x, weights_by_scipy.x)
    norma2 = math.sqrt(reduce(lambda x, y: x + y, norma2))
    weights_by_scipy.x /= norma2

    #print weights_by_grad, weights_by_scipy.x

    support.draw(weights_by_grad, 'black', axes)
    support.draw(weights_by_scipy.x, 'yellow', axes)
    pb.show()
    return N
Example #2
0
def create_zone(zone):
    field = open(zone, 'r')
    global wall_list
    global not_wall_list
    wall_list = []
    not_wall_list = []
    y = 220
    for line in field:
        x = -398
        for block in line:
            if block == '1':
                wall_list.append(support.draw('square', 1, '#f7d4ab', x, y))
            elif block == '0':
                not_wall_list.append([x, y])
            x += 8.3
        y -= 16.3
Example #3
0
def create_shooter_two():
    shot_two = draw('square', 0.16, '#a83232', tank.two.xcor(),
                    tank.two.ycor())
    shot_two.setheading(tank.two.heading())
    shot_two.forward(20)
    shot_two_list.append(shot_two)
Example #4
0
def create_shooter_one():
    shot_one = draw('square', 0.16, '#2441a1', tank.one.xcor(),
                    tank.one.ycor())
    shot_one.setheading(tank.one.heading())
    shot_one.forward(20)
    shot_one_list.append(shot_one)
Example #5
0
def victory(player_num):
    hud_victory = support.draw(None, None, 'white', 0, -15)
    hud_victory.hideturtle()
    support.write(hud_victory, 'PLAYER {} WINS!!!'.format(player_num))
    support.play_victory()
    close_screen()
Example #6
0
    # primeiro tanque
    screen.onkeypress(tank.rotate_left_1, 'a')
    screen.onkeypress(tank.rotate_right_1, 'd')
    screen.onkeypress(tank.go_ahead_1, 'w')
    screen.onkeypress(bullet.shooter_one, 'space')
    # segundo tanque
    screen.onkeypress(tank.rotate_left_2, 'Left')
    screen.onkeypress(tank.rotate_right_2, 'Right')
    screen.onkeypress(tank.go_ahead_2, 'Up')
    screen.onkeypress(bullet.shooter_two, 'o')
    # sair do jogo
    screen.onkeypress(close_screen, 'Escape')


# criação do painel da pontuação
hud_score = support.draw('square', 1, 'white', 0, 250)
hud_score.hideturtle()
support.write(hud_score, '0 : 0')
score_1 = score_2 = 0


# colisão dos projéteis com o labirinto
def wall_collision(shot_list):
    for proj in shot_list:
        for wall in wall_list:
            if (wall.distance(proj)) <= 15:
                proj.hideturtle()
                del (proj)
                break