Exemplo n.º 1
0
        public bool WordExists(string word)
        {
            if (!_englishDictionaryService.IsValidWord(word))
            {
                return(false);
            }

            var candidates = GetWordCandidates();
            var comparer   = new StringComparerCaseInsensitive();

            return(candidates.Contains(word, comparer));
        }
Exemplo n.º 2
0
        public ObjectResult GetValidWords2(string boardDefinition)
        {
            var board = new Board2(boardDefinition, _englishDictionaryService);

            if (!board.Validate(out string validationMessage))
            {
                return(StatusCode(StatusCodes.Status400BadRequest, new ErrorResponse {
                    Message = validationMessage
                }));
            }

            var endTime = DateTime.Now.AddSeconds(allottedNumberOfSeconds);

            var validWords = new List <string>();

            using (board.GetWordCandidates().ToObservable()
                   .TakeUntil(endTime)
                   .Subscribe(s =>
            {
                if (_englishDictionaryService.IsValidWord(s))
                {
                    validWords.Add(s);
                }
            }))
            {
                Debug.WriteLine($">>> Found {validWords.Count} valid words on the board in the allotted time ({allottedNumberOfSeconds} seconds).");
            }

            var boardDisplay = boardDefinition.Split(new char[] { ',' }).ToList();

            return(StatusCode(StatusCodes.Status200OK, new ValidWordsResponse
            {
                Board = boardDisplay,
                Words = validWords.Distinct().OrderBy(w => w).ToList()
            }));
        }
Exemplo n.º 3
0
        public bool WordExists(string word)
        {
            if (!_englishDictionaryService.IsValidWord(word))
            {
                return(false);
            }

            var answer = false;

            foreach (var tile in _tiles)
            {
                answer = answer || tile.CanBeRead(word);
                if (answer)
                {
                    break;
                }
            }
            return(answer);
        }