Esempio n. 1
0
        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;
            }
            ;
        }
Esempio n. 2
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
            //}
        }