コード例 #1
0
        /// <summary>
        /// We can only be missing digits at the beginning (because the number is small),
        /// not in the center, or at the end. E.g. "33333" - valid,
        /// "33_33" - not valid, "3333_" - not valid
        /// </summary>
        public static bool isDigitSequenceNotInterrupting(List <DigitEnum> digits, PlayerIndex playerIndex)
        {
            Dbg.assertPlayerIndexIsInRangeAndNotInvalid(playerIndex);

            // Must have 5 digits for BP score
            Dbg.assert(digits.Count == 5);

            bool          bSequenceStarted = false;
            DigitEnum     firstDigit       = DigitEnum.Error;
            DigitPosition firstDigitIndex  = DigitPosition.Error;

            // From left to right - For all digits in list see if sequence interrupts
            for (int d = ( int )DigitPosition.DigitPos0; d <= (int)DigitPosition.DigitPos4; d++)
            {
                Dbg.assertDigitEnumIsInRange(digits[d]);

                // We previously found a valid digit, must be followed by digits until the end
                // If it's not then we have an error
                if (bSequenceStarted && digits[d] == DigitEnum.Error)
                {
                    //Dbg.onError( "Wrong BP digit sequence at pos: " + d.ToString() +
                    //    " for player: " + playerIndex.ToString() );

                    return(false);
                }

                // Did we find the first valid digit?
                if (!bSequenceStarted && digits[d] != DigitEnum.Error)
                {
                    firstDigit       = digits[d];
                    firstDigitIndex  = ( DigitPosition )d;
                    bSequenceStarted = true;
                }
            }

            // We can only have '0' at the beginning if it's the last digit (usually on DC)
            if (firstDigit == DigitEnum.Digit0)
            {
                if (firstDigitIndex != DigitPosition.DigitPos4)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Take player index and index of a digit in BP score and return the digit.
        /// E.g. digit at index '2' from BP score "14 356" will be '3'
        /// </summary>
        public static DigitEnum recognizeDigitAtDigitPosForPlayer(PlayerIndex playerIndex, DigitPosition digitPos)
        {
            // We might have casted it from an int, check if it's inside enum range
            Dbg.assertPlayerIndexIsInRangeAndNotInvalid(playerIndex);
            Dbg.assertDigitPosEnumIsInRangeAndNotInvalid(digitPos);


            List <bool> boolDigitList = new List <bool>();

            // Try to recognize ALL possible digits at that place
            for (int d = 0; d <= 9; d++)
            {
                boolDigitList.Add(digit[d].recognize(playerIndex, digitPos));
            }

            Dbg.ensureMaxOneBoolIsTrue(boolDigitList);

            // see which one is true, if any
            DigitEnum recognizedDigit = DigitEnum.Error;

            for (int d = (int)DigitEnum.Digit0; d <= (int)DigitEnum.Digit9; d++)
            {
                // Already set it before, so we have more than 1 value => error
                if (boolDigitList[d] && recognizedDigit != DigitEnum.Error)
                {
                    return(DigitEnum.Error);
                }

                if (boolDigitList[d])
                {
                    recognizedDigit = ( DigitEnum )d;
                }
            }

            Dbg.assertDigitEnumIsInRange(recognizedDigit);

            return(recognizedDigit);
        }
コード例 #3
0
        /// <summary>
        /// Recognize DB number digit sequence for a given player
        /// </summary>
        public static List <DigitEnum> recognizeAllDigitsForPlayer(PlayerIndex playerIndex)
        {
            Dbg.assertPlayerIndexIsInRangeAndNotInvalid(playerIndex);

            DigitEnum recognizedDigit = DigitEnum.Error;

            List <DigitEnum> digits = new List <DigitEnum>();

            //string sNumber = "";

            // For all 5 digit positions
            for (int digitPos = ( int )DigitPosition.DigitPos0; digitPos <= ( int )DigitPosition.DigitPos4; digitPos++)
            {
                recognizedDigit = recognizeDigitAtDigitPosForPlayer(playerIndex, ( DigitPosition )digitPos);

                Dbg.assertDigitEnumIsInRange(recognizedDigit);

                digits.Add(recognizedDigit);

                //sNumber = sNumber + ( ( int )recognizedDigit ).ToString();
            }

            return(digits);
        }
コード例 #4
0
ファイル: Dbg.cs プロジェクト: Troman-cs/DBD-Monitor
 public static void assertDigitEnumIsInRange(DigitEnum digit)
 {
     assert(Enum.IsDefined(typeof(DigitEnum), ( int )digit));
 }
コード例 #5
0
ファイル: Dbg.cs プロジェクト: Troman-cs/DBD-Monitor
 public static void assertDigitEnumIsInRangeAndNotInvalid(DigitEnum digit)
 {
     assertDigitEnumIsInRange(digit);
     assert(digit != DigitEnum.Error);
 }