public void CardsWithSameSuitAndDifferentFaceAreNotEqual()
        {
            var AceOfSpades  = new StandardCard(Suit.Spades, Face.Ace);
            var KingOfSpades = new StandardCard(Suit.Spades, Face.King);

            Assert.NotEqual(AceOfSpades, KingOfSpades);
        }
        private async Task <SpeechletResponse> BuildSpeechletResponse(string title, string output, bool shouldEndSession)
        {
            //Create a standard card
            var image = new Image()
            {
                SmallImageUrl = "https://samman.hopto.org/rokusmall.png",
                LargeImageUrl = "https://samman.hopto.org/rokubig.png"
            };

            var card = new StandardCard()
            {
                Title = String.Format("RokuControl - {0}", title),
                Text  = String.Format("{0}", output),
                Image = image
            };

            // Create the plain text output.
            var speech = new PlainTextOutputSpeech()
            {
                Text = output
            };

            // Create the speechlet response.
            var response = new SpeechletResponse()
            {
                ShouldEndSession = shouldEndSession,
                OutputSpeech     = speech,
                Card             = card
            };

            return(response);
        }
        public void CardsWithSameFaceAndDifferentSuitAreNotEqual()
        {
            var AceOfSpades   = new StandardCard(Suit.Spades, Face.Ace);
            var AceOfDiamonds = new StandardCard(Suit.Diamonds, Face.Ace);

            Assert.NotEqual(AceOfSpades, AceOfDiamonds);
        }
Пример #4
0
        public static SkillResponse MakeSkillResponseWithCard(string outputSpeech,
                                                              bool shouldEndSession, StandardCard card,
                                                              string repromptText = "Reprompt Text")
        {
            var response = new ResponseBody
            {
                ShouldEndSession = shouldEndSession,
                OutputSpeech     = new PlainTextOutputSpeech {
                    Text = outputSpeech
                }
            };

            if (repromptText != null)
            {
                response.Reprompt = new Reprompt()
                {
                    OutputSpeech = new PlainTextOutputSpeech()
                    {
                        Text = repromptText
                    }
                };
            }

            var skillResponse = new SkillResponse
            {
                Response = response,
                Version  = "1.0"
            };

            if (card != null)
            {
                response.Card = card;
            }
            return(skillResponse);
        }
        public void CardsWithSameSuitAndFaceAreEqual()
        {
            var AceOfSpades1 = new StandardCard(Suit.Spades, Face.Ace);
            var AceOfSpades2 = new StandardCard(Suit.Spades, Face.Ace);

            Assert.True(AceOfSpades1.Equals(AceOfSpades2));
        }
Пример #6
0
        public StandardCard SetStandardCard(string title, string content, CardImage images)
        {
            StandardCard card = new StandardCard {
                Title = title, Content = content, Image = images
            };

            return(card);
        }
Пример #7
0
        public static SpeechletResponse BuildSpeechletResponse(SimpleIntentResponse simpleIntentResponse, bool shouldEndSession)
        {
            SpeechletResponse response = new SpeechletResponse();

            response.ShouldEndSession = shouldEndSession;

            // Create the speechlet response from SimpleIntentResponse.
            // If there's an ssmlString use that as the spoken reply
            // If ssmlString is empty, speak cardText

            if (simpleIntentResponse.ssmlString != "")
            {
                SsmlOutputSpeech speech = new SsmlOutputSpeech();
                speech.Ssml           = simpleIntentResponse.ssmlString;
                response.OutputSpeech = speech;
            }
            else
            {
                PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
                speech.Text           = simpleIntentResponse.cardText;
                response.OutputSpeech = speech;
            }


            // if images are passed, then assume a standard card is wanted
            // images should be stored in the ~/Images/ folder and follow these requirements

            // JPEG or PNG supported, no larger than 2MB
            // 720x480 - small size recommendation
            // 1200x800 - large size recommendation

            if (simpleIntentResponse.smallImage != "" && simpleIntentResponse.largeImage != "")
            {
                StandardCard card = new StandardCard();
                card.Title = AlexaConstants.AppName;
                card.Text  = simpleIntentResponse.cardText;

                // The trailing slash after the image name is required because we're serving off the image through a Web API controller and
                // don't want to change the default web project settings

                card.Image = new Image()
                {
                    LargeImageUrl = "https://" + System.Web.HttpContext.Current.Request.Url.Host + "/api/alexaimages/" + simpleIntentResponse.largeImage + "/",
                    SmallImageUrl = "https://" + System.Web.HttpContext.Current.Request.Url.Host + "/api/alexaimages/" + simpleIntentResponse.smallImage + "/",
                };

                response.Card = card;
            }
            else
            {
                SimpleCard card = new SimpleCard();
                card.Title    = AlexaConstants.AppName;
                card.Content  = simpleIntentResponse.cardText;
                response.Card = card;
            }

            return(response);
        }
Пример #8
0
        public SkillResponseBuilder WithCard(string title, string content)
        {
            Card = new StandardCard()
            {
                Title   = title,
                Content = content,
            };

            return(this);
        }
