コード例 #1
0
        public static string FindBestHandValue(string inputLine)
        {
            string[] splits = inputLine.Split(' ');

            //validate the length of the input lines and number of card codes
            if (inputLine.Length != 29 || splits.Length != 10)
            {
                throw new InvalidInputException("Invalid input line: " + inputLine);
            }
            else
            {
                ParseResult parseResult;
                string      handString;
                string      deckString;

                try
                {
                    int halfLength = inputLine.Length / 2;

                    //get the card codes representing the hand
                    handString = inputLine.Substring(0, halfLength);

                    //get the card codes representing the deck
                    deckString = inputLine.Remove(0, halfLength + 1);

                    //parse the card codes and create corresponding Hand and Deck objects
                    parseResult = InputParser.Parse(handString, deckString);
                }
                catch (InvalidInputException ex)
                {
                    //this exception is thrown by our own classes to indicate an invalid input
                    throw new InvalidInputException(ex.Message + inputLine);
                }
                catch
                {
                    //any other unknown exception that may occur during input parsing
                    throw new InvalidInputException("Invalid input line: " + inputLine);
                }

                //this will be used to enumarate all possible (32) card combinations
                int enumerator = 0;

                //this is the temporary value of enumerator used in the loop
                int temp;

                Hand hand;
                Deck deck;

                //represents the best hand value
                HandValue result = HandValue.highest_card;

                HandValue current;

                //in this loop we enumerate and try all possible hands
                //to do this we use the binary representation of the numbers from 0 to 31
                //00000 means no card is replaced (no card drawn from the deck)
                //00001 means first card of the hand is replaced
                //10001 means first and last cards of the hand is replaced and so on.
                while (enumerator < 32)
                {
                    temp = enumerator;

                    hand = new Hand(parseResult.Hand);
                    deck = new Deck(parseResult.Deck);

                    for (int i = 0; i < 5; i++)
                    {
                        //determine if the current card will be replaced
                        //if the last bit is 1, then the card in the current index is replaced
                        if ((temp & 1) == 1)
                        {
                            hand.ReplaceCard(i, deck.GetNext());
                        }

                        //we are done with this bit, so drop it
                        temp = temp >> 1;
                    }

                    //calculate the hand value
                    current = hand.GetHandValue();

                    if (current > result)
                    {
                        result = current;
                    }

                    //if it is a straight flush, no need to check other possible hands
                    if (result == HandValue.straight_flush)
                    {
                        break;
                    }

                    //advance to the next hand
                    enumerator++;
                }

                return("Hand: " + handString + " Deck:" + deckString + " Best hand: " + result.ToString());
            }
        }
コード例 #2
0
        string GetFeatureValue(InputDevice device, InputFeatureUsage featureUsage)
        {
            switch (featureUsage.type.ToString())
            {
            case "System.Boolean":
                bool boolValue;
                if (device.TryGetFeatureValue(featureUsage.As <bool>(), out boolValue))
                {
                    return(boolValue.ToString());
                }
                break;

            case "System.UInt32":
                uint uintValue;
                if (device.TryGetFeatureValue(featureUsage.As <uint>(), out uintValue))
                {
                    return(uintValue.ToString());
                }
                break;

            case "System.Single":
                float floatValue;
                if (device.TryGetFeatureValue(featureUsage.As <float>(), out floatValue))
                {
                    return(floatValue.ToString());
                }
                break;

            case "UnityEngine.Vector2":
                Vector2 Vector2Value;
                if (device.TryGetFeatureValue(featureUsage.As <Vector2>(), out Vector2Value))
                {
                    return(Vector2Value.ToString());
                }
                break;

            case "UnityEngine.Vector3":
                Vector3 Vector3Value;
                if (device.TryGetFeatureValue(featureUsage.As <Vector3>(), out Vector3Value))
                {
                    return(Vector3Value.ToString());
                }
                break;

            case "UnityEngine.Quaternion":
                Quaternion QuaternionValue;
                if (device.TryGetFeatureValue(featureUsage.As <Quaternion>(), out QuaternionValue))
                {
                    return(QuaternionValue.ToString());
                }
                break;

            case "UnityEngine.XR.Hand":
                Hand HandValue;
                if (device.TryGetFeatureValue(featureUsage.As <Hand>(), out HandValue))
                {
                    return(HandValue.ToString());
                }
                break;

            case "UnityEngine.XR.Bone":
                Bone BoneValue;
                if (device.TryGetFeatureValue(featureUsage.As <Bone>(), out BoneValue))
                {
                    return(BoneValue.ToString());
                }
                break;

            case "UnityEngine.XR.Eyes":
                Eyes EyesValue;
                if (device.TryGetFeatureValue(featureUsage.As <Eyes>(), out EyesValue))
                {
                    return(EyesValue.ToString());
                }
                break;
            }

            return("");
        }
