Пример #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);
        }
Пример #2
0
        public int AnyFewerMoves(ref board tb, ref int WhereInSeries)
        {
            int[] des     = new int[112];
            Int64 ChkWord = 0;
            int   desptr;

            desptr = tb.FormVerify(ref des, ref ChkWord);
            return(BoardLookup(ChkWord, desptr, ref des, ref WhereInSeries));
        }
Пример #3
0
        public bool TrySpinOneCard(ref board tb, int SrcCol, int SrcCard, int DesCol, int DesCard)
        {
            if (cSC.bTrigger)
            {
                Console.WriteLine(MethodBase.GetCurrentMethod().Name);
            }
            board nb = null;

            int[] des = new int[112];
            Int64 ChkWord = 0;
            int   WouldGoHere = cSC.ThisBoardSeries.Count;
            bool  bInsertFailed = false, bResult = false;

#if AINT
            int[] des1 = new int[112];
            Int64 ChkWord1 = 0, ChkWord2 = 0;
            int   desptr1;
            bool  bVerify = true;
#endif
            int desptr = tb.FormDupList(SrcCol, SrcCard, DesCol, DesCard, ref des, ref ChkWord);
            // check for a duplicate move before creating a new board
            // note that the number of actual moves is 1 less since we have not yet moved anything

            if (cSC.stlookup.bIsNewBoard(ChkWord, desptr, ref des, tb.MyMoves.TheseMoves.Count + 1, ref WouldGoHere, ref bInsertFailed))
            {
                if (bInsertFailed)
                {
                    cSC.bSignalSpinDone       = true;
                    cSC.bOutOfSpaceInSTLOOKUP = true;
                    return(false);
                }
                if (WouldGoHere != cSC.ThisBoardSeries.Count)
                {
                    // this indicates the lookup program found an identical board that had more moves
                    // replace that board with the moves from this one.

                    //ThisBoardSeries[WouldGoHere].DoNotUse = true;
                    cSC.ThisBoardSeries.RemoveAt(WouldGoHere);
                    nb      = new board(ref tb);
                    bResult = SpinOneCard(ref nb, SrcCol, SrcCard, DesCol, DesCard);
                    cSC.ThisBoardSeries.Insert(WouldGoHere, nb);
                    cSC.ThisBoardSeries.RemoveAt(cSC.ThisBoardSeries.Count - 1);
                    return(bResult);
                }

                // either it was not found or it was found but we cannot update the queue
                // because the pointer WouldGoHere is invalid (board was shrunk)
                nb      = new board(ref tb);
                bResult = SpinOneCard(ref nb, SrcCol, SrcCard, DesCol, DesCard);

#if AINT
                //bVerify = tbsCompare1(0, 12);
                //tbsDump(WouldGoHere, desptr, ref des);
                //if ((WouldGoHere == 12 && RunCounter == 2) || WouldGoHere == 0)
                //{
                //    tbsDump(WouldGoHere, desptr, ref des);
                //}
                //if (WouldGoHere == 13 || WouldGoHere == 102)
                //{
                //    tbsDump(WouldGoHere, desptr, ref des);
                //    desptr = tb.FormDupList(SrcCol, SrcCard, DesCol, DesCard, ref des, ref ChkWord2);
                //    desptr1 = nb.FormVerify(ref des1, ref ChkWord1);
                //    Console.WriteLine("WGH: " + WouldGoHere + " " + ChkWord.ToString("x16") + " " + ChkWord1.ToString("x16") + " " + ChkWord2.ToString("x16"));
                //}
                if ((iTrace & 0x10) > 0)
                {
                    ChkWord1 = 0;
                    //desptr = tb.FormDupList(SrcCol, SrcCard, DesCol, DesCard, ref des, ref ChkWord);
                    desptr1  = nb.FormVerify(ref des1, ref ChkWord1);
                    bVerify  = (desptr == desptr1);
                    bVerify |= (ChkWord == ChkWord1);
                    for (int ii = 0; ii < desptr; ii++)
                    {
                        bVerify |= (des[ii] == des1[ii]);
                    }
                    Debug.Assert(bVerify);
                }
#endif
                return(bResult);
            }
            else
            {
                cSC.NumberDuplicates++;
            }
            return(true);
        }