Esempio n. 1
0
        internal void DebugPrint(TextWriter tw)
        {
            tw.WriteLine("Base Axis {0}", Id);
            tw.Write("  Dir:");
            PuzzleStructure.PrintVec(Dir, tw, false);
            tw.WriteLine();
            tw.Write("  NLayers: {0}", NLayers);
            tw.Write("  FixedMask: {0}", FixedMask);
            tw.Write("  Cut:");
            PuzzleStructure.PrintVec(Cut, tw, false);
            tw.WriteLine();

            /*
             * for(int i=0;i<NLayers;i++){
             *  if(Layers[i]!=null){
             *      tw.Write("  Layer {0}:",i);
             *      PuzzleStructure.PrintIArr(Layers[i],tw);
             *      tw.WriteLine();
             *  }
             * }*/
            tw.WriteLine("  Twists: {0}", Twists.Length);

            /*
             * foreach(PBaseTwist tww in Twists){
             *  tww.DebugPrint(tw);
             * }*/
        }
Esempio n. 2
0
        internal void DebugPrint(TextWriter tw)
        {
            tw.WriteLine("Base Face {0}:", Id);
            tw.Write("  Pole:");
            PuzzleStructure.PrintVec(Pole, tw, false);
            tw.WriteLine();
            tw.WriteLine("  NCutAxes: {0}", NCutAxes);
            tw.Write("  CutAxes:");
            PuzzleStructure.PrintIArr(CutAxes, tw);
            tw.WriteLine();

            /*
             * tw.Write("  AxesLayers:");
             * PuzzleStructure.PrintIArr(AxisLayers,tw);
             * tw.WriteLine();*/
            tw.WriteLine("  NStickers: {0}", NStickers);
            for (int i = 0; i < NStickers; i++)
            {
                tw.Write("Sticker {0}: NV={1}, NE={2}, NF={3}, Ctr=",
                         i, StickerMesh[i].NV, StickerMesh[i].NE, StickerMesh[i].NF);
                PuzzleStructure.PrintVec(StickerMesh[i].Ctr, tw, false);
                tw.Write(" Mask:");
                for (int j = 0; j < NCutAxes; j++)
                {
                    tw.Write(" {0}", StickerMask[i, j]);
                }
                tw.WriteLine();
            }
        }
Esempio n. 3
0
 internal void DebugPrint(TextWriter tw)
 {
     tw.Write("  Twist");
     PuzzleStructure.PrintVec(Dir, tw, true);
     tw.WriteLine("    Order={0}", Order);
     tw.WriteLine("    Map:");
     for (int i = 0; i < Map.Length; i++)
     {
         if (Map[i] != null)
         {
             tw.Write("      Level {0}:", i);
             PuzzleStructure.PrintIArr(Map[i], tw);
             tw.WriteLine();
         }
     }
     tw.WriteLine("    InvMap:");
     for (int i = 0; i < InvMap.Length; i++)
     {
         if (InvMap[i] != null)
         {
             tw.Write("      Level {0}:", i);
             PuzzleStructure.PrintIArr(InvMap[i], tw);
             tw.WriteLine();
         }
     }
 }
Esempio n. 4
0
 internal void DebugPrint(TextWriter tw)
 {
     tw.WriteLine("Face {0}:", Id);
     tw.WriteLine("  Base: {0}", Base.Id);
     tw.Write("  Pole:");
     PuzzleStructure.PrintVec(Pole, tw, false);
     tw.WriteLine();
     tw.Write("  CutAxes:");
     PuzzleStructure.PrintIArr(CutAxes, tw);
     tw.WriteLine();
     tw.WriteLine("  First Sticker: {0}", FirstSticker);
 }
Esempio n. 5
0
 internal Puzzle(PuzzleStructure str)
 {
     Str        = str;
     NStk       = Str.NStickers;
     Field      = new short[NStk];
     Fld2       = new short[NStk];
     Seq        = new long[100000];
     LShuffle   = LSeq = Ptr = 0;
     NTwists    = 0;
     SetupStack = new int[100, 2];
     LStk       = 0;
     Reset();
 }
Esempio n. 6
0
        internal void DebugPrint(TextWriter tw)
        {
            tw.WriteLine("Axis {0}:", Id);
            tw.WriteLine("  Base: {0}", Base.Id);
            tw.Write("  Dir:");
            PuzzleStructure.PrintVec(Dir, tw, false);
            tw.WriteLine();

/*
 *          for(int i=0;i<Layers.Length;i++){
 *              if(Layers[i]!=null){
 *                  tw.Write("  Layer {0}:",i);
 *                  PuzzleStructure.PrintIArr(Layers[i],tw);
 *                  tw.WriteLine();
 *              }
 *          }
 *
 *          for(int i=0;i<Twists.Length;i++){
 *              tw.Write("  Twist {0}:",i);
 *              PuzzleStructure.PrintVec(Twists[i],tw,true);
 *              tw.WriteLine();
 *          }*/
        }
