Exemple #1
0
def test_matrix():
    name = 'LA004_tgt.mdl'
    data = data_files.lightning_problem(name)
    m = Matrix.parse(data)
    assert m.R == 20

    print(f'Central vertical slice of {name}')
    print('with a blip in the bottom left corner')
    print('and a hole in the middle')
    x = m.R // 2

    m0 = Matrix(m)
    assert m0 == m
    assert m.num_full == 559
    m[Pos(m.R // 2, 1, 1)] = True
    assert m.num_full == 560
    assert m0 != m
    m[Pos(m.R // 2, 4, 8)] = False
    assert m.num_full == 559

    for y in reversed(range(m.R)):
        s = []
        for z in range(m.R):
            if m[Pos(x, y, z)]:
                s.append('*')
            else:
                s.append('.')
        print(' '.join(s))

    assert m.count_inside_region(Pos(0, 0, 0), Pos(m.R - 1, m.R - 1,
                                                   m.R - 1)) == 559
def main():
    from production import data_files

    name = 'LA004'
    m = Model.parse(data_files.lightning_problem(f'{name}_tgt.mdl'))

    trace_name = f'{name}.nbt'
    trace = parse_commands(buf=data_files.lightning_default_trace(trace_name),
                           source=trace_name)

    state = State(m.R)
    state.time_step(trace)
Exemple #3
0
def main():
    from production import data_files

    name = 'LA004_tgt.mdl'
    data = data_files.lightning_problem(name)
    m = Model.parse(data)

    print(f'Central vertical slice of {name}:')
    x = m.R // 2
    for y in reversed(range(m.R)):
        s = []
        for z in range(m.R):
            if m[Pos(x, y, z)]:
                s.append('*')
            else:
                s.append('.')
        print(' '.join(s))
    print('R =', m.R)
        yield Cmd.Halt()

    def solve_gen(self, model: 'Model'):
        self.commands = iter([])
        self.state = State(model.R)

        voxels_to_fill = breadth_first_search(floor_contact(model),
                                              filled_neighbors(model))

        for voxel in voxels_to_fill:
            current_position = self.state.bots[0].pos
            self.add_commands(navigate_near_voxel(current_position, voxel))
            current_position = self.state.bots[0].pos
            self.add_commands([Cmd.Fill(voxel - current_position)])

        self.add_commands(self.finish())
        return self.commands


if __name__ == '__main__':
    task_number = int(sys.argv[1]) if len(sys.argv) > 1 else 1

    name = 'LA{0:03d}_tgt.mdl'.format(task_number)
    data = data_files.lightning_problem(name)
    m = Model.parse(data)

    with open('LA{0:03d}.nbt'.format(task_number), 'wb') as f:
        solver = BFSSolver(None)
        for cmd in solver.solve_gen(m):
            f.write(bytearray(cmd.compose()))