Exemplo n.º 1
0
        IList <PuzzleMatrix> TraceWord(char[] characters, PuzzleMatrix currentCell, IList <PuzzleMatrix> wholeMatrix, IList <PuzzleMatrix> solutionMatrix)
        {
            var character = characters.FirstOrDefault();
            var originalSolutionMatrix = new List <PuzzleMatrix>(solutionMatrix);
            var surroundings           = FindSurroundings(currentCell, wholeMatrix, originalSolutionMatrix);

            foreach (var surrounding in surroundings)
            {
                if (surrounding.Character == character)
                {
                    originalSolutionMatrix.Add(surrounding);

                    if (characters.Length > 1)
                    {
                        var newSolutionMatrix = TraceWord(characters.Skip(1).ToArray(), surrounding, wholeMatrix, originalSolutionMatrix);

                        if (newSolutionMatrix.Count == solutionMatrix.Count + characters.Length)
                        {
                            return(newSolutionMatrix);
                        }
                        else
                        {
                            originalSolutionMatrix.Remove(surrounding);
                        }
                    }
                    else
                    {
                        solutionMatrix.Add(surrounding);
                        break;
                    }
                }
            }

            return(solutionMatrix);
        }
Exemplo n.º 2
0
        public void True_With_Direct_Path_And_Enough_Buffer(int bufferSize)
        {
            var          chain   = new[] { 2, 10, 11 };
            PuzzleMatrix subject = new PuzzleMatrix(Board);

            subject.Check(chain, bufferSize, out var path).Should().BeTrue();
            path.Should().BeEquivalentTo(new[]
Exemplo n.º 3
0
        IList <PuzzleMatrix> FindSurroundings(PuzzleMatrix point, IList <PuzzleMatrix> wholeMatrix, IList <PuzzleMatrix> solutionMatrix)
        {
            IList <PuzzleMatrix> surroundings = new List <PuzzleMatrix>();

            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    if ((i != 0 || j != 0) && solutionMatrix.Count(s => s.Column == point.Column + i && s.Row == point.Row + j) == 0)
                    {
                        var surrounding = wholeMatrix.FirstOrDefault(m => m.Column == point.Column + i && m.Row == point.Row + j);

                        if (surrounding != null)
                        {
                            surroundings.Add(surrounding);
                        }
                    }
                }
            }

            return(surroundings);
        }