コード例 #3
0
        string GetFeatureValue(InputDevice device, InputFeatureUsage featureUsage)
        {
            switch (featureUsage.type.ToString())
            {
            case "System.Boolean":
                bool boolValue;
                if (device.TryGetFeatureValue(featureUsage.As <bool>(), out boolValue))
                {
                    return(boolValue.ToString());
                }
                break;

            case "System.UInt32":
                uint uintValue;
                if (device.TryGetFeatureValue(featureUsage.As <uint>(), out uintValue))
                {
                    return(uintValue.ToString());
                }
                break;

            case "System.Single":
                float floatValue;
                if (device.TryGetFeatureValue(featureUsage.As <float>(), out floatValue))
                {
                    return(floatValue.ToString());
                }
                break;

            case "UnityEngine.Vector2":
                Vector2 Vector2Value;
                if (device.TryGetFeatureValue(featureUsage.As <Vector2>(), out Vector2Value))
                {
                    return(Vector2Value.ToString());
                }
                break;

            case "UnityEngine.Vector3":
                Vector3 Vector3Value;
                if (device.TryGetFeatureValue(featureUsage.As <Vector3>(), out Vector3Value))
                {
                    return(Vector3Value.ToString());
                }
                break;

            case "UnityEngine.Quaternion":
                Quaternion QuaternionValue;
                if (device.TryGetFeatureValue(featureUsage.As <Quaternion>(), out QuaternionValue))
                {
                    return(QuaternionValue.ToString());
                }
                break;

            case "UnityEngine.XR.Hand":
                Hand HandValue;
                if (device.TryGetFeatureValue(featureUsage.As <Hand>(), out HandValue))
                {
                    return(HandValue.ToString());
                }
                break;

            case "UnityEngine.XR.Bone":
                Bone BoneValue;
                if (device.TryGetFeatureValue(featureUsage.As <Bone>(), out BoneValue))
                {
                    Vector3    bonePosition;
                    Quaternion boneRotation;
                    if (BoneValue.TryGetPosition(out bonePosition) && BoneValue.TryGetRotation(out boneRotation))
                    {
                        return(string.Format("{0}, {1}", bonePosition.ToString(), boneRotation.ToString()));
                    }
                }
                break;

            case "UnityEngine.XR.Eyes":
                Eyes EyesValue;
                if (device.TryGetFeatureValue(featureUsage.As <Eyes>(), out EyesValue))
                {
                    Vector3 fixation, left, right;
                    float   leftOpen, rightOpen;
                    if (EyesValue.TryGetFixationPoint(out fixation) &&
                        EyesValue.TryGetLeftEyePosition(out left) &&
                        EyesValue.TryGetRightEyePosition(out right) &&
                        EyesValue.TryGetLeftEyeOpenAmount(out leftOpen) &&
                        EyesValue.TryGetRightEyeOpenAmount(out rightOpen))
                    {
                        return(string.Format("{0}, {1}, {2}, {3}, {4}", fixation.ToString(), left.ToString(), right.ToString(), leftOpen, rightOpen));
                    }
                }
                break;
            }

            return("");
        }