示例#1
0
 public TwistEffect()
 {
     EffectData = new TwistData ();
 }
示例#2
0
 public TwistEffect()
 {
     EffectData = new TwistData();
 }
示例#3
0
        public static void SaveScript(Puzzle puzzle)
        {
            string filename = Loader.GetSaveFileName(m_filter);

            if (string.IsNullOrEmpty(filename))
            {
                return;
            }

            // Get the existing state, so we don't have to clobber the one in the puzzle.
            XElement xState = new XElement("State");

            puzzle.State.SaveToXml(xState);
            State state = new State(puzzle.State.NumCells, puzzle.State.NumStickers);

            state.LoadFromXml(xState);

            // Get all the generators.
            List <Generator> generators = new List <Generator>();

            foreach (IdentifiedTwistData itd in puzzle.AllTwistData)
            {
                TwistData td = itd.TwistDataForStateCalcs.First();

                // NOTE: We use NumSlicesNoOpp rather than NumSlices on purpose,
                // to avoid problems in the group definition for spherical puzzles.
                for (int slice = 0; slice < td.NumSlicesNoOpp; slice++)
                {
                    SingleTwist twist = new SingleTwist()
                    {
                        IdentifiedTwistData = itd,
                        SliceMask           = 1 << slice
                    };

                    state.Reset();
                    var updated = Puzzle.UpdateState(puzzle.Config, state, twist);
                    HashSet <Sticker> allStickers = new HashSet <Sticker>(updated.Keys.ToArray());

                    List <Cycle>          cycles          = new List <Cycle>();
                    HashSet <List <int> > completedCycles = new HashSet <List <int> >(new SkewPolyhedron.CycleEqualityComparer());
                    int numCycles = updated.Count / td.Order;
                    for (int c = 0; c < numCycles; c++)
                    {
                        Sticker start = allStickers.First();
                        allStickers.Remove(start);

                        List <int> cycle = new List <int>();
                        cycle.Add(GetStickerId(state, start));
                        for (int t = 0; t < td.Order - 1; t++)
                        {
                            Sticker next = updated[start];
                            cycle.Add(GetStickerId(state, next));
                            allStickers.Remove(next);
                            start = next;
                        }

                        // On hyperbolic puzzles, we can get duplicates.
                        if (!completedCycles.Add(cycle))
                        {
                            continue;
                        }
                        cycles.Add(new Cycle(cycle.ToArray()));
                    }

                    generators.Add(new Generator()
                    {
                        Cycles = cycles
                    });
                }
            }

            // Write everything out.
            using (StreamWriter sw = new StreamWriter(filename))
            {
                sw.WriteLine("puzzle := Group(");
                SaveCycleList(sw, generators);
                sw.WriteLine(");");
                sw.WriteLine("size := Size( puzzle );");
                sw.WriteLine("Print( size );");
                sw.WriteLine("Print( \"\\n\" );");
                sw.WriteLine("Print( Collected( Factors( size ) ) );");
                //sw.WriteLine( "Print( StructureDescription( puzzle ) );" );
            }
        }