Example #1
0
        /// <summary>
        /// Store a good move at the front of the list for the given depth
        /// Move the rest up
        /// If the good move was in the list but not that the front,
        /// bring it to the front
        /// If there are enough good moves already, one falls off the end
        /// else the count goes up
        /// </summary>
        /// <param name="moveDepth">the depth at which to add</param>
        /// <param name="insertLoc">the locaiton to add</param>
        public void AddGoodMove(int moveDepth, Location insertLoc)
        {
            if (insertLoc.IsNull())
            {
                return;
            }

            if (moveDepth >= this.Depth)
            {
                this.SetDepth(moveDepth + 1);
            }

            Location[] myDepthLocs = this.moves[moveDepth];

            Location currentLoc = insertLoc;

            bool foundInList = false;

            int max = this.count[moveDepth];
            if (max >= GoodMovesCount)
            {
                max = GoodMovesCount - 1;
            }

            for (int index = 0; index <= max; index++)
            {
                Location tempLoc = myDepthLocs[index];

                // insert and move the next move up one
                myDepthLocs[index] = currentLoc;
                currentLoc = tempLoc;

                // if the original inserted loc was in the list, stop moving up
                if ((index < max) && insertLoc.Equals(currentLoc))
                {
                    foundInList = true;
                    break;
                }
            }

            // has the stored move count increased?
            if ((!foundInList) && (this.count[moveDepth] < GoodMovesCount))
            {
                this.count[moveDepth]++;
            }
        }