Пример #9
0
        public void Creates_Valid_StandardCard()
        {
            var cardImages = new CardImage {
                SmallImageUrl = "https://example.com/smallImage.png", LargeImageUrl = "https://example.com/largeImage.png"
            };
            var actual = new StandardCard {
                Title = ExampleTitle, Content = ExampleBodyText, Image = cardImages
            };

            Assert.True(Utility.CompareJson(actual, "StandardCard.json"));
        }
    string GetSuits(List <int> suits)
    {
        string res = "";

        foreach (int suit in suits)
        {
            res += StandardCard.GetSuit(suit) + " ";
        }

        return(res);
    }
    string GetRanks(List <int> ranks)
    {
        string res = "";

        foreach (int rank in ranks)
        {
            res += StandardCard.GetRank(rank) + " ";
        }

        return(res);
    }
Пример #12
0
        public void HasStandardCardPositiveCheck()
        {
            var assertCard = new StandardCard {
                Content = "test"
            };
            var response = ResponseBuilder.Empty();

            response.Response.Card = assertCard;
            var StandardCard = response.HasCard <StandardCard>();

            Assert.NotNull(StandardCard);
            Assert.Equal(assertCard, StandardCard);
        }
Пример #13
0
        public override SkillResponse CreateResponse()
        {
            SkillResponse response = ResponseBuilder.Tell(Speech);
            StandardCard  card     = new StandardCard();

            card.Title                         = Title;
            card.Content                       = Content;
            card.Image                         = new CardImage();
            card.Image.SmallImageUrl           = SmallImageUrl;
            card.Image.LargeImageUrl           = LargeImageUrl;
            response.Response.Card             = card;
            response.Response.ShouldEndSession = true;

            return(response);
        }
Пример #14
0
        /// <summary>
        /// Return the response fact, if user enters a known detail for a state e.g. says "17" find the
        /// information for that state e.g. Ohio, and then return the complete set
        /// </summary>
        /// <param name="input"></param>
        /// <param name="innerResponse"></param>
        /// <returns>void</returns>
        private void AnswerFacts(SkillRequest input, IOutputSpeech innerResponse)
        {
            SsmlOutputSpeech output = (innerResponse as SsmlOutputSpeech);

            string textout       = string.Empty;
            var    intentRequest = input.Request;
            Item   item          = GetItem(intentRequest.Intent.Slots, out textout);

            if (item != null && item.Capital != null)
            {
                if (this.USE_CARDS_FLAG)
                {
                    StandardCard card = new StandardCard();

                    card.Title             = GetCardTitle(item);
                    card.text              = GetTextDescription(item);
                    response.Response.Card = card;

                    card.Image = new CardImage();
                    card.Image.LargeImageUrl = GetLargeImage(item);
                    card.Image.SmallImageUrl = GetSmallImage(item);

                    output.Ssml = GetSpeechDescriptionWithCard(item);
                    response.SessionAttributes.Add(RESPONSE, output.Ssml);
                }
                else
                {
                    output.Ssml = GetSpeechDescription(item);
                    response.SessionAttributes.Add(RESPONSE, output.Ssml);
                }

                SsmlOutputSpeech repromptResponse = new SsmlOutputSpeech();
                repromptResponse.Ssml      = DecorateSsml(REPROMPT_SPEECH);
                response.Response.Reprompt = new Reprompt();
                response.Response.Reprompt.OutputSpeech = repromptResponse;
            }
            else
            {
                output.Ssml = GetBadAnswer(textout);
                response.SessionAttributes.Add(RESPONSE, output.Ssml);
                response.Response.Reprompt = new Reprompt();
                response.Response.Reprompt.OutputSpeech = innerResponse;
            }
        }
Пример #15
0
        /// <summary>
        /// Builds out the deck of 52 cards.
        /// </summary>
        /// <returns></returns>
        protected override IList <Card> BuildDeck()
        {
            List <Card> cards = new List <Card>();    //list that will hold the cards

            // Get all of the suit
            var suits = Enum.GetValues(typeof(StandardCard.Suits)).Cast <StandardCard.Suits>();

            // Get all of the ranks
            var ranks = Enum.GetValues(typeof(StandardCard.Ranks)).Cast <StandardCard.Ranks>();

            // Foreach through each suit
            foreach (var suit in suits)
            {
                // Foreach through each rank
                foreach (var rank in ranks)
                {
                    // Create a card and add to cards
                    StandardCard card = new StandardCard(suit, rank);
                    cards.Add(card);
                }
            }

            return(cards);
        }
