Exemplo n.º 1
0
        // this is done from the startup program -or-
        // it could be done from DealStrategy where new boards are created
        // from a bunch of boards that have empty columns
        public void AddInitialBoard(ref board nb, int TypeInitialBoard, ref csuitable Suitable)
        {
            int desptr;

            int[] des     = new int[112];
            Int64 ChkWord = 0;

            this.Suitable = Suitable;
            bool bInsertFailed = false;

            switch (TypeInitialBoard)
            {
            case GlobalClass.FIRST_CARD:
                int tsbCount = 0;
                nb.ComputeRemainingSuits();
                LastBest          = nb.score - 1;
                cSC.BestScore     = LastBest;
                nb.TimeOfLastDeal = DateTime.Now;
                nb.DealCounter    = 5 - nb.ThisColumn[10].Cards.Count / 10;
                // if there are 20 cards left, we must have dealt 3 times

                nb.MyMoves.AddMoveInfo(TypeInitialBoard, nb.DealCounter, 0);
                nb.from = -1;       // didnt come from another board
                desptr  = nb.FormVerify(ref des, ref ChkWord);
                cSC.stlookup.bIsNewBoard(ChkWord, desptr, ref des, nb.MyMoves.TheseMoves.Count, ref tsbCount, ref bInsertFailed);
                Debug.Assert(!bInsertFailed);
                Debug.Assert(0 == tsbCount);
                break;

            case GlobalClass.DEALT_A_CARD:

                break;
            }
            AddNewBoard(ref nb);
        }
Exemplo n.º 2
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);
            }
        }