Esempio n. 1
0
        public List <ICommand> MakeReassemblyTrace(TModel srcModel, TModel tgtModel)
        {
            Fill doFill = new Fill();

            doFill.Diff.Dy = -1;

            Void doVoid = new Void();

            doVoid.Diff.Dy = -1;

            var result = new List <ICommand>();

            result.Add(new Flip());

            var current          = new TCoord();
            var dumpCureTraverse = new TDumpCubeTraverse(srcModel, tgtModel);

            TState          state = new TState(srcModel);
            List <ICommand> ss    = new List <ICommand>();

            var iteration = 0;

            while ((iteration == 0) || !current.IsAtStart())
            {
                var next = dumpCureTraverse.Next();

                if (srcModel[next] > 0)
                {
                    Void curVoid = new Void();
                    curVoid.Diff = dumpCureTraverse.GetDirection();
                    result.Add(curVoid);

                    {
                        if (ss.Count == 0)
                        {
                            ss.Add(curVoid);
                        }
                        else
                        {
                            ss[0] = curVoid;
                        }
                        ss.Add(curVoid);
                        TCommandsReader cr = new TCommandsReader(ss);
                        state.Step(cr);
                    }
                }

                var move = new StraightMove();
                move.Diff = dumpCureTraverse.GetDirection();
                result.Add(move);

                {
                    if (ss.Count == 0)
                    {
                        ss.Add(move);
                    }
                    else
                    {
                        ss[0] = move;
                    }

                    TCommandsReader cr = new TCommandsReader(ss);
                    state.Step(cr);
                }

                if ((next.Y > 0) && (tgtModel[next.X, next.Y - 1, next.Z] > 0) && state.Matrix[next.X, next.Y - 1, next.Z] == 0)
                {
                    result.Add(doFill);
                    {
                        if (ss.Count == 0)
                        {
                            ss.Add(doFill);
                        }
                        else
                        {
                            ss[0] = doFill;
                        }
                        TCommandsReader cr = new TCommandsReader(ss);
                        state.Step(cr);
                    }
                }
                if ((next.Y > 0) && (tgtModel[next.X, next.Y - 1, next.Z] == 0) && state.Matrix[next.X, next.Y - 1, next.Z] > 0)
                {
                    result.Add(doVoid);
                    {
                        if (ss.Count == 0)
                        {
                            ss.Add(doVoid);
                        }
                        else
                        {
                            ss[0] = doVoid;
                        }

                        TCommandsReader cr = new TCommandsReader(ss);
                        state.Step(cr);
                    }
                }

                current = next;
                ++iteration;
            }

            result.Add(new Flip());
            result.Add(new Halt());

            return(result);
        }
Esempio n. 2
0
        public List <ICommand> MakeTrace(TModel src, TModel model)
        {
            if (src.NumFilled != 0)
            {
                return(null);
            }

            ICommand modifyCommand = new Fill();

            ((Fill)modifyCommand).Diff.Dy = -1;
            if (model.Name.Contains("FD"))
            {
                modifyCommand = new Void();
                ((Void)modifyCommand).Diff.Dy = -1;
            }

            //      TState state = new TState(model);

            var result = new List <ICommand>();

            result.Add(new Flip());

            var current          = new TCoord();
            var dumpCureTraverse = new TDumpCubeTraverse(model);

            var iteration = 0;

            while ((iteration == 0) || !current.IsAtStart())
            {
                if (iteration == 295)
                {
                    int a = 0;
                }

                var next = model.Name.Contains("FA") ? dumpCureTraverse.Next() : dumpCureTraverse.NextDestroy();
                var move = new StraightMove();
                move.Diff = dumpCureTraverse.GetDirection();
                result.Add(move);
                //               {
                //                   List<ICommand> ss = new List<ICommand>();
                //                 ss.Add(move);
                //                 TCommandsReader cr = new TCommandsReader(ss);
                //                 state.Step(cr);
                //             }

                if ((next.Y > 0) && (model[next.X, next.Y - 1, next.Z] > 0))
                {
                    result.Add(modifyCommand);
                    //              {
                    //                  List<ICommand> ss = new List<ICommand>();
                    //                 ss.Add(move);
                    //                 TCommandsReader cr = new TCommandsReader(ss);
                    //                 state.Step(cr);
                    //            }
                }

                current = next;
                ++iteration;
            }

            result.Add(new Flip());
            result.Add(new Halt());

            return(result);
        }