Ejemplo n.º 1
0
        public void ConstraintsConstructorTest()
        {
            string tiles = string.Empty; // TODO: Initialize to an appropriate value
            string template = string.Empty; // TODO: Initialize to an appropriate value
            Constraints target = new Constraints(tiles, template);

            Assert.AreEqual(tiles, target.Tiles);
            Assert.AreEqual(template, target.Template);
        }
Ejemplo n.º 2
0
        public void TryCandidateWordTest()
        {
            var constraints = new Constraints("dog", "o");

            Word w;
            var match = constraints.TryCandidateWord("DOG", out w);
            Assert.IsFalse(match);
            Assert.IsNull(w);
        }
Ejemplo n.º 3
0
        public IEnumerable<Word> GetWords(Constraints constraints)
        {
            if (constraints == null)
                yield break;

            if (!m_isLoaded)
            {
                LoadDictionary();
            }

            if (m_words == null)
                yield break;

            foreach (var candidate in m_words)
            {
                Word solvedWord;
                if (constraints.TryCandidateWord(candidate, out solvedWord))
                    yield return solvedWord;
            }
        }
Ejemplo n.º 4
0
        public void Solve()
        {
            int myQueryId;

            // lock both setting the id and clearing the results to prevent
            // race condition where we add an item to the results just as we are
            // about to solve again
            lock (_querySync)
            {
                myQueryId = ++_queryId;
                Solutions.Clear();
            }
            var cs = new Constraints(ActiveConstraints.Tiles, ActiveConstraints.GetAdjustedTemplate());
            var dispatcher = Deployment.Current.Dispatcher;
            dispatcher.BeginInvoke(OnSearchBeginning);
            BackgroundWorker worker = new BackgroundWorker();
            worker.WorkerReportsProgress = false;
            worker.DoWork += new DoWorkEventHandler((obj, eargs) =>
            {
                Stopwatch sw = Stopwatch.StartNew();
                var words = SolverService.GetWords(
                    cs).OrderByDescending(w=>w.Score).Take(100);
                Debug.WriteLine("Selection took {0} ms", sw.ElapsedMilliseconds);
                int skip = (words.Count() > 3 && _isTrial ) ? 1 : 0;
                words = words.Skip(skip);
                sw.Stop();
                dispatcher.BeginInvoke(() =>
                {
                    foreach (var w in words)
                    {
                        lock (_querySync)
                        {
                            if (myQueryId != _queryId)
                                break;
                            Solutions.Add(w);
                        }
                    }
                });
            }
            );
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
            worker.RunWorkerAsync();
        }