Exemple #1
0
def run():
    global world

    sleep(0.1)
    Popen('run_serv.bat')
    sleep(0.1)

    EPS = 1e-2

    # TODO: may be circle isn't the best path? or not path at all, dynamic direction calculation
    # about 1000 runs with different rpath showed that 0.42 is the best, but diff isn't great
    global rpath
    rpath = 0.42
    floats = [x / 20 for x in range(-20, 21)]
    path = [vec(0.5, 0.5) + vec(x, sqrt(1 - x ** 2)) * rpath for x in floats]
    path += [vec(0.5, 0.5) + vec(x, -sqrt(1 - x ** 2)) * rpath for x in reversed(floats[1:-1])]

    world = World()
    world.make_move()

    were104 = False

    try:
        while True:
            world.make_move()

            move_path(path)

            mons = [mon for mon in world.monsters if mon.ClassName != -1]
            if len(mons) == 0:
                continue


#            ms = [(calc_time_approx(m), m) for m in mons]
#            if len(ms) > 10:
#                ms = ms[:10]
#            sum_next = sum(t for t, m in ms)
#
#            ms = [(calc_time_approx(m, True), m) for m in mons]
#            if len(ms) > 10:
#                ms = ms[:10]
#            sum_prev = sum(t for t, m in ms)
#
#            if sum_next < sum_prev:
#                print(sum_prev - sum_next)
#                path = path[::-1]

            ids = {mon.ClassName for mon in mons}
            if ids == {104}:
                were104 = False
                for mon in mons:
                    shoot(mon)
                    move_path(path)
                    world.make_move()
                    shoot(mon)
                    move_path(path)
                    world.make_move()
            elif 104 in ids and not were104:
                were104 = True
                for mon in (m for m in mons if m.ClassName == 104):
                    shoot(mon)
                    move_path(path)
                    world.make_move()
                    shoot(mon)
                    move_path(path)
                    world.make_move()
            else:
                nearest_mon = min(mons, key = calc_time_approx)
                shoot(nearest_mon)
    except socket.error:
        return int(open('score.txt').read())