Esempio n. 1
0
 public cReduce(ref cSpinControl cSC, ref cDisassemble Disassemble, ref cStrategy Strategy)
 {
     this.Disassemble = Disassemble;
     this.Strategy    = Strategy;
     this.cSC         = cSC;
 }
Esempio n. 2
0
 public cTest(ref cSpinControl cSC, ref cStrategy Strategy)
 {
     this.Strategy = Strategy;
     this.cSC      = cSC;
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            bool   bIsThere      = false;
            string strSpiderBin0 = "";
            string PathToDirectory;
            string stTemp = System.Reflection.Assembly.GetEntryAssembly().Location; // path to executable

            // KnownFolderFinder.EnumerateKnownFolders();   // this was used for testing purposes
            // GlobalClass.InitExceptions();

            // if argument is supplied and extension is a saved game, then use that
            GlobalClass.bLookForFirstColumn = true;
            GlobalClass.bFoundFirstColunn   = false;
            Console.WriteLine("Spider(v) 1.0; 5-20-2018; Copyright Joseph Stateson:  [email protected]\n");

            if (args.Count() > 0)
            {
                if (args[0].Contains(".SpiderSolitaireSave-ms"))
                {
                    string path = Directory.GetCurrentDirectory();
                    strSpiderBin0 = path + "\\" + args[0];
                    bIsThere      = File.Exists(strSpiderBin0);
                    Debug.Assert(bIsThere);
                    GlobalClass.strSpiderBin = strSpiderBin0;
                }
            }
            else
            {
                // look for file in current director and use that one
                strSpiderBin0 = System.IO.Path.GetDirectoryName(stTemp) + "\\Spider Solitaire.SpiderSolitaireSave-ms";
                bIsThere      = File.Exists(strSpiderBin0);
            }
            if (!bIsThere)
            {
                //Attempt to find where the saved spider file is located.  Normally at c:\user\username but the windows MOVE property might
                //have been used to relocat the file.  In addition,  OneDrive may or may not be in the path returned by SpecialFolder

                strSpiderBin0 = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                // the above is usually user\stateson\documents
                GlobalClass.strSpiderBin = strSpiderBin0.Replace("Documents", "Saved Games\\Microsoft Games\\Spider Solitaire\\Spider Solitaire.SpiderSolitaireSave-ms");
                bIsThere = File.Exists(GlobalClass.strSpiderBin);
                if (!bIsThere)
                {
                    // user has made it hard to find, try looking in the registry in case the windows 10 "MOVE" relocated Documents.
                    // we need to find the original Documents location, not the new one
                    Console.WriteLine("could not find " + GlobalClass.strSpiderBin + "\n");
                    PathToDirectory          = KnownFolderFinder.GetFolderFromKnownFolderGUID(new Guid("{FDD39AD0-238F-46AF-ADB4-6C85480369C7}"));
                    GlobalClass.strSpiderBin = PathToDirectory.Replace("Documents", "Saved Games\\Microsoft Games\\Spider Solitaire\\Spider Solitaire.SpiderSolitaireSave-ms");
                    bIsThere = File.Exists(GlobalClass.strSpiderBin);
                    if (!bIsThere)
                    {
                        string strEXE;
                        Console.WriteLine("nothing here also " + GlobalClass.strSpiderBin + "\n");
                        Console.WriteLine("Trying local directory where this .exe program resides\n");
                        strEXE          = System.Reflection.Assembly.GetEntryAssembly().Location;
                        PathToDirectory = System.IO.Path.GetDirectoryName(strSpiderBin0);
                        Console.WriteLine("Looking here: " + PathToDirectory + "\n");
                        strSpiderBin0 = PathToDirectory + "\\Spider Solitaire.SpiderSolitaireSave-ms";
                        if (!File.Exists(strSpiderBin0))
                        {
                            Console.WriteLine("Giving up, cannot find " + strSpiderBin0);
                            Environment.Exit(0);
                        }
                        else
                        {
                            GlobalClass.strSpiderBin = strSpiderBin0;
                        }
                    }
                    else
                    {
                        strSpiderBin0 = GlobalClass.strSpiderBin;
                    }
                }
                else
                {
                    strSpiderBin0 = GlobalClass.strSpiderBin;
                }
            }
            else
            {
                GlobalClass.strSpiderBin = strSpiderBin0;
            }
            PathToDirectory = Path.GetDirectoryName(GlobalClass.strSpiderBin) + "\\";
            GlobalClass.strSpiderOutputBinary = GlobalClass.strSpiderBin = strSpiderBin0;
            GlobalClass.strSpiderDir          = PathToDirectory;
            GlobalClass.strSpiderName         = PathToDirectory + Path.GetFileNameWithoutExtension(strSpiderBin0);
            GlobalClass.strSpiderExt          = Path.GetExtension(strSpiderBin0);
            ClearDir(PathToDirectory);  // erases files with pattern DEAL*, SUIT*, *.mov and adeck and those xml ones also
            cSpinControl cSC = new cSpinControl();

            DisAssemble    = new cDisassemble(ref cSC);
            Suitable       = new csuitable(ref cSC, ref DisAssemble);
            Strategy       = new cStrategy(ref cSC, ref DisAssemble);
            Reduce         = new cReduce(ref cSC, ref DisAssemble, ref Strategy);
            cSC.Strategy   = Strategy;
            cSC.Suitable   = Suitable;
            cSC.JoinSuited = new cJoinSuited(ref cSC);

            Test = new cTest(ref cSC, ref Strategy);

//            Test.RunTest();

            // http://stackoverflow.com/questions/177856/how-do-i-trap-ctrl-c-in-a-c-sharp-console-apphttp://stackoverflow.com/questions/177856/how-do-i-trap-ctrl-c-in-a-c-sharp-console-app
            try
            {
                SolveBoard(ref cSC, GlobalClass.strSpiderBin);
            }
            catch (Exception e)
            {
                if (e.Message != "Spider")
                {
                    throw e;
                }
                //GlobalClass.eExceptionType eID = (GlobalClass.eExceptionType) e.Data["ID"];
                string msg = (string)e.Data["MSG"];
                Console.WriteLine(msg);
                Environment.Exit(0);
            }
        }