Ejemplo n.º 1
0
        private void FindWords(CharCoordinate currentCoordinate, TraversalStack stack = null)
        {
            stack = stack ?? new TraversalStack();

            if (stack.Path.Contains(currentCoordinate))
            {
                return;
            }

            if (!_dfa.StateChange(Matrix.GetCharAt(currentCoordinate)))
            {
                return;
            }

            stack.StepTo(currentCoordinate);

            if (_dfa.IsFinal)
            {
                var currentPath = new CharCoordinate[stack.Path.Count];
                stack.Path.CopyTo(currentPath);
                MatrixWords.Add(new MatrixWord(_dfa.State, currentPath));
            }

            foreach (var coordinate in currentCoordinate.FindSiblings(Matrix.Size).Where(x => !stack.Path.Contains(x)))
            {
                FindWords(coordinate, stack);
            }


            _dfa.Back();
            stack.StepBack();
        }
 public bool IsSiblingOf(CharCoordinate other)
 {//boolean: true / false
     return(Math.Abs(Row - other.Row) <= 1 && Math.Abs(Column - other.Column) <= 1 && !this.Equals(other));
 }
 public void StepTo(CharCoordinate nextCoordinate)
 {
     Path.Add(nextCoordinate);
 }