Пример #16
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public SkillResponse FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            SkillResponse response = new SkillResponse();

            response.Response = new ResponseBody();
            response.Response.ShouldEndSession = false;

            // initialiize the variables we ultimately need for output, the response text and the card
            IOutputSpeech innerResponse = null;
            ICard         responseCard  = null;

            var log = context.Logger;

            log.LogLine($"CoolPlaces Skill Request Object:");
            log.LogLine(JsonConvert.SerializeObject(input));

            // Get what we need to get the zip code from the device
            string alexaDeviceID    = input.Context.System.Device.DeviceID;
            string alexaAPItoken    = input.Context.System.ApiAccessToken;
            string alexaAPIEndpoint = input.Context.System.ApiEndpoint;

            log.LogLine($"CoolPlaces Skill DeviceID:");
            log.LogLine(alexaDeviceID);
            log.LogLine($"CoolPlaces Skill APIAccessToken:");
            log.LogLine(alexaAPItoken);
            log.LogLine($"CoolPlaces Skill APIEndpoint:");
            log.LogLine(alexaAPIEndpoint);

            //alexa url info
            string ep1            = "/v1/devices/";
            string ep2            = "/settings/address/countryAndPostalCode";
            string alexaLookupURL = alexaAPIEndpoint + ep1 + alexaDeviceID + ep2;

            log.LogLine($"CoolPlaces Skill DeviceLocationEndpoint:");
            log.LogLine(alexaLookupURL);

            // this is where we get the location info from alexa.
            //if it errors out, we know we dont have the permissions yet
            string deviceLocationJSON = Utilities.GetDeviceLocationFromAlexa(alexaAPItoken, alexaLookupURL);

            log.LogLine($"CoolPlaces Skill devicelocation result:");
            log.LogLine(deviceLocationJSON);
            //https://developer.amazon.com/docs/custom-skills/device-address-api.html
            //https://developer.amazon.com/blogs/alexa/post/0c975fc7-17dd-4f5c-8343-a37024b66c99/alexa-skill-recipe-using-the-device-address-api-to-request-information
            string defaultZipCode = "45150";

            bool zipFound = false;

            string zipCode = "";

            //  look to see if the location request errored out, then we know we need to ask for permissions
            if (!deviceLocationJSON.Contains("error code:") && !deviceLocationJSON.Contains("error:"))
            {
                zipFound = true;

                // get the zipcode from the json
                log.LogLine($"CoolPlaces Skill devicelocation found!!!!:");
                log.LogLine(deviceLocationJSON);


                zipCode = Utilities.ExtractDeviceZipCodeFromJSON(log, deviceLocationJSON, defaultZipCode);;
                log.LogLine($"CoolPlaces Skill zipcode:");
                log.LogLine(zipCode);
            }
            else
            {
                // default the zip code
                zipCode = defaultZipCode;
                log.LogLine($"CoolPlaces Skill devicelocation not found :( ");
                log.LogLine(deviceLocationJSON);
            }


            // google variables
            string googleAPIKey = "&key=AIzaSyCM0J-Drb3xKzY96XecL7khAfs33zM4Uac";

            Utilities.PlaceType googlePlaceType = Utilities.PlaceType.bar;
            int googleMileRadiusForSearch       = 10;

            // fetch the location to use for the google search using the zipcode
            string loct = Utilities.GetLocationDataForZipFromGoogle(zipCode, googleAPIKey);
            string googleBaseLocationURLParam = "location=" + loct;

            // initialize the variables and fetch the cool places from google
            var allResources = Utilities.InitCoolPlaces(googleMileRadiusForSearch, googleBaseLocationURLParam, googlePlaceType, googleAPIKey);
            // grab a result from all of the results
            var resource = allResources.FirstOrDefault();

            string responseText = "";

            if (input.GetRequestType() == typeof(LaunchRequest))
            {
                log.LogLine($"CoolPlaces Default LaunchRequest made: 'Alexa, open Cool Places'");

                if (!zipFound)
                {
                    log.LogLine($"CoolPlaces : Need Permissions");

                    innerResponse = new PlainTextOutputSpeech();
                    responseText  = "I need your permission for your location to find cool places near you.  Please see your alexa app to grant me this permission.";
                    (innerResponse as PlainTextOutputSpeech).Text = responseText;

                    AskForPermissionsConsentCard permissionCard = new AskForPermissionsConsentCard();
                    permissionCard.Permissions.Add("read::alexa:device:all:address:country_and_postal_code");

                    responseCard = permissionCard;
                }
                else
                {
                    // everything is fine, so log where we landed
                    // we will create the response text and card at the end of this routine
                    log.LogLine($"CoolPlaces : Dont Need Permissions");
                    log.LogLine($"CoolPlaces LaunchRequest");
                }
            }
            else if (input.GetRequestType() == typeof(IntentRequest))
            {
                var intentRequest = (IntentRequest)input.Request;

                // create response text for intents other than the full cool place response, we will do that one at the end
                switch (intentRequest.Intent.Name)
                {
                case "AMAZON.CancelIntent":
                    log.LogLine($"CoolPlaces AMAZON.CancelIntent: send StopMessage");
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = resource.StopMessage;
                    response.Response.ShouldEndSession            = true;
                    break;

                case "AMAZON.StopIntent":
                    log.LogLine($"CoolPlaces AMAZON.StopIntent: send StopMessage");
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = resource.StopMessage;
                    response.Response.ShouldEndSession            = true;
                    break;

                case "AMAZON.HelpIntent":
                    log.LogLine($"CoolPlaces AMAZON.HelpIntent: send HelpMessage");
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = resource.HelpMessage;
                    break;

                case "AMAZON.FallbackIntent":
                    log.LogLine($"CoolPlaces AMAZON.FallbackIntent");
                    // Same as the help
                    //https://developer.amazon.com/docs/custom-skills/standard-built-in-intents.html#amazonfallbackintent-and-dialogdelegate
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = resource.HelpMessage;
                    break;

                case "AMAZON.NavigateHomeIntent":
                    log.LogLine($"CoolPlaces AMAZON.NavigateHomeIntent");
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = resource.StopMessage;
                    response.Response.ShouldEndSession            = true;
                    break;

                case "GetCoolPlaceIntent":
                    // everything is fine, so log where we landed
                    // we will create the response text and card at the end of this routine
                    log.LogLine($"CoolPlaces GetCoolPlaceIntent sent: send cool place");
                    break;

                case "GetNewCoolPlaceIntent":
                    // everything is fine, so log where we landed
                    // we will create the response text and card at the end of this routine
                    log.LogLine($"CoolPlaces GetNewCoolPlaceIntent sent: send new cool place");
                    break;

                default:
                    log.LogLine($"CoolPlaces Unknown intent: " + intentRequest.Intent.Name);
                    innerResponse = new PlainTextOutputSpeech();
                    (innerResponse as PlainTextOutputSpeech).Text = resource.HelpReprompt;
                    break;
                }
            }

            // if we have no response to this point, then we need to get a cool place!!
            if (innerResponse == null)
            {
                log.LogLine($"CoolPlaces : form the response text and card for the cool place");

                CoolPlace    myCoolPlace    = null;
                StandardCard myStandardCard = null;
                CardImage    myCardImage    = null;

                // ****START
                // grab info from the API return values and format for alexa card
                myCoolPlace = Utilities.EmitCoolPlace(resource);

                innerResponse = new PlainTextOutputSpeech();
                responseText  = myCoolPlace.Name;
                (innerResponse as PlainTextOutputSpeech).Text = resource.GetCoolPlaceOpenMessage + responseText;

                //SimpleCard mySimpleCard = new SimpleCard();
                //responseCard = new AskForPermissionsConsentCard();
                //responseCard = new LinkAccountCard();
                myStandardCard            = new StandardCard();
                myCardImage               = new CardImage();
                myCardImage.SmallImageUrl = myCoolPlace.Photo.PhotoAPIURL(720, googleAPIKey);
                myCardImage.LargeImageUrl = myCoolPlace.Photo.PhotoAPIURL(1200, googleAPIKey);
                myStandardCard.Image      = myCardImage;

                myStandardCard.Content = myCoolPlace.Name + "\r\n" + myCoolPlace.Location + "\r\n Rating " + myCoolPlace.Rating + " out of 5" + "\r\n";
                myStandardCard.Title   = myCoolPlace.Name;
                responseCard           = myStandardCard;
                // ****END
            }

            /*
             * //accesstoken
             * //input.Context.System.User.AccessToken;
             * //input.Context.System.User.UserId;
             * User myUser = input.Context.System.User;
             * log.LogLine($"CoolPlaces Skill User Object:");
             * log.LogLine(JsonConvert.SerializeObject(myUser));
             */

            // take whatever card and/or response we have and send it to alexa
            response.Response.OutputSpeech = innerResponse;
            response.Response.Card         = responseCard;
            response.Version = "1.0";
            log.LogLine($"CoolPlaces Skill Response Object...");
            log.LogLine(JsonConvert.SerializeObject(response));
            return(response);
        }
        /// <summary>
        /// Creates the Skill Response which will be returned by the Azure Function.
        /// </summary>
        /// <param name="outputSpeech">Text which should be played</param>
        /// <param name="shouldEndSession">Indicated if the session should be ended</param>
        /// <param name="card">Card which will be shown in the companion app</param>
        /// <param name="useSsml">Indicates if the text is using SSML or not</param>
        private static SkillResponse GetSkillResponse(string outputSpeech, bool shouldEndSession, StandardCard card = null, bool useSsml = false)
        {
            var response = new ResponseBody
            {
                ShouldEndSession = shouldEndSession,
            };

            if (card != null)
            {
                response.Card       = card;
                response.Directives = new List <IDirective>
                {
                    new DisplayRenderTemplateDirective
                    {
                        Template = new BodyTemplate1
                        {
                            BackgroundImage = new TemplateImage
                            {
                                ContentDescription = "Picture",
                                Sources            = new List <ImageSource> {
                                    new ImageSource {
                                        Url = card.Image.LargeImageUrl
                                    }
                                }
                            },
                        }
                    }
                };
            }

            if (useSsml)
            {
                response.OutputSpeech = new SsmlOutputSpeech {
                    Ssml = outputSpeech
                }
            }
            ;
            else
            {
                response.OutputSpeech = new PlainTextOutputSpeech {
                    Text = outputSpeech
                }
            };

            var skillResponse = new SkillResponse
            {
                Response = response,
                Version  = "1.0"
            };

            return(skillResponse);
        }
    }
