public void PuzzleSolver_calls_FindWord_as_many_times_as_there_are_words(string wordsString)
        {
            List <string>       wordStringList = wordsString.Split((",")).ToList();
            List <List <char> > gridArrayList  = GetGridList();

            _puzzleSolver.SolvePuzzle(wordStringList, gridArrayList);

            _wordSearchMock.Verify(x => x.FindWordCoordinates(It.IsAny <string>(), It.IsAny <List <List <char> > >()), Times.Exactly(wordStringList.Count));
        }
Example #2
0
        static void Main(string[] args)
        {
            bool debug = true;

            // Come up with a puzzle to solve
            Puzzle puzzle = PuzzleBuilder.FromString(PuzzleStrings.Cherries);

            // Draw once
            Renderer.Draw(puzzle);
            Console.WriteLine("Press any key to start the solve...");
            Console.ReadLine();

            // Solve as much as we can
            PuzzleSolver solver = new PuzzleSolver();

            solver.SegmentSolvers = new List <SegmentSolver>()
            {
                // Start simple with known entire chunks:
                new SegmentEntirelyFilled(),            // The segment is all true or all false
                new SequenceAddsToSegmentLength(),      // When the sequences already adds up to the total size

                // Easy pickings
                new BookendOnesInOneOnlySequence(),     // When the sequence contains only 1s, bookend all 1s with False

                // Perform solves in single number chunks
                new SingleSequenceOverlapSolver(),      // Single sequence overlap
                new SingleSequenceConnectEnds(),        // Single sequence connection
                new SingleSequenceExcludeOOB(),         // Single sequence exclude bounds

                // Finish off
                new SegmentCompleteMarkBlanksFalse(),   // Mark blank cells in a "complete" segment as false
                new SequenceTerminatesOnASide(),        // Terminate the other side of a full sequence touching an edge
                new OnlyFinalPiecesRemain(),            // When the number of blanks remaining match the number of trues remaining, fill them all in
                new ImpossibleStartOrEnd(),             // When the first or last number in a sequence can't fit in the first or last holes, fill the holes
                new ExtendStartAndEnd(),                // When a first or last segment cell is True, extend it outward the number of known cells in that segment
            };

            // Start a stopwatch
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            // Solve the puzzle
            solver.SolvePuzzle(puzzle, debug);

            // Stop the stopwatch
            stopWatch.Stop();

            // Draw again
            Renderer.Draw(puzzle);

            // Print out the solving stats
            Console.WriteLine("Solve completed in " + stopWatch.Elapsed.TotalMilliseconds + "ms");
            Console.WriteLine("Unknown cells left: " + puzzle.UnknownCount);
            Console.WriteLine("Segment passes: " + SolverStats.Instance.SegmentPasses);
            Console.ReadLine();
        }
Example #3
0
    ///<summary>
    ///Solves the currently selected puzzle if it is not null and updates the resolved cells in the ui manager.
    ///</summary>
    internal void SolvePuzzle()
    {
        if (currentPuzzle != null)
        {
            int[,] solvedPuzzle = solver.SolvePuzzle(currentPuzzle);

            for (int i = 0; i < PuzzleUtils.Constants.GRID_SIZE; i++)
            {
                for (int j = 0; j < PuzzleUtils.Constants.GRID_SIZE; j++)
                {
                    if (currentPuzzle[i, j] == 0)
                    {
                        puzzleUi.UpdateCell(i, j, solvedPuzzle[i, j]);
                    }
                }
            }
        }
    }
Example #4
0
        static void SolvePuzzle()
        {
            var rules  = MarkovDecoder.ReadRules();
            var values = MarkovDecoder.ReadValues();

            Console.WriteLine("***********************Decoding Characters using Markov Algorithm***************");
            char[,] array = MarkovDecoder.Decypher(rules, values);
            Console.WriteLine("***********************Generating Puzzle****************************************");
            string[] wordsToCheck = MarkovDecoder.ReadWords().ToArray();

            Console.WriteLine("***********************List of possible Words: *********************************");
            foreach (var word in wordsToCheck)
            {
                Console.Write(word + " - ");
            }
            Console.WriteLine();

            List <PuzzleResponse> puzzleResponseList = new List <PuzzleResponse>();
            List <Coordinate>     coordinatesToPaint = new List <Coordinate>();
            StringBuilder         sBuilderFoundWords = new StringBuilder();

            foreach (var word in wordsToCheck)
            {
                var            coordinatesPerWord = Puzzle.CheckAdjacentsC(word, 0, 0, array);
                PuzzleResponse puzzleResponseTemp = new PuzzleResponse();
                puzzleResponseTemp.Breakdown = new List <Breakdown>();
                //We need to check whether or not the query returned values.
                if (coordinatesPerWord.Count > 0)
                {
                    puzzleResponseTemp.Word = word;

                    coordinatesToPaint.AddRange(coordinatesPerWord);
                    foreach (var coord in coordinatesPerWord)
                    {
                        Breakdown brkDown = new Breakdown()
                        {
                            Character = array[coord.X, coord.Y],
                            Row       = coord.X,
                            Column    = coord.Y
                        };
                        puzzleResponseTemp.Breakdown.Add(brkDown);
                    }
                    sBuilderFoundWords.Append(word + "-");
                }
                puzzleResponseList.Add(puzzleResponseTemp);
            }
            foreach (var word in wordsToCheck)
            {
                var solution = PuzzleSolver.SolvePuzzle(array, word);
                if (solution.Word != null)
                {
                    puzzleResponseList.Add(solution);
                }
            }

            foreach (var puzzleSolution in puzzleResponseList)
            {
                foreach (var item in puzzleSolution.Breakdown)
                {
                    Coordinate c = new Coordinate()
                    {
                        X = item.Row,
                        Y = item.Column
                    };
                    coordinatesToPaint.Add(c);
                }
                if (!String.IsNullOrWhiteSpace(puzzleSolution.Word))
                {
                    if (!sBuilderFoundWords.ToString().Contains(puzzleSolution.Word))
                    {
                        sBuilderFoundWords.Append(puzzleSolution.Word + "-");
                    }
                }
            }

            var output = JsonConvert.SerializeObject(puzzleResponseList.Where(p => p.Word != null), Formatting.Indented);

            Console.WriteLine("JSON Output Generated: ");
            Console.WriteLine(output);

            Console.WriteLine(string.Format("WORDS FOUND IN PUZZLE: {0} ", sBuilderFoundWords.ToString()));
            Console.WriteLine();
            MarkovDecoder.PrintSolvedGrid(array, coordinatesToPaint);
            Console.WriteLine();
        }