Пример #1
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);
        }