public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> item)
        {
            var message = await item;

            if (message.Text == "/end")
            {
                context.Done <object>(null);
            }
            else
            {
                if (message.ChannelId == "skypeforbusiness")
                {
                    json = await GenerateAnswer.GetResultAsync(message.Text);

                    if (json != "failture")
                    {
                        var result = JsonConvert.DeserializeObject <QnAMakerResults>(json);
                        await ShowQuestions(context, result);
                    }
                }
                else
                {
                    await context.Forward(new BasicQnAMakerDialog(), AfterAnswerAsync, message, CancellationToken.None);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="SinglePlayerMaze"/> class.
 /// </summary>
 /// <param name="answer">The answer.</param>
 /// <param name="rows">The rows.</param>
 /// <param name="cols">The cols.</param>
 public SinglePlayerMaze(GenerateAnswer answer, int rows, int cols)
 {
     this.answer = answer;
     this.cols   = cols;
     this.rows   = rows;
     // place the player at the start of the maze
     this.playerPosition = new MazePosition(this.answer.Start);
     this.hint           = new MazePosition(this.answer.Start);
 }
Exemple #3
0
        /// <summary>
        /// Attempts to fetch a game from the model's data.
        /// If the game does not exist, a check is performed to see if the sending client is in a different game.
        ///     if so, the function closes.
        ///     Otherwise we create the game, and add the client to the game.
        /// Otherwise, if the game exists, the model attemps to add the client to the game.
        ///     if succeeded, the game now contains 2 different client, so a maze is generated,
        ///     given a name, and sent to the first client.
        ///     then a different starting position is given to the same maze and it is sent to the second client.
        /// if the client could not be added to the game the function exists.
        /// </summary>
        /// <param name="from">the client that sent the command.</param>
        /// <param name="commandParsed">The parsed command.</param>
        public override void Execute(object from, string[] commandParsed)
        {
            string          name        = commandParsed[1];
            int             commandType = 3;
            MultiplayerGame g           = model.GetMultiplayerGame(name);

            // game does not exist
            if (g == null)
            {
                // client is already in a different multiplayer game
                if (model.IsClientInGame(from) != null)
                {
                    return;
                }

                // otherwise create a game
                IMaze           maze = GenerateOption.CreateMaze(1);
                MultiplayerGame game = new MultiplayerGame(model, name, maze);
                game.AddClient(from);
                model.AddMultiplayerGame(name, game);
            }
            // game exists
            else
            {
                // add second(different) client to game, and if the game had not been started yet
                if (g.AddClient(from) && !g.IsInProgress())
                {
                    g.GameStarted();
                    string reply;
                    IMaze  maze = g.GetMaze();
                    IMaze  secondMaze;
                    object client;
                    string mazeName;

                    // generate answer for first client
                    mazeName = name + "_1";
                    this.model.AddMaze(mazeName, maze);
                    GenerateAnswer firstClient = BuildMaze(maze, mazeName);

                    // change starting position for second client
                    mazeName   = name + "_2";
                    secondMaze = maze.CreateMazeChangeStartPosition();
                    this.model.AddMaze(mazeName, secondMaze);
                    GenerateAnswer secondClient = BuildMaze(secondMaze, mazeName);

                    // first client
                    g.RetrieveOtherClient(from, out client);
                    reply = BuildReply(name, commandType, firstClient, secondClient);
                    model.CompletedTask(client, new View.MessageEventArgs(reply));

                    // second client ('from' is the second player)
                    client = from;
                    reply  = BuildReply(name, commandType, secondClient, firstClient);
                    model.CompletedTask(client, new View.MessageEventArgs(reply));
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Builds a reply.
        /// </summary>
        /// <param name="name">The name of the maze.</param>
        /// <param name="type">The type of command.</param>
        /// <param name="myMaze">the first client's maze.</param>
        /// <param name="otherMaze">The other client's maze.</param>
        /// <returns>reply string</returns>
        private string BuildReply(string name, int type, GenerateAnswer myMaze, GenerateAnswer otherMaze)
        {
            MultiplayerAnswer ans = new MultiplayerAnswer();

            ans.Name     = name;
            ans.MazeName = name + " maze";
            ans.You      = myMaze;
            ans.Other    = otherMaze;

            return(new Answer().GetJSONAnswer(type, ans));
        }
Exemple #5
0
        private async Task SearchQuestion(IDialogContext context, IAwaitable <string> item)
        {
            var    message       = await item;
            string StrictFilters = "";

            if (SelectedCategory != FAQCategory.FAQCategory.CategoryList[FAQCategory.FAQCategory.CategoryList.Count - 1])
            {
                StrictFilters = ", \"strictFilters\": [ { \"name\": \"category\", \"value\": \"" + SelectedCategory + "\"}]";
            }

            await context.PostAsync($"「{SelectedCategory}」で探しています...");

            string json = await GenerateAnswer.GetResultAsync(message, StrictFilters);

            if (json != "failture")
            {
                var result = JsonConvert.DeserializeObject <QnAMakerResults>(json);
                await ShowQuestions(context, result);
            }
        }
Exemple #6
0
        private async Task ShowAnswer(IDialogContext context, IAwaitable <IMessageActivity> item)
        {
            var message = await item;

            if (message.Text == "上記のどれでもない")
            {
                await context.PostAsync("お役に立てず申し訳ございません。。");
                await AfterAnswerAsync(context, item);
            }
            else
            {
                string json = await GenerateAnswer.GetResultAsync(message.Text, "");

                if (json != "failture")
                {
                    var result = JsonConvert.DeserializeObject <QnAMakerResults>(json);
                    await context.PostAsync(result.Answers[0].Answer.ToString());
                    await AfterAnswerAsync(context, item);
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Builds a maze.
        /// </summary>
        /// <param name="maze">The maze.</param>
        /// <param name="name">The name of it.</param>
        /// <returns>
        /// GenerateAnswer class that represents the server's answer
        /// to a generate request </returns>
        private GenerateAnswer BuildMaze(IMaze maze, string name)
        {
            GenerateAnswer ans = new GenerateAnswer();

            JsonOptions.MazePosition start  = new JsonOptions.MazePosition();
            JsonOptions.MazePosition finish = new JsonOptions.MazePosition();

            ans.Name = name;
            StringBuilder sb = new StringBuilder(maze.ToString());

            sb.Replace("\n", "", 0, sb.Length);
            ans.Maze = sb.ToString();

            start.Row  = maze.GetStartPosition().Row;
            start.Col  = maze.GetStartPosition().Colomn;
            finish.Row = maze.GetFinishPosition().Row;
            finish.Col = maze.GetFinishPosition().Colomn;
            ans.Start  = start;
            ans.End    = finish;

            return(ans);
        }
Exemple #8
0
        /// <summary>
        /// Returns the list of answers for the given question sorted in descending order of ranking score. Top is 1 by default
        /// </summary>
        /// <returns>If Error return null</returns>
        public async Task <AnswerReturnList> GenerateAnswer(string question, int top = 1)
        {
            if (string.IsNullOrWhiteSpace(SubscriptionKey))
            {
                return(null);
            }

            if (string.IsNullOrWhiteSpace(KnowledgeId))
            {
                return(null);
            }

            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", SubscriptionKey);

            var uri = EndPoint + KnowledgeId + "/generateAnswer";

            using (var request = new HttpRequestMessage(new HttpMethod("POST"), uri))
            {
                var generateAnswer = new GenerateAnswer {
                    Question = question, Top = top
                };
                request.Content = new StringContent(JsonConvert.SerializeObject(generateAnswer), Encoding.UTF8, "application/json");

                var response = await client.SendAsync(request);

                if (!response.IsSuccessStatusCode)
                {
                    return(null);
                }

                var jsonResponse = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <AnswerReturnList>(jsonResponse));
            }
        }