Пример #18
0
    public List <int> GetValidSuits(KMBombInfo bomb, List <int> suits, int startTime, string date, StandardCard firstCard)
    {
        switch (arcana)
        {
        case 1:
        {
            List <int> ret = new List <int>();
            foreach (char letter in bomb.GetSerialNumberLetters())
            {
                if (letter == 'S')
                {
                    ret.Add(SPADES);
                }
                else if (letter == 'D')
                {
                    ret.Add(DIAMONDS);
                }
                else if (letter == 'H')
                {
                    ret.Add(HEARTS);
                }
                else if (letter == 'C')
                {
                    ret.Add(CLUBS);
                }
            }

            if (ret.Count() == 0)
            {
                ret.AddRange(new int[] { CLUBS, DIAMONDS, HEARTS, SPADES });
            }

            return(ret);
        }

        case 2:
        {
            List <int> ret = new List <int>();
            if (bomb.GetBatteryCount() != 0 &&
                bomb.GetBatteryCount() != bomb.GetBatteryHolderCount() &&
                bomb.GetBatteryCount() != 2 * bomb.GetBatteryHolderCount() &&
                bomb.GetOnIndicators().Count() != 0 &&
                bomb.GetOffIndicators().Count() != 0 &&
                bomb.GetPortPlateCount() != 0)
            {
                ret.AddRange(new int[] { CLUBS, DIAMONDS, HEARTS, SPADES });
            }
            else
            {
                ret.Add(CLUBS);
            }
            return(ret);
        }

        case 3:
        {
            List <int> ret = new List <int>();
            ret.AddRange(new int[] { HEARTS, DIAMONDS });
            return(ret);
        }

        case 4:
        {
            List <int> ret = new List <int>();
            ret.AddRange(new int[] { SPADES, CLUBS });
            return(ret);
        }

        case 5:
        {
            List <int> ret = new List <int>();
            if (date == "Saturday" || date == "Sunday")
            {
                ret.AddRange(new int[] { CLUBS, DIAMONDS, HEARTS, SPADES });
            }
            else
            {
                ret.Add(DIAMONDS);
            }
            return(ret);
        }

        case 6:
        {
            List <int> ret = new List <int>();
            ret.Add(HEARTS);
            return(ret);
        }

        case 7:
        {
            List <int> ret = new List <int>();
            if (startTime % 7 == 0 ||
                bomb.GetModuleNames().Count() % 7 == 0 ||
                bomb.GetSerialNumberNumbers().Sum() % 7 == 0)
            {
                ret.AddRange(new int[] { CLUBS, DIAMONDS, HEARTS, SPADES });
            }
            else
            {
                ret.Add(SPADES);
            }
            return(ret);
        }

        case 10:
        {
            List <int> ret = new List <int>();
            if (bomb.GetSerialNumberNumbers().Sum() % 22 == 10)
            {
                ret.AddRange(new int[] { CLUBS, DIAMONDS, HEARTS, SPADES });
                return(ret);
            }
            arcana = bomb.GetSerialNumberNumbers().Sum() % 22;
            return(GetValidSuits(bomb, suits, startTime, date, firstCard));
        }

        case 13:
        {
            List <int> ret = new List <int>();
            for (int i = 0; i <= 3; i++)
            {
                if (!suits.Exists(x => x == i))
                {
                    ret.Add(i);
                }
            }
            return(ret);
        }

        case 14:
        {
            List <int> ret = new List <int>();
            if (bomb.GetModuleNames().Count() - bomb.GetSolvableModuleNames().Count() != 0)
            {
                ret.AddRange(new int[] { CLUBS, DIAMONDS, HEARTS, SPADES });
            }
            else
            {
                ret.Add(SPADES);
            }
            return(ret);
        }

        case 15:
        {
            List <int> ret = new List <int>();
            ret.AddRange(new int[] { HEARTS, DIAMONDS });
            return(ret);
        }

        case 17:
        {
            List <int> ret = new List <int>();

            if (firstCard.GetType() == typeof(StandardCard))
            {
                if (firstCard.rank >= 2 && firstCard.rank <= 6)
                {
                    ret.AddRange(new int[] { SPADES });
                }
                else if (firstCard.rank >= 7 && firstCard.rank <= 9)
                {
                    ret.AddRange(new int[] { CLUBS });
                }
                else
                {
                    ret.AddRange(new int[] { DIAMONDS, HEARTS });
                }
            }
            else if (firstCard.GetType() == typeof(MetropolitanCard))
            {
                if (firstCard.rank >= 2 && firstCard.rank <= 6)
                {
                    ret.AddRange(new int[] { SPADES, CLUBS });
                }
                else if (firstCard.rank >= 7 && firstCard.rank <= 9)
                {
                    ret.AddRange(new int[] { SPADES });
                }
                else
                {
                    ret.AddRange(new int[] { CLUBS });
                }
            }
            else if (firstCard.GetType() == typeof(MaritimeCard))
            {
                if (firstCard.rank >= 2 && firstCard.rank <= 6)
                {
                    ret.AddRange(new int[] { SPADES });
                }
                else if (firstCard.rank >= 7 && firstCard.rank <= 9)
                {
                    ret.AddRange(new int[] { CLUBS });
                }
                else
                {
                    ret.AddRange(new int[] { CLUBS });
                }
            }
            else if (firstCard.GetType() == typeof(ArcticCard))
            {
                if (firstCard.rank >= 2 && firstCard.rank <= 6)
                {
                    ret.AddRange(new int[] { SPADES });
                }
                else if (firstCard.rank >= 7 && firstCard.rank <= 9)
                {
                    ret.AddRange(new int[] { SPADES, CLUBS });
                }
                else
                {
                    ret.AddRange(new int[] { HEARTS, DIAMONDS });
                }
            }
            else if (firstCard.GetType() == typeof(TropicalCard))
            {
                if (firstCard.rank >= 2 && firstCard.rank <= 6)
                {
                    ret.AddRange(new int[] { HEARTS, DIAMONDS });
                }
                else if (firstCard.rank >= 7 && firstCard.rank <= 9)
                {
                    ret.AddRange(new int[] { SPADES, CLUBS });
                }
                else
                {
                    ret.AddRange(new int[] { CLUBS });
                }
            }
            else if (firstCard.GetType() == typeof(OasisCard))
            {
                if (firstCard.rank >= 2 && firstCard.rank <= 6)
                {
                    ret.AddRange(new int[] { SPADES });
                }
                else if (firstCard.rank >= 7 && firstCard.rank <= 9)
                {
                    ret.AddRange(new int[] { SPADES, CLUBS });
                }
                else
                {
                    ret.AddRange(new int[] { CLUBS });
                }
            }
            else
            {
                ret.AddRange(new int[] { SPADES, DIAMONDS, HEARTS, CLUBS });
            }

            return(ret);
        }
        }

        return(suits);
    }
    #pragma warning restore 414
    IEnumerator ProcessTwitchCommand(string command)
    {
        if (Application.isEditor)
        {
            command = command.Trim();
        }

        if (Regex.IsMatch(command, @"^\s*reset\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
        {
            yield return(null);

            btns[0].OnInteract();
            yield break;
        }
        else if (Regex.IsMatch(command, @"^\s*submit\s*$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
        {
            yield return(null);

            btns[1].OnInteract();
            yield break;
        }
        string[] parameters = command.Split(' ');
        if (Regex.IsMatch(command, @"^\s*card\s+", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
        {
            string potentialSubCmd = command.Substring(4).Trim();
            if (Regex.IsMatch(potentialSubCmd, @"^\d+$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
            {
                yield return(null);

                int dest;
                int.TryParse(parameters[1], out dest);
                dest--;
                if (currentCard < dest)
                {
                    int start = currentCard;
                    for (int i = 0; i < dest - start; i++)
                    {
                        nextCard.OnInteract();
                        do
                        {
                            yield return(string.Format("trycancel The card flipping animation has been canceled. The card has stopped on card Nº {0}", currentCard));
                        }while (animating);
                    }
                }
                else if (currentCard > dest)
                {
                    int start = currentCard;
                    for (int i = 0; i < start - dest; i++)
                    {
                        prevCard.OnInteract();
                        do
                        {
                            yield return(string.Format("trycancel The card flipping animation has been canceled. The card has stopped on card Nº {0}", currentCard));
                        }while (animating);
                    }
                }
                else
                {
                    yield return("sendtochaterror The module is already on the specified card!");
                }
            }
            else if (Regex.IsMatch(potentialSubCmd, @"^info$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
            {
                StandardCard selectedCard = deckCreated.ElementAtOrDefault(currentCard);
                if (selectedCard == null)
                {
                    yield return(string.Format("sendtochat That is not a card. I don't know what that is."));
                }
                else
                {
                    yield return(string.Format("sendtochat {0}", selectedCard.PrintTPCardInfo()));
                }
                yield break;
            }
            else if (Regex.IsMatch(potentialSubCmd, @"^(next|r(ight)?)$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
            {
                if (currentCard == 39)
                {
                    yield return("sendtochaterror {0}, you are already at the end of the deck!");

                    yield break;
                }
                yield return(null);

                nextCard.OnInteract();
                yield break;
            }
            else if (Regex.IsMatch(potentialSubCmd, @"^(prev(ious)?|l(eft)?)$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant))
            {
                if (currentCard == -1)
                {
                    yield return("sendtochaterror {0}, you are already at the start of the deck!");

                    yield break;
                }
                yield return(null);

                prevCard.OnInteract();
                yield break;
            }
            else
            {
                yield return(string.Format("sendtochaterror Unknown subcommand \"{0}\"", potentialSubCmd));

                yield break;
            }
            yield break;
        }
    }
Пример #20
0
        public SkillResponse flashBriefing()
        {
            String responseString = "These are the top three news posts on Reddit. ";

            var subredditTask = reddit.SearchSubreddits(SUBREDDIT_FOR_FLASHBRIEFING, 1).First();

            subredditTask.Wait();
            var sr = subredditTask.Result;

            log.LogLine($"WorldNews Subreddit: {sr}");

            var posts = sr.GetPosts(3).ToList <Post>();

            posts.Wait();


            log.LogLine("Posts (toString): " + posts.ToString());
            var i = 0;

            String[] postIntro = { "First Post", "Second Post", "Third Post" };

            List <Post> storedPosts = posts.Result;
            String      imageURL    = "";

            foreach (var post in storedPosts)
            {
                log.LogLine($"Post Title ({i}) | {postIntro[i]}: {post.Title}");
                responseString += $"{postIntro[i]}: {post.Title}. ";
                i++;

                String img = storedPosts[0].Thumbnail.ToString();
                if (img != null && img != "")
                {
                    imageURL = img;
                    break;
                }
            }
            responseString += "See the feed in your Alexa App for more Info.";
            log.LogLine("FullSkillResponse FlashBriefing: " + responseString);

            //CARD
            StandardCard card = new StandardCard();

            card.Title = "The Top 3 News from Reddit";

            String cardContent = $"{storedPosts[0].Title} " +
                                 $"(See more: {storedPosts[0].Url})\n\n" +
                                 $"{storedPosts[1].Title} (See more: {storedPosts[1].Url})\n\n" +
                                 $"{storedPosts[2].Title} (See more: {storedPosts[2].Url})";

            card.Content = cardContent;
            log.LogLine("FlashBriefingCard CardContent: " + cardContent);

            //IMAGE FOR CARD
            if (imageURL != "")
            {
                CardImage cardImage = new CardImage();
                log.LogLine("FlashBriefingCard CardImageURL: " + imageURL);
                cardImage.SmallImageUrl = imageURL;
                cardImage.LargeImageUrl = imageURL;
                card.Image = cardImage;
            }
            else
            {
                log.LogLine("FlashBriefingCard CardImageURL: No post had an image");
            }

            return(Function.MakeSkillResponseWithCard(responseString, true, card));
        }
Пример #21
0
        public static SpeechletResponse BuildSpeechletResponse(SimpleIntentResponse simpleIntentResponse, bool shouldEndSession)
        {
            SpeechletResponse response = new SpeechletResponse();

            response.ShouldEndSession = shouldEndSession;

            List <Directives> directives = new List <Directives>();

            // if there's a value present for musicUrl, this then generate the directives
            // required for Echo to play the requested track

            if (simpleIntentResponse.musicUrl != "")
            {
                // figure out if we are dealing with a multi-track album
                // the token we send Echo is in this format if so:
                // <MusicId>?<Index>

                string[] items         = simpleIntentResponse.msgId.Split('?');
                int      msgAlbumIndex = -1;
                string   msgAlbumId    = "";

                // if there are two members of the array item[] then
                // we are dealing with a multi-track album

                if (items.Length == 2)
                {
                    msgAlbumId    = items[0];
                    msgAlbumIndex = int.Parse(items[1]);
                }

                if (msgAlbumIndex < 1 || simpleIntentResponse.musicAction == "AMAZON.NextIntent")
                {
                    directives = new List <Directives>()
                    {
                        new Directives()
                        {
                            type         = "AudioPlayer.Play",
                            playBehavior = "REPLACE_ALL",
                            audioItem    = new Directives.AudioItem()
                            {
                                stream = new Directives.Stream()
                                {
                                    offsetInMilliseconds = 0,
                                    token = simpleIntentResponse.msgId,
                                    url   = simpleIntentResponse.musicUrl,
                                }
                            },
                        }
                    };

                    // the next intent doesn't require a card to be generated

                    if (simpleIntentResponse.musicAction == "AMAZON.NextIntent")
                    {
                        response.Directives = directives;
                        return(response);
                    }
                }
                else
                {
                    int    previousIndex = msgAlbumIndex - 1;
                    string previousToken = msgAlbumId + "?" + previousIndex;

                    directives = new List <Directives>()
                    {
                        new Directives()
                        {
                            type         = "AudioPlayer.Play",
                            playBehavior = "ENQUEUE",
                            audioItem    = new Directives.AudioItem()
                            {
                                stream = new Directives.Stream()
                                {
                                    offsetInMilliseconds = 0,
                                    token = simpleIntentResponse.msgId,
                                    url   = simpleIntentResponse.musicUrl,
                                    expectedPreviousToken = previousToken,
                                }
                            },
                        }
                    };

                    // the enqueue intent can not have a card associated with it
                    // otherwise, Alexa will return an error

                    response.Directives = directives;
                    return(response);
                }
                response.Directives = directives;
            }



            // Create the speechlet response from SimpleIntentResponse.
            // If there's an ssmlString use that as the spoken reply
            // If ssmlString is empty, speak cardText

            if (simpleIntentResponse.ssmlString != "")
            {
                SsmlOutputSpeech speech = new SsmlOutputSpeech();
                speech.Ssml           = simpleIntentResponse.ssmlString;
                response.OutputSpeech = speech;
            }
            else
            {
                PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
                speech.Text           = simpleIntentResponse.cardText;
                response.OutputSpeech = speech;
            }


            // if images are passed, then assume a standard card is wanted
            // images should be stored in the ~/Images/ folder and follow these requirements

            // JPEG or PNG supported, no larger than 2MB
            // 720x480 - small size recommendation
            // 1200x800 - large size recommendation

            if (simpleIntentResponse.smallImage != "" && simpleIntentResponse.largeImage != "")
            {
                StandardCard card = new StandardCard();
                card.Title = AlexaConstants.AppName;
                card.Text  = simpleIntentResponse.cardText;

                // The trailing slash after the image name is required because we're serving off the image through a Web API controller and
                // don't want to change the default web project settings

                card.Image = new Image()
                {
                    //LargeImageUrl = "https://" + System.Web.HttpContext.Current.Request.Url.Host + "/api/alexaimages/" + simpleIntentResponse.largeImage + "/",
                    //SmallImageUrl = "https://" + System.Web.HttpContext.Current.Request.Url.Host + "/api/alexaimages/" + simpleIntentResponse.smallImage + "/",
                    LargeImageUrl = simpleIntentResponse.largeImage,
                    SmallImageUrl = simpleIntentResponse.smallImage
                };

                response.Card = card;
            }
            else
            {
                SimpleCard card = new SimpleCard();
                card.Title    = AlexaConstants.AppName;
                card.Content  = simpleIntentResponse.cardText;
                response.Card = card;
            }

            return(response);
        }
Пример #22
0
        /// <summary>
        /// Creates a new meld from the given tiles.
        /// </summary>
        /// <param name="meld">The tiles to meld.</param>
        /// <param name="concealed">If true, the meld will be treated as concealed.</param>
        public MahjongMeld(IEnumerable <Card> meld, bool concealed = false) : base(meld)
        {
            Chow = false;
            Pung = false;
            Kong = false;
            Eye  = false;

            ThirteenOrphans = false;
            NineGates       = false;
            SevenPair       = false;

            Concealed          = concealed;
            ExposedFromExposed = false;

            // There are two special cases we need to handle
            // There's thirteen orphans and nine gates (the latter is a special case because it must be all concealed and has meaning beyond the melds it makes)
            if (CardsInHand == 14)
            {
                // Thirteen orphans is easier to check, so do that first
                Card[] orphans = { new StandardCard(new SimpleSuit(SuitIdentifier.BAMBOO),       new ValueN(1, "One")), new StandardCard(new SimpleSuit(SuitIdentifier.BAMBOO),    new ValueN(9,                                               "Nine")),
                                   new StandardCard(new SimpleSuit(SuitIdentifier.CHARACTER),    new ValueN(1, "One")), new StandardCard(new SimpleSuit(SuitIdentifier.CHARACTER), new ValueN(9,                                               "Nine")),
                                   new StandardCard(new SimpleSuit(SuitIdentifier.DOT),          new ValueN(1, "One")), new StandardCard(new SimpleSuit(SuitIdentifier.DOT),       new ValueN(9,                                               "Nine")),
                                   new StandardCard(new HonourSuit(SuitIdentifier.GREEN_DRAGON), new ValueN(0, null),   "Green Dragon"),                                           new StandardCard(new HonourSuit(SuitIdentifier.RED_DRAGON), new ValueN(0,null),  "Red Dragon"), new StandardCard(new HonourSuit(SuitIdentifier.WHITE_DRAGON), new ValueN(0, null), "White Dragon"),
                                   new StandardCard(new HonourSuit(SuitIdentifier.EAST_WIND),    new ValueN(0, null),   "East Wind"),                                              new StandardCard(new HonourSuit(SuitIdentifier.SOUTH_WIND), new ValueN(0,null),  "South Wind"), new StandardCard(new HonourSuit(SuitIdentifier.WEST_WIND),    new ValueN(0, null), "West Wind"),   new StandardCard(new HonourSuit(SuitIdentifier.NORTH_WIND),new ValueN(0, null), "North Wind") };

                for (int i = 0; i < 13; i++)
                {
                    if (!Cards.Contains(orphans[i]))
                    {
                        break;
                    }
                    else if (i == 12)
                    {
                        ThirteenOrphans = true;
                        return;
                    }
                }

                // We don't have thirteen orphans, so check for seven pairs
                Hand temp = new StandardHand(Cards);

                // Check for pairs by sheer brute force
                for (int i = 0; i < 7; i++)
                {
                    Card c = temp.PlayCard(0);

                    if (!temp.Cards.Contains(c))
                    {
                        break;
                    }

                    temp.PlayCard(c);

                    if (i == 6)
                    {
                        SevenPair = true;
                        return;
                    }
                }

                // We don't have thirteen orphans or seven pairs, so check for nine gates
                CardSuit suit = Cards[0].Suit;

                // For optimisation, we check this here rather than letting it be implicitly check later by asking for values
                if (suit.Color != SuitColor.SIMPLE)
                {
                    return;
                }

                // Each card must be the same suit
                for (int i = 1; i < 14; i++)
                {
                    if (!suit.Equals(Cards[i].Suit))
                    {
                        return;
                    }
                }

                // Now we need the tiles 1112345678999 and one extra
                temp = new StandardHand(Cards);
                string[] value_names = { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };

                // Check if all the cards are there by brute force
                for (int i = 1; i < 10; i++)
                {
                    for (int j = (i == 1 || i == 9 ? 0 : 2); j < 3; j++)                  // Ones and nines need to be played thrice
                    {
                        Card c = new StandardCard(suit, new ValueN(i, value_names[i - 1]));

                        if (!temp.Cards.Contains(c))
                        {
                            return;
                        }

                        temp.PlayCard(c);
                    }
                }

                // The last card doesn't matter as we know it's the right suit, so we're done
                NineGates = true;
                return;
            }

            if (CardsInHand < 2 || CardsInHand > 4)
            {
                return;
            }

            if (CardsInHand == 2)
            {
                if (Cards[0].Equals(Cards[1]))
                {
                    Eye = true;
                }

                return;
            }

            // If we have four tiles, our only option is a kong
            if (CardsInHand == 4)
            {
                // A kong must have four equal tiles
                for (int i = 0; i < 3; i++)
                {
                    if (!Cards[i].Equals(Cards[i + 1]))
                    {
                        return;
                    }
                }

                Kong = true;
                return;
            }

            // If we have three tiles and the first two are equal, we either have a pung or nothing
            if (Cards[0].Equals(Cards[1]))
            {
                if (!Cards[1].Equals(Cards[2]))
                {
                    return;
                }
                else
                {
                    Pung = true;
                    return;
                }
            }

            // We now have a chow or nothing, so make sure the tiles are of the same suit and are sequential
            if (!Cards[0].Suit.Equals(Cards[1].Suit) || !Cards[1].Suit.Equals(Cards[2].Suit))
            {
                return;
            }

            SortByValue();

            if (!ApproxEqual(Cards[0].Value.MaxValue + 1.0, Cards[1].Value.MaxValue) || !ApproxEqual(Cards[1].Value.MaxValue + 1.0, Cards[2].Value.MaxValue))
            {
                return;
            }

            Chow = true;
            return;
        }