public IEnumerable <ICommand> Solve()
        {
            var state = new DeluxeState(source, target);
            var disassembleCommands = disassembler.Solve().Where(c => !(c is Halt)).ToList();

            new Interpreter(state).RunPartially(disassembleCommands);
            var idMap            = GetIdMap(state);
            var assembleCommands = GetAssembleCommands(idMap);

            return(disassembleCommands.Concat(assembleCommands));
        }
        private IEnumerable <ICommand> GetAssembleCommands(int[] idMap)
        {
            var ticks         = new List <List <(int bid, ICommand command)> >();
            var state         = new DeluxeState(null, target);
            var originalTrace = new Queue <ICommand>(assembler.Solve());

            while (originalTrace.Any())
            {
                state.StartTick();
                var tick = new List <(int bid, ICommand command)>();
                foreach (var bot in state.Bots.OrderBy(b => b.Bid))
                {
                    var command = originalTrace.Dequeue();
                    state.SetBotCommand(bot, command);
                    tick.Add((bot.Bid, command));
                }
                ticks.Add(tick.OrderBy(t => idMap[t.bid]).ToList());
                state.EndTick();
            }
            return(ticks.SelectMany(t => t.Select(botCommand => botCommand.command)));
        }
Ejemplo n.º 3
0
        public IEnumerable <ICommand> Solve()
        {
            var commands = new Queue <ICommand>(assembler.Solve());

            return(ReverseCommands(commands, targetMatrix, sourceMatrix));
        }