public static void HandleNewStrategy(GlobalClass.StrategyType gcst, ref cSpinControl cSC, ref int FilterSize) { int i, n; switch (gcst) { case GlobalClass.StrategyType.RUN_JOINSUITS_INPLACE: foreach (board tb in cSC.ThisBoardSeries) { board nb = tb; Strategy.ExposeTop(ref nb); Strategy.RunJoinables(ref nb, true); } break; case GlobalClass.StrategyType.SPIN_JOINSUITS: n = cSC.ThisBoardSeries.Count; for (i = 0; i < n; i++) { board tb = cSC.ThisBoardSeries[i]; Strategy.FirstStrategy(ref tb); } break; case GlobalClass.StrategyType.REDUCE_SUITS: PerformReduceSuits(ref cSC, FilterSize); break; default: Debug.Assert(false); break; } ; }
public int GetBoards(ref cSpinControl cSC) { int i, j = 0; int OriginalCount = NewBoards.Count; board nb; cSC.ThisBoardSeries.Clear(); for (i = 0; i < NewBoards.Count; i++) { nb = NewBoards[i]; //if (nb.NumEmptyColumns == 0 || i > OriginalCount) if (nb.bWasDealtTo) { //bs.Suitable.PerformSuitability(ref nb, ref NewBoards); //if (j == 0) //{ // bs.SetSuitableValues(nb.bIsCompletable); //} nb.ID = cSC.ThisBoardSeries.Count; cSC.ThisBoardSeries.Add(nb); j++; } } NewBoards.Clear(); Console.WriteLine("Added " + j + " boards with this new deal"); return(j); }
public cDealStrategy(ref cSpinControl cSC) { NewBoards = new List <board>(); OEmpties = new List <int>(); StartOfDealPtr = 0; this.cSC = cSC; }
public cDisassemble(ref cSpinControl cSC) { this.cSC = cSC; runSEQdisassemble(); runSOSdisassemble(); CardCountMoves = new List <cCardCountMoves>(); }
public void AddShrinkCode(ref cSpinControl cSC, int cnt) { int n = TheseMoves.Count - 1; if (cnt > 99) { cnt = 99; } // jys oct 2012 remove this??? // nov 2012 Debug.Assert(n > 0); TheseMoves[n].ShrinkCode = utils.GetShrinkCode(ref cSC).ToString() + "-" + utils.Lpadto(cnt.ToString(), 2); }
public static bool tbsCompareAll(ref cSpinControl cSC, int id1, int id2) { bool bSame1 = tbsCompare(ref cSC, id1, id2); bool bSame2 = cSC.stlookup.cstCompare(id1, id2); if (bSame1 && bSame2) { Console.WriteLine("ERROR: Boards are identical! " + id1 + " " + id2); Console.WriteLine(" Unique IDs are: " + cSC.ThisBoardSeries[id1].UniqueID + " " + cSC.ThisBoardSeries[id2].UniqueID); } return(bSame1 && bSame2); }
// save the DEALx which is the best of the DEALx_1, DEALx..12 etc and takes a while to identify // usually the FirstEmptyColumn deck is just as good to use and is calculated earlier private static void SaveBestBoard(ref cSpinControl cSC) { cSC.LocalDealCounter = 0; cSC.BestBoard.DealCountIndex = cSC.LocalDealCounter; cSC.Deck.SaveBoardAtDeal(GlobalClass.eSBAD.eStartGather, ref cSC.BestBoard, 0); if (cSC.bSpinDidAllBoards && cSC.BestBoard.DealCounter == 5) { // if we ran that reduce suits here it would be nice 16nov2012 } GlobalClass.No_Cards_Left.Data.Add("MSG", "Out of Cards in HandleDeal"); throw GlobalClass.No_Cards_Left; } }
public static int PerformReduceSuits(ref cSpinControl cSC, int m) { bool bAny = true; int cnt = 0; int j, n, OCount = cSC.ThisBoardSeries.Count; for (int i = 0; i < OCount; i++) // Reduce can add boards to this { board oldtb = cSC.ThisBoardSeries[i]; board tb = new board(ref oldtb); if (tb.bIsCompletable) { Suitable.PerformSuitabilityScreening(ref tb); } else { int Any = Strategy.TryUnstackOne(ref tb, ref cnt); //Strategy.RunJoinables(ref tb, true); if (Any == 0) { continue; } if (tb.bIsCompletable) { Suitable.PerformSuitabilityScreening(ref tb); } else { cSC.NextBoardSeries.Add(tb); // it will not be processed because of bIsCompletable however, it } // will be moved back into ThisBoardSeries for another try at it } } bAny = (cSC.NextBoardSeries.Count > 0); return(cSC.NextBoardSeries.Count); // jys 16nov2012 Debug.Assert(bAny); while (bAny) { bAny = Reduce.RunFilter(m); } n = cSC.ThisBoardSeries.Count; if (OCount < n) { j = 0; for (int i = OCount; i < n; i++) { cSC.ThisBoardSeries[j] = cSC.ThisBoardSeries[OCount + j]; j++; } cSC.ThisBoardSeries.RemoveRange(OCount, n - OCount); } }
public cSpinAllMoves(ref cSpinControl cSC) { // Suitable = new csuitable(ref MaxValues); cSC.stlookup = new Cstlookup(cSC.MaxValues.MaxInsertsWhenSuiting * 4); cSC.PrevSeed = new cSeed(); cSC.ThisSeed = new cSeed(); cSC.SortedScores = new List <cBestScore>(128); this.cSC = cSC; NumSuitsWritten = 0; SuitsCompleted = new int[4]; ClearSeries(); RepeatDepth = 0; strSpinType = ""; }
public cStrategy(ref cSpinControl cSC, ref cDisassemble DisAssemble) { this.cSC = cSC; this.DisAssemble = DisAssemble; OurLastBest = 0; //DisAssemble = new cDisassemble(); RtnCode = 0; CardsToMove = new List <card>(); desCardsToMove = new List <card>(); srcCardsToMove = new List <card>(); xBottomMost = new List <card>(); xEmpties = new List <int>(); xNonEmpties = new List <int>(); xTopMost = new List <card>(); }
private static bool tbsCompare(ref cSpinControl cSC, int i1, int i2) { int i, j, k, n = cSC.ThisBoardSeries.Count; if (n < 2) { return(true); } board nb1 = cSC.ThisBoardSeries[i1]; board nb2 = cSC.ThisBoardSeries[i2]; if (nb1.NonEmpties.Count != nb2.NonEmpties.Count) { return(false); } if (nb1.Empties.Count != nb2.Empties.Count) { return(false); } for (i = 0; i < nb1.NonEmpties.Count; i++) { k = nb1.NonEmpties[i]; n = nb1.ThisColumn[k].Cards.Count; if (n != nb2.ThisColumn[k].Cards.Count) { return(false); } for (j = 0; j < n; j++) { if (nb1.ThisColumn[k].Cards[j].rank != nb2.ThisColumn[k].Cards[j].rank) { return(false); } if (nb1.ThisColumn[k].Cards[j].suit != nb2.ThisColumn[k].Cards[j].suit) { return(false); } if (nb1.ThisColumn[k].Cards[j].bFaceUp != nb2.ThisColumn[k].Cards[j].bFaceUp) { return(false); } } } return(true); }
public static void SetSuitableValues(ref cSpinControl cSC, ref board tb) { if (tb.bIsCompletable) { if (cSC.MaxValues.MaxInserts != cSC.MaxValues.MaxInsertsWhenSuiting) { Console.WriteLine("Switching to max resources"); } cSC.MaxValues.MaxInserts = cSC.MaxValues.MaxInsertsWhenSuiting; cSC.MaxValues.TimeOutBest = cSC.MaxValues.MaxTimeoutWhenSuiting; } else { if (cSC.MaxValues.MaxInserts != cSC.MaxValues.MinInserts) { Console.WriteLine("Switching to min resources"); } cSC.MaxValues.MaxInserts = cSC.MaxValues.MinInserts; cSC.MaxValues.TimeOutBest = cSC.MaxValues.MinTimeout; } }
public static bool tbsCompareSeeds(ref cSpinControl cSC) { int i, j, n = cSC.ThisSeed.Seeds.Count; bool bResult = true; if (n > GlobalClass.MIN_FILTERED_BOARDS) { n = GlobalClass.MIN_FILTERED_BOARDS; } if (n < 2) { return(true); } for (i = 0; i < n - 1; i++) { for (j = i + 1; j < n; j++) { bResult &= tbsCompareAll(ref cSC, i, j); } } return(bResult); }
public static char GetShrinkCode(ref cSpinControl cSC) { if (cSC.bExceededCountLimit) { return('L'); } if (cSC.bExceededONEcolLimit) { return('1'); } if (cSC.bExceededTWOcolLimit) { return('2'); } if (cSC.bExceededThreecolLimit) { return('3'); } if (cSC.bSpinTimedOut) { return('T'); } if (cSC.bSpinDidAllBoards) { return('D'); } if (cSC.bOutOfSpaceInSTLOOKUP) { return('S'); } if (cSC.bGotOneSuitAtLeast) { return('C'); } Debug.Assert(false); return(' '); }
public static int HandleDeal(ref cSpinControl cSC, bool bDealThruSeed) { int m, n = cSC.ThisBoardSeries.Count; // utils.UseThisManyBoards(ref cSC); cDealStrategy DealStrategy = new cDealStrategy(ref cSC); board tb = null; int j, nNewBoards = 0; if (cSC.BestBoard != null) { SaveBestBoard(ref cSC); } if (bDealThruSeed) { n = cSC.ThisSeed.Seeds.Count; } if (n > GlobalClass.MAX_FILTERED_BOARDS) { n = GlobalClass.MAX_FILTERED_BOARDS; } cSC.BestBoard = null; // only want the one for the current deal for (int i = 0; i < n; i++) { if (bDealThruSeed) { if (i >= cSC.ThisSeed.SeedIndex.Count) { break; } j = cSC.ThisSeed.SeedIndex[i]; } else { j = i; } tb = cSC.ThisBoardSeries[j]; nNewBoards = DealStrategy.DealToBoard(ref tb, DateTime.Now, n); // nNewBoards mistakenly includes dead boards so dont check for n==m anymore cSC.LocalDealCounter++; tb.DealCountIndex = cSC.LocalDealCounter; // save only the first 12 boards of the deal. the deal is against the previous deck if (i < GlobalClass.MaxDealsToShow) { bool bOnLast = ((i == (n - 1)) || (i == (GlobalClass.MaxDealsToShow - 1))); cSC.Deck.SaveBoardAtDeal(bOnLast ? GlobalClass.eSBAD.eAllGathered : GlobalClass.eSBAD.eContinue, ref tb, i); if (tb.MyMoves.TheseMoves.Count() < 6) { int kk = 0; } } if (nNewBoards > GlobalClass.MinInserts) { break; } } m = DealStrategy.GetBoards(ref cSC); if (m <= 0) { if (tb.DealCounter < 5) { Debug.Assert(m > 0); Console.WriteLine("problem with handleing deal! m:" + m + " nNewBoards:" + nNewBoards); } else { Console.WriteLine("Game over\n"); } Environment.Exit(0); } tb = cSC.ThisBoardSeries[0]; utils.SetSuitableValues(ref cSC, ref tb); if (m > GlobalClass.MAX_FILTERED_BOARDS) { m = GlobalClass.MAX_FILTERED_BOARDS; } // all will be processed, just want at most 500 results after RunFilter if (m < GlobalClass.MIN_FILTERED_BOARDS) { m = GlobalClass.MIN_FILTERED_BOARDS; } // want to have at least this many from the filter if possible cSC.BestScore = 0; // this may get new boards into SortedScores at least on the next filter run cSC.stlookup.Clear(); //GlobalClass.bLookForFirstColumn = true; // ONLY WANT TO DO THIS ONCE FOR VERY FIRST TIME. //GlobalClass.bFoundFirstColunn = false; return(m); }
public static GlobalClass.StrategyType UseThisManyBoards(ref cSpinControl cSC, ref int NumToUse) { int i, n = cSC.ThisBoardSeries.Count; int iBiggest = 0; int[] tsbEmptyDistribution = new int[11] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int[] sedEmptyDistribution = new int[11] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Debug.Assert(cSC.ThisBoardSeries.Count > 0); Debug.Assert(cSC.ThisSeed.SeedIndex.Count > 0); foreach (board tb in cSC.ThisBoardSeries) { tsbEmptyDistribution[tb.Empties.Count]++; } for (i = 0; i < cSC.ThisSeed.SeedIndex.Count; i++) { board tb = cSC.ThisBoardSeries[cSC.ThisSeed.SeedIndex[i]]; sedEmptyDistribution[tb.Empties.Count]++; } for (i = 10; i >= 1; i--) { if (sedEmptyDistribution[i] > 0) { iBiggest = i; break; } } if (iBiggest == 0) { NumToUse = GlobalClass.MAX_FILTERED_BOARDS; // if no empty columns run thru all boards return(GlobalClass.StrategyType.CONTINUE_SPINNING); } if (iBiggest <= 3) { NumToUse = GlobalClass.MIN_FILTERED_BOARDS; return(GlobalClass.StrategyType.CONTINUE_SPINNING); } if (iBiggest > 3 && cSC.ThisBoardSeries[0].bIsCompletable) { NumToUse = 0; return(GlobalClass.StrategyType.REDUCE_SUITS); // stop the spinning - switch to end game } // UNTIL I FIX JOINSUITS //if (iBiggest == 3) //{ // NumToUse = 10; // return GlobalClass.StrategyType.SPIN_JOINSUITS; //} //if (iBiggest == 2) //{ // NumToUse = GlobalClass.MIN_FILTERED_BOARDS; // return GlobalClass.StrategyType.RUN_JOINSUITS_INPLACE; //} //foreach (board tb in cSC.ThisBoardSeries) //{ // if (tb.NumEmptyColumns == 2) // Console.WriteLine(tb.ID + " " + tb.score + " "); //} NumToUse = GlobalClass.MIN_FILTERED_BOARDS; return(GlobalClass.StrategyType.CONTINUE_SPINNING); }
static void Main(string[] args) { bool bIsThere = false; string stExt = ".SpiderSolitaireSave-ms"; string stTemp, strSpiderBin0; string PathToDirectory; string stSrc = "", stDef = "Spider Solitaire.SpiderSolitaireSave-ms"; cSpinControl cSC; board InitialBoard; stTemp = System.Reflection.Assembly.GetEntryAssembly().Location; // path to executable if (args.Count() > 0) { stSrc = "\\" + args[0]; } else //stSrc = "\\" + stDef; - not searching for save file anymore { GiveHelp(); Environment.Exit(0); } strSpiderBin0 = System.IO.Path.GetDirectoryName(stTemp) + stSrc; bIsThere = File.Exists(strSpiderBin0); if (bIsThere) { PathToDirectory = Path.GetDirectoryName(strSpiderBin0) + "\\"; GlobalClass.strSpiderBin = strSpiderBin0; GlobalClass.strSpiderDir = PathToDirectory; GlobalClass.strSpiderName = PathToDirectory + Path.GetFileNameWithoutExtension(strSpiderBin0); GlobalClass.strSpiderExt = Path.GetExtension(strSpiderBin0); cSC = new cSpinControl(); // this created the default xml "filename" InitialBoard = new board(); cSC.Deck = new cBuildDeck(strSpiderBin0, XMLtoRead, ref cSC); if (args.Count() < 2) // just want to look at the xml { cSC.Deck.GetBoardFromSpiderSave(ref InitialBoard); } else { string stDes = stDef; if (args.Count() == 3) { stDes = args[2]; } if (!stDes.Contains(stExt)) { stDes += stExt; } if (args[0] == stDes) { Console.WriteLine("cannot have same output file name as the input saved game\n"); Environment.Exit(0); } stTemp = PathToDirectory + Path.GetFileNameWithoutExtension(args[1]); if (GlobalClass.strSpiderName == stTemp) { Console.WriteLine("should not have same input saved game name as the input xml filename\n"); Console.WriteLine("or input xml file will be over written as that filename used for temp storage\n"); Environment.Exit(0); } GlobalClass.strSpiderOutputBinary = cSC.BIN_Diag_filename = PathToDirectory + "\\" + stDes; cSC.Deck.GetBoardFromSpiderSave(ref InitialBoard); // read in the saved game and also create the matching xml cSC.XML_Diag_filename = PathToDirectory + args[1]; cSC.Deck.WriteBoardMergingXML(); } } }
public cTest(ref cSpinControl cSC, ref cStrategy Strategy) { this.Strategy = Strategy; this.cSC = cSC; }
public cReduce(ref cSpinControl cSC, ref cDisassemble Disassemble, ref cStrategy Strategy) { this.Disassemble = Disassemble; this.Strategy = Strategy; this.cSC = cSC; }
public void ReCreateBinFile(ref board tb, ref cSpinControl cSC, string strPrefix) { long nLen1, nLen = 1048576; int i, j, n; int DealID = cSC.LocalDealCounter; // this is the deals that are done to the "working deal" which is the board deal counter. string strFullpathname = ""; if (strPrefix == "") { strFullpathname = GlobalClass.strSpiderOutputBinary; } else { strFullpathname = GlobalClass.strSpiderDir + strPrefix + ".SpiderSolitaireSave-ms"; } //FileStream inStream = File.OpenRead(strFullpathname + ".hdr"); //BinaryReader br = new BinaryReader(inStream); //nLen = inStream.Length; //Debug.Assert(nLen == 0x2028); if (File.Exists(strFullpathname)) { Debug.Assert(false); } FileStream outStream = File.Create(strFullpathname); BinaryWriter bw = new BinaryWriter(outStream); // get the hdr byte[] outbuf = new byte[256000]; for (j = 0; j < 0x2028; j++) { outbuf[j] = cSC.Hdr[j]; } nLen = cSC.PngArray.Length; // get the png file #if SAVE_PNG inStream = File.OpenRead(strFullpathname + ".png"); nLen = inStream.Length; br = new BinaryReader(inStream); br.Read(outbuf, 0x2028, (int)nLen); nLen1 = nLen + 0x2028; #endif nLen1 = 0x2028; for (i = 0; i < nLen; i++) { outbuf[nLen1] = cSC.PngArray[i]; nLen1++; } MakeXmlFile(strFullpathname, ref tb, ref cSC); n = sbXML.Length; string sbTemp = sbXML.ToString(); j = (int)nLen1; // convert n into bytes and append ff fe so one could get "c6 18 01 00 ff fe" byte[] b6 = new byte[8]; GetUnk6(ref b6, 6 + n * 2); // added 2 to fix problem and added another 2 for two more nulls but 0xa is missing for (i = 0; i < 6; i++) { outbuf[j] = b6[i]; j++; } for (i = 0; i < n; i++) { outbuf[j] = (byte)sbTemp[i]; j++; outbuf[j] = 0; j++; } outbuf[j] = 0; j++; outbuf[j] = 0x0a; j++; bw.Write(outbuf, 0, j + 2); bw.Close(); }
//complete starts off with x 110 y 380 then x goes to 140 (increments by 30 private void MakeXmlFile(string strFullPathName, ref board tb, ref cSpinControl cSC) { bool bFaceUp; // deck: all are false except the last enabled bool bEnabled; // complete: all are faceup and all enabled are false sbXML = new StringBuilder(16384); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = (" "); settings.NewLineChars = "\n"; settings.OmitXmlDeclaration = true; using (XmlWriter writer = XmlWriter.Create(sbXML, settings)) //(strFullPathName + "_bin.xml", settings)) // using (XmlWriter writer = XmlWriter.Create(strFullPathName + "_bin.xml", settings)) { // Write XML data. writer.WriteStartElement("Root"); writer.WriteStartElement("GameState"); writer.WriteElementString("Version", "7"); writer.WriteElementString("GameSeed", cSC.GameSeed.ToString()); writer.WriteElementString("Score", tb.score.ToString()); // 2018 tb.score.ToString()); writer.WriteElementString("Moves", (1 + tb.DealCounter).ToString()); // (tb.NumMoves + tb.MyMoves.TheseMoves.Count).ToString()); writer.WriteEndElement(); // gamestate writer.WriteStartElement("CardTable"); writer.WriteStartElement("CardStacks"); cCardStack ccsPtr; int nCardStack = 0; int nDirection = 1; foreach (column col in tb.ThisColumn) { ccsPtr = col.CardStack; int ccsPtrX = ccsPtr.X; int ccsPtrY = ccsPtr.Y; int j = 0; // count cards as only last one is enabled int dX = 0, dY = 0; string stackName = ""; switch (nDirection) { case 1: stackName = "Stack" + (col.CardStack.stackid).ToString(); dY = 7; dX = -7; break; case 2: stackName = "Deck"; dX = -6; break; case 3: stackName = "Complete"; dX = 30; // origin of X was 110 dY = 0; // origin of Y was 380 break; } writer.WriteStartElement("CardStack"); writer.WriteElementString("NumEndCardsSpaced", ccsPtr.NumEndCardsSpaced.ToString()); writer.WriteElementString("X", ccsPtr.X.ToString()); writer.WriteElementString("Y", ccsPtr.Y.ToString()); writer.WriteElementString("Name", stackName); writer.WriteElementString("Direction", nDirection.ToString()); writer.WriteStartElement("Cards"); foreach (card crd in col.Cards) { writer.WriteStartElement("Card"); writer.WriteElementString("X", ccsPtrX.ToString()); writer.WriteElementString("Y", ccsPtrY.ToString()); bFaceUp = crd.bFaceUp; bEnabled = bFaceUp; if (nDirection == 3) { bFaceUp = true; bEnabled = false; } else if (nDirection == 2) { bFaceUp = false; bEnabled = (j == (col.Cards.Count - 1)); } if (nDirection == 1) { ccsPtrY += dY; } writer.WriteElementString("Name", GlobalClass.ProperName(crd)); writer.WriteElementString("Type", crd.type.ToString()); writer.WriteElementString("FaceUp", bFaceUp.ToString().ToLower()); writer.WriteElementString("Enabled", bEnabled.ToString()); if (bFaceUp && nDirection < 3) { dY = 23; } if (((1 + j) % 13) == 0) { ccsPtrX += dX; if (nDirection != 1) { ccsPtrY += dY; } } j++; writer.WriteEndElement(); // card } writer.WriteEndElement(); // cards writer.WriteEndElement(); //CardStack nCardStack++; if (nCardStack == 10) { nDirection = 2; } if (nCardStack == 11) { nDirection = 3; } // need to write out the completed stack eventually!! } writer.WriteEndElement(); // cardstacks writer.WriteEndElement(); // cardtable writer.WriteEndElement(); // root writer.Flush(); if (strFullPathName.Contains("SUIT")) { Console.WriteLine(" Wrote out a binary suit file: " + strFullPathName); } else if (strFullPathName.Contains("DEAL")) { Console.WriteLine(" Wrote out a binary deal file: " + strFullPathName); } else { Console.WriteLine(" replaced with a new binary deal file: " + strFullPathName); } foreach (cSuitedStatus cSS in tb.SuitStatus) { for (int i = 0; i < cSS.NumCompletedAndRemoved; i++) { Console.WriteLine("Removed suit:" + GlobalClass.SuitNames[cSS.index]); } } } }
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); } }
public csuitable(ref cSpinControl cSC, ref cDisassemble Disassemble) { this.cSC = cSC; this.Disassemble = Disassemble; NumberCompletable = 0; }
static void SolveBoard(ref cSpinControl cSC, string strSpiderBin) { int m = GlobalClass.MAX_FILTERED_BOARDS; GlobalClass.StrategyType gcst = GlobalClass.StrategyType.CONTINUE_SPINNING; board InitialBoard = new board(); cSC.Deck = new cBuildDeck(strSpiderBin, XMLtoRead, ref cSC); MakeAllPossibleMoves = new cSpinAllMoves(ref cSC); cSC.Deck.GetBoardFromSpiderSave(ref InitialBoard); if (InitialBoard.NumEmptyColumns > 0) { GlobalClass.bFoundFirstColunn = false; // started with an empty column, no need to display it. } InitialBoard.ShowBoard(); cSC.cMXF = new cMergeXmlFile(); if (cSC.bJustReadXML) { Console.WriteLine(" Did you mean to read a pre-existing XML file?\n - close window to abort\n - or press N to delete the XML file and abort\n - or press Y to continue"); if (cSC.EventList.Count > 0) { Console.WriteLine(" There are " + cSC.EventList.Count + " events in the event list"); Console.WriteLine(cSC.Deck.strEventInfoPrompt); } ConsoleKeyInfo cki = Console.ReadKey(); Console.WriteLine(""); if (cki.Key.ToString().ToLower() == "n") { File.Delete(cSC.XML_Diag_filename); Environment.Exit(0); } else { string strA = cki.KeyChar.ToString(); int A = -1; int.TryParse(strA, out A); if (A >= 1 && A < 7) { int RequiredOffset = 0; int RequiredDeal = A; string strCmd = Console.ReadLine().ToLower(); strA = strCmd.Substring(0, 1); InitialBoard = null; if (strA == "m") //Format is 2m34 or 3M45 { strCmd = strCmd.Substring(1); RequiredOffset = Convert.ToInt32(strCmd); bool bResult = cSC.Deck.AdvanceToPosition(RequiredDeal, RequiredOffset, out InitialBoard); CallExit(); } else { if (strA == "s") // format is 2s 3S , etc .. show all best scores { bool bResult = cSC.Deck.ShowAllBestScores(RequiredDeal, out InitialBoard); CallExit(); } else if (strA == "t") // format is 2t45 3t9 , etc .. trace using stlookup { // deals 2, 3, and set breakpoint in debugger at the callout for the 45, 9, etc RequiredOffset = Convert.ToInt32(strCmd.Substring(1)); bool bResult = cSC.Deck.AddBoardsToLookup(RequiredDeal, RequiredOffset); CallExit(); } else { Console.WriteLine("Unknown key code. One of M,S,m,s only"); CallExit(); } } } else { bool bResult = cSC.Deck.AdvanceSaveBoard(cki.Key.ToString().ToLower(), out InitialBoard); Debug.Assert(false); } } } //Suitable.CheckSuitability(ref InitialBoard); // the above is not critical to the program as yet, just good info about unexposed cards //cSC.Suitable.CombineLikeSuits(ref InitialBoard); MakeAllPossibleMoves.AddInitialBoard(ref InitialBoard, GlobalClass.FIRST_CARD, ref Suitable); //cSC.JoinSuited.SpinSuitedJoinables(ref cSC.ThisBoardSeries); //if (InitialBoard.bIsCompletable) PerformReduceSuits(ref cSC, 20); //Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) //{ // e.Cancel = true; // Program.keepRunning = false; //}; while (true) // (Program.keepRunning) { RunAway--; if (RunAway < 0) { Console.WriteLine("hit any key except x: TBS:" + cSC.ThisBoardSeries.Count + " NBS:" + cSC.NextBoardSeries.Count); ConsoleKeyInfo cki = Console.ReadKey(); if (cki.KeyChar == 'x') { Environment.Exit(0); } } bool b1 = MakeAllPossibleMoves.RunFilter(m); // m is max to allow after applying filter bool bSameSeed = cSC.PrevSeed.bSameSeed(ref cSC.ThisSeed); if (cSC.bOutOfSpaceInSTLOOKUP) { Console.WriteLine("ran out of space and had to clear stlookup"); cSC.stlookup.Clear(); cSC.bOutOfSpaceInSTLOOKUP = false; } if (cSC.bSpinDidAllBoards) { int iAny = 0; for (int i = 0; i < cSC.ThisBoardSeries.Count; i++) { board nb = cSC.ThisBoardSeries[i]; if (cSC.Suitable.CombineLikeSuits(ref nb)) { iAny++; } } if (iAny > 0) { cSC.bSpinDidAllBoards = false; m = cSC.ThisBoardSeries.Count; Console.WriteLine("Cannot deal but found " + iAny.ToString() + " new boards using join suited" + cSC.bSpinDidAllBoards); } } if (cSC.bSpinDidAllBoards || bSameSeed || cSC.bStopThisRun) { m = HandleDeal(ref cSC, false); Console.WriteLine("Handled deal with m:" + m.ToString() + " bSpin:" + cSC.bSpinDidAllBoards + " SameSeed:" + bSameSeed, " StopRun:" + cSC.bStopThisRun); Console.WriteLine("TBS: " + cSC.ThisBoardSeries.Count + " NBS: " + cSC.NextBoardSeries.Count); cSC.bTrace = true; } else { // unable to finish all boards -or- didnt generate any boards other then the same seeds if (cSC.SortedScores.Count == 0) { // no larger scores were found during the last run: use ThisSeed m = HandleDeal(ref cSC, true); Console.WriteLine("Handled deal from SortedScores.count=0 m:" + m.ToString()); } else { gcst = utils.UseThisManyBoards(ref cSC, ref m); Console.WriteLine("HNS: " + m + " type " + gcst.ToString()); if (gcst != GlobalClass.StrategyType.CONTINUE_SPINNING) { Console.WriteLine("Seem we are to reduce:" + m); HandleNewStrategy(gcst, ref cSC, ref m); } } } } //if (!Program.keepRunning) //{ // cSC.BestBoard.ShowBoard(); // 11nov2012 added this ctrl-c stuff //} }
public cJoinSuited(ref cSpinControl cSC) { this.cSC = cSC; }