Exemplo n.º 1
0
    public string[] GetWords()
    {
        if (_shuffledWords == null)
        {
            _shuffledWords       = new string[Answers.Length * Answers[0].Words.Length];
            _shuffledWordIndeces = new int[Answers.Length][];

            List <int> unusedIndeces = new List <int>(_shuffledWords.Length);

            for (int i = 0; i < _shuffledWords.Length; i++)
            {
                unusedIndeces.Add(i);
            }

            for (int answerIndex = 0; answerIndex < Answers.Length; answerIndex++)
            {
                PuzzleAnswer answer = Answers[answerIndex];

                _shuffledWordIndeces[answerIndex] = new int[answer.Words.Length];

                for (int wordIndex = 0; wordIndex < answer.Words.Length; wordIndex++)
                {
                    int index = unusedIndeces[UnityEngine.Random.Range(0, unusedIndeces.Count)];
                    _shuffledWords[index] = answer.Words[wordIndex];
                    _shuffledWordIndeces[answerIndex][wordIndex] = index;
                    unusedIndeces.Remove(index);
                }
            }
        }

        return(_shuffledWords);
    }
        public ActionResult AddPuzzleAnswer([FromBody] PuzzleAnswer PuzzleAnswer)
        {
            var question = _unitOfWork.Question.Get(PuzzleAnswer.QuestionId);

            if (question == null)
            {
                return(NotFound("Cant find Puzzle Id"));
            }
            else
            {
                if (PuzzleAnswer.Rating != null && question.HasRating == false)
                {
                    return(Conflict("This is question with open answer, You can`t add rating here"));
                }
                else if (PuzzleAnswer.Answer != null && question.HasRating == true)
                {
                    return(Conflict("This is question with rating, You can`t add open answer here"));
                }

                _unitOfWork.PuzzleAnswer.Add(PuzzleAnswer);
                PuzzleAnswer.SubmitDate = DateTime.Now;
                _unitOfWork.Complete();
                return(Ok(PuzzleAnswer));
            }
        }
Exemplo n.º 3
0
        private static void AutoSolve(Puzzle puzzle)
        {
            Console.Clear();
            PrintTemplates.Logo2();
            Console.WriteLine("\n    Searching for the shortest answer, Please wait.. !\n");

            PuzzleSolver solver = new PuzzleSolver(puzzle);

            PuzzleAnswer answer = solver.SolveAsync().Result;

            if (answer != null)
            {
                foreach (var item in answer.Path)
                {
                    Console.WriteLine(item);
                }

                Console.WriteLine("\tTested States Count: " + answer.TestedStatesCount);
                Console.WriteLine("\tShortest Answer Steps Count: " + answer.StepsCount);
            }
            else
            {
                Console.WriteLine("\tSorry, we couldn't find any answer!");
            }

            Console.WriteLine("\n\tPress any key to exit..");
            Console.ReadKey();
        }
Exemplo n.º 4
0
        private async void btnSolve_Click(object sender, EventArgs e)
        {
            Pause();
            PuzzleSolver solver = new PuzzleSolver(puzzle);

            answer = await solver.SolveAsync();

            Continue();

            timerSolving.Start();
        }
        public void Add_SingleAnswer_Returns_SameAnswer()
        {
            var options = new DbContextOptionsBuilder <TietoFeedbackToolContext>()
                          .UseInMemoryDatabase(databaseName: "Add_SingleAnswer_Returns_SameAnswer")
                          .Options;

            using (var context = new TietoFeedbackToolContext(options))
            {
                //Arrange
                var     unitOfWork = new UnitOfWork(context);
                Account newAccount = new Account()
                {
                    Login = "******", Name = "Filippa Eilhart"
                };
                unitOfWork.Account.Add(newAccount);
                Question newQuestion = new Question {
                    AccountLogin = "******", Domain = "localhost:44444", QuestionText = "Do You like feedbacktool?", Enabled = true
                };
                unitOfWork.Question.Add(newQuestion);
                var          accid = newAccount.Questions[0].Id;
                PuzzleAnswer newOpenPuzzleAnswer = new PuzzleAnswer()
                {
                    QuestionId = accid, Answer = "Yes"
                };
                unitOfWork.PuzzleAnswer.Add(newOpenPuzzleAnswer);
                unitOfWork.Complete();
                unitOfWork.Dispose();
            }
            //Assert
            using (var context = new TietoFeedbackToolContext(options))
            {
                var unitOfWork = new UnitOfWork(context);
                var account    = unitOfWork.Account.GetByString("Filippa");
                var answer     = account.Questions[0].PuzzleAnswers[0];
                Assert.Equal("Yes", answer.Answer);
                unitOfWork.Dispose();
            }
        }
Exemplo n.º 6
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (answer == null)
            {
                lblPleaseWait.Text = "This state is unsolvable!";
                counter            = 0;
                timerSolving.Stop();
            }

            if (counter < answer.Path.Count)
            {
                puzzle.CurrentState = answer.Path[counter++];
                SyncBoard();
            }
            else
            {
                lblPleaseWait.Text  = "Solved in " + answer.StepsCount + " steps";
                lblPleaseWait.Text += "\nWe tested " + answer.TestedStatesCount + " states";
                answer              = null;
                counter             = 0;
                timerSolving.Stop();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// A method to check whether the passed guessed word <paramref name="phrase"/> matches the puzzle or no
        /// </summary>
        /// <param name="phrase">passed guessed word</param>
        /// <returns>puzzle solved bool</returns>
        public bool IsPuzzleSolved(string phrase)
        {
            bool isSolved = (phrase.Trim().ToLower() == PuzzleAnswer.ToLower());

            return(isSolved);
        }