Esempio n. 7
0
        internal void Load(string fn)
        {
            StreamReader sr = null;

            try {
                sr = new StreamReader(fn);
                string[] head    = sr.ReadLine().Split(' ', '\t');
                bool     MyProg  = head[0] == "MPUltimate";
                bool     needGen = true;
                ulong    crc     = 0;
                long     T       = 0;
                string   Name;
                if (MyProg)
                {
                    Name     = head[2];
                    LSeq     = int.Parse(head[3]);
                    LShuffle = int.Parse(head[4]);
                    Ptr      = int.Parse(head[5]);
                    if (File.Exists(Name + ".pzl"))
                    {
                        try {
                            Str     = PuzzleStructure.ReadCompiled(Name + ".pzl");
                            needGen = false;
                        } catch { }
                    }
                }
                string[] ss = sr.ReadLine().Split(' ', '\t');
                if (ss[0] != "Puzzle")
                {
                    throw new Exception("Missing 'Puzzle' tag");
                }
                ArrayList dsc = new ArrayList();
                for (;;)
                {
                    string s0 = sr.ReadLine();
                    if (s0 == null)
                    {
                        throw new Exception("Missing 'EndPuzzle' tag");
                    }
                    if (s0 == "EndPuzzle")
                    {
                        break;
                    }
                    dsc.Add(s0);
                }
                if (needGen)
                {
                    Str = PuzzleStructure.Create(ss[1], (string[])dsc.ToArray(typeof(string)));
                    Str.SaveCompiled(ss[1] + ".pzl");
                }
                if (MyProg)
                {
                    ss = sr.ReadLine().Split(' ', '\t');
                    int nstk = int.Parse(ss[1]), lb = int.Parse(ss[0]);
                    Field = new short[nstk];
                    Fld2  = new short[nstk];
                    for (int k = 0; k < nstk;)
                    {
                        string s1 = sr.ReadLine();
                        int    nb = s1.Length / lb;
                        for (int i = 0; i < nb; i++)
                        {
                            Field[k++] = (short)GetBytes36(s1, i * lb, lb);
                        }
                    }
                    for (;;)
                    {
                        string s2 = sr.ReadLine();
                        if (s2 == "*")
                        {
                            break;
                        }
                        string[] ss2 = s2.Split(' ');
                        if (ss2[0] == "#timer")
                        {
                            T = long.Parse(ss2[1]);
                        }
                        if (ss2[0] == "#CRC")
                        {
                            crc = ulong.Parse(ss2[1]);
                        }
                    }
                    NStk = nstk;
                }
                else
                {
                    for (;;)
                    {
                        string s2 = sr.ReadLine();
                        if (s2 == "*" || s2 == null)
                        {
                            break;
                        }
                    }
                }
                Seq = new long[100000];
                int p = 0, ps = 0;
                for (;;)
                {
                    string s3 = sr.ReadLine();
                    if (s3 == null)
                    {
                        break;
                    }
                    bool qlast = s3.EndsWith(".");
                    if (qlast)
                    {
                        s3 = s3.Substring(0, s3.Length - 1);
                    }
                    string[] ss3 = s3.Split(' ', '\t');
                    foreach (string s4 in ss3)
                    {
                        if (p == Seq.Length)
                        {
                            long[] sq = new long[2 * p];
                            Buffer.BlockCopy(Seq, 0, sq, 0, p * sizeof(long));
                            Seq = sq;
                        }
                        if (s4 == null || s4 == "")
                        {
                            continue;
                        }
                        else if (s4 == "m[")
                        {
                            Seq[p++] = START_MACRO;
                        }
                        else if (s4 == "m]")
                        {
                            Seq[p++] = STOP_MACRO;
                        }
                        else if (s4 == "m|")
                        {
                            ps = p;
                        }
                        else
                        {
                            string[] s5 = s4.Split(':');
                            int      ax = int.Parse(s5[0]);
                            int      tw = int.Parse(s5[1]);
                            int      an = int.Parse(s5[2]);
                            int      ms = int.Parse(s5[3]);
                            an       = Str.Axes[ax].Base.Twists[tw].ReAngle(an); // -1 => 3
                            Seq[p++] = ((long)((ms << 16) + an) << 32) + ((tw << 16) + ax);
                        }
                    }
                }
                if (!MyProg)
                {
                    LSeq  = Ptr = p; LShuffle = ps;
                    NStk  = Str.NStickers;
                    Field = new short[NStk];
                    Fld2  = new short[NStk];
                    Recalculate();
                }
                else
                {
#if false
                    if (crc != 1234567890123456789)
                    {
                        CSum = 0;
                        AddCSum(Str.NStickers); AddCSum(LSeq); AddCSum(LShuffle); AddCSum(Ptr);
                        AddCSum(T);
                        for (int i = 0; i < LSeq; i++)
                        {
                            AddCSum(Seq[i]);
                        }
                        for (int i = 0; i < NStk; i++)
                        {
                            AddCSum(Field[i]);
                        }
                        if (RevBit(CSum) != crc)
                        {
                            throw new Exception("Wrong CRC");
                        }
                    }
#endif
                    CTime = T * 10000;
                }
                NTwists    = 0;
                NTwists    = GetNTwists(0, Ptr);
                SetupStack = new int[100, 2];
                LStk       = 0;
            } catch (Exception e) {
                if (sr != null)
                {
                    sr.Close();
                }
                throw e;
            }
            sr.Close();
        }