Ejemplo n.º 1
0
        public void AdvanceCurrentNodesToChildNodes()
        {
            List <Node> nodes = new List <Node>();

            Node curretnNode1 = new Node()
            {
                Word = "test"
            };
            Node curretnNode2 = new Node()
            {
                Word = "cast"
            };

            Node childNode1 = new Node()
            {
                Word = "best"
            };
            Node childNode2 = new Node()
            {
                Word = "bats"
            };
            Node childNode3 = new Node()
            {
                Word = "ball"
            };
            Node childNode4 = new Node()
            {
                Word = "call"
            };

            curretnNode1.ChildNodes = new List <Node>()
            {
                childNode1, childNode2
            };
            curretnNode2.ChildNodes = new List <Node>()
            {
                childNode3, childNode4
            };

            nodes.Add(curretnNode1);
            nodes.Add(curretnNode2);

            _nodeProcessor.AdvanceCurrentNodes(nodes);

            Assert.IsTrue(nodes.Count == 4);
            Assert.AreEqual(nodes[0], childNode1);
            Assert.AreEqual(nodes[1], childNode2);
            Assert.AreEqual(nodes[2], childNode3);
            Assert.AreEqual(nodes[3], childNode4);
        }
Ejemplo n.º 2
0
        public void Process(AppProperties props)
        {
            props.WordList = _fileUtility.FileToList(props.FilePath);
            props.WordList.Remove(props.StartWord);

            _outputPath = props.ResultPath;

            _currentNodes = new List <Node>();
            _currentNodes.Add(new Node()
            {
                IsStartNode = true, Word = props.StartWord
            });

            _nodeProcessor.OnComplete += OnPuzzleCompleted;

            Stopwatch sw = new Stopwatch();

            sw.Start();
            int iterations = 0;

            while (!_goalReached)
            {
                iterations++;
                if (_currentNodes.Count == 0)
                {
                    Console.WriteLine("No route was found :(");
                    break;
                }

                _goalReached = _nodeProcessor.ProcessNodes(_currentNodes, props);

                if (!_goalReached)
                {
                    _nodeProcessor.AdvanceCurrentNodes(_currentNodes);
                }
                else
                {
                    break;
                }
            }

            sw.Stop();
            _timeTaken = sw.Elapsed;
            Console.WriteLine($"Puzzle complete in {_timeTaken.ToString(@"mm\:ss\:fff")}");
            Console.WriteLine("File out put to : " + props.ResultPath);
        }