Exemplo n.º 1
0
                                              instr.ndz).set_fd(
                                                  instr.fdx, instr.fdy,
                                                  instr.fdz)
            elif klass in (commands.Fission, commands.FusionP,
                           commands.FusionS):
                # we've intercepted and modified these in advance
                result.append(instr)

            elif klass == commands.Halt:
                # we've reached the end
                end = True

        bots.extend(new_bots)
        for b in dead_bots:
            bots.remove(b)
        time += 1

    return reversed(result)


if __name__ == '__main__':
    problem = int(sys.argv[1])
    f = open('submission/FA{:03d}.nbt'.format(problem), 'rb').read()
    cmds = commands.read_nbt(f)
    res = unprint(cmds)

    data = commands.export_nbt(res)
    g = open('submission/FD{:03d}.nbt'.format(problem), 'wb')
    g.write(data)
    g.close()
Exemplo n.º 2
0
if __name__ == '__main__':

    def parse():
        try:
            return int(sys.argv[1])
        except:
            return 1

    prob = parse()
    st = state.State.create(problem=prob)
    brain = ScanBrain(st)
    while brain.step():
        st.step()

    print(st)
    filename = "submission/LA%03d.nbt" % prob
    sys.stderr.write('{}: {}\n'.format(filename, st.score))
    print('{}: energy: {}, default: {}, score: {:0.3f}/{:0.3f}'.format(
        filename, st.energy, st.default_energy, st.score, st.score_max))
    with open(filename, "wb") as file:
        file.write(commands.export_nbt(st.trace))

# scores (problem time/energy)
# 1 878 / 21098000
# 2 333 / 8001940
# 3  437 / 10500892
# 4 (crash; ungrounded)
# 5 1936 / 46520988
# 6 1411 / 33903292
# 7 3087 / 74179928
Exemplo n.º 3
0
    bot = st.bots[0]

    for bot2 in st.bots[1:]:
        for a in bot.pos.adjacent(st.R):
            if st.matrix[a].is_void():
                path = shortest_path(st, bot2, a)
                if path is not None:
                    print("found path")
                    compress(st, bot2, path)
                    break
        st.step_all()
        bot.fusionp(bot2.pos - bot.pos)
        bot2.fusions(bot.pos - bot2.pos)
        st.step_all()

    # shortest_path_algo(st)
    back_to_base(st, bot)
    bot.halt()

    while st.step():
        pass

    print(st)
    print('energy: {}, default: {}, score: {:0.3f}/{:0.3f}'.format(
        st.energy, st.default_energy, st.score, st.score_max))
    data = commands.export_nbt(st.trace)
    with open("submission/FD" + str(problem).zfill(3) + suffix + ".nbt",
              "wb") as file:
        file.write(data)
Exemplo n.º 4
0
 def test_roundtrip(self):
     with open('dfltTracesL/LA095.nbt', 'rb') as f:
         data = f.read()
         cmds = commands.read_nbt_iter(data)
         out = commands.export_nbt(cmds)
         self.assertEqual(data, out)