Пример #1
0
 public LexiconController(IWordRepository wordRepository, ISessionService sessionService, ILexiconService lexiconService, ILogger log)
 {
     this.wordRepository = wordRepository;
     this.sessionService = sessionService;
     this.lexiconService = lexiconService;
     this.log            = log;
 }
Пример #2
0
        public GameController(ILogger log, IBoardRepository boardRepository, IUserRepository userRepository,
                              ISessionService sessionService, IGameService gameService, IGameQueueService gameQueueService, ILexiconService lexiconService,
                              IHubContext <GameHub, IGameClient> gameHubContext)
        {
            this.log             = log;
            this.boardRepository = boardRepository;
            this.userRepository  = userRepository;

            this.sessionService   = sessionService;
            this.gameService      = gameService;
            this.gameQueueService = gameQueueService;
            this.lexiconService   = lexiconService;

            this.gameHubContext = gameHubContext;
        }
Пример #3
0
        public GameService(ILogger logger,
                           IGameCache gameCache,
                           IUserRepository userRepository, IGameRepository gameRepository, IBoardRepository boardRepository,
                           ILexiconService lexiconService, IStatService statService, IGameQueueService gameQueueService)
        {
            this.userRepository  = userRepository;
            this.gameRepository  = gameRepository;
            this.boardRepository = boardRepository;

            this.gameCache = gameCache;

            this.lexiconService   = lexiconService;
            this.statService      = statService;
            this.gameQueueService = gameQueueService;
            this.logger           = logger;
        }
Пример #4
0
 public WordListPresenter(IService <T> service)
 {
     SetupComplete = false;
     _svc          = service as ILexiconService <T>;
 }
Пример #5
0
 public LexiconEntryPresenter(TService service)
 {
     _service = service as ILexiconService <LexiconRaw>;
 }
Пример #6
0
 public LexiconController(ILexiconService lexiconService)
 {
     this._lexiconService = lexiconService;
 }
Пример #7
0
        public static async Task <IEnumerable <IPlayWord> > ExtractAllWords(this IGame game, ILexiconService lexiconService, IEnumerable <IPlayLetter> existingLetters, IEnumerable <IPlayLetter> playedLetters)
        {
            var allLetters = new List <IPlayLetter>();

            allLetters.AddRange(existingLetters);
            allLetters.AddRange(playedLetters);


            var horizontalWords = new List <IPlayWord>();
            var verticalWords   = new List <IPlayWord>();

            // Extract valid words
            foreach (var letter in playedLetters)
            {
                var word = game.Board.GetHorizontalWord(allLetters, letter);
                if (word.Letters.Count() > 1)
                {
                    // check if word was already added (or it will add the main word for every checked letter)
                    var hAlreadyExists = horizontalWords.SingleOrDefault(w =>
                                                                         w.GetStartY() == word.GetStartY() &&
                                                                         w.GetEndY() == word.GetEndY() &&
                                                                         w.GetStartX() == word.GetStartX() &&
                                                                         w.GetEndX() == word.GetEndX());
                    if (hAlreadyExists == null)
                    {
                        var wordString = word.GetString();
                        if (await lexiconService.ValidateWord(game.Language, wordString))
                        {
                            Console.WriteLine($"[{letter.Letter.Letter.Char}] - H word:{wordString}");
                            horizontalWords.Add(word);
                        }
                        else
                        {
                            Console.WriteLine($"[{letter.Letter.Letter.Char}] - H word Invalid:{wordString}");
                            return(null); // This word is invalid
                        }
                    }
                }
                else
                {
                    Console.WriteLine($"[{letter.Letter.Letter.Char}] - No valid H words");
                }


                word = game.Board.GetVerticalWord(allLetters, letter);
                if (word.Letters.Count() > 1)
                {
                    // check if word was already added (or it will add the main word for every checked letter)
                    var vAlreadyExists = verticalWords.SingleOrDefault(w =>
                                                                       w.GetStartY() == word.GetStartY() &&
                                                                       w.GetEndY() == word.GetEndY() &&
                                                                       w.GetStartX() == word.GetStartX() &&
                                                                       w.GetEndX() == word.GetEndX());

                    if (vAlreadyExists == null)
                    {
                        var wordString = word.GetString();
                        if (await lexiconService.ValidateWord(game.Language, wordString))
                        {
                            Console.WriteLine($"[{letter.Letter.Letter.Char}] - V word:{wordString}");
                            verticalWords.Add(word);
                        }
                        else
                        {
                            Console.WriteLine($"[{letter.Letter.Letter.Char}] - V word Invalid:{ wordString}");
                            return(null); // This word is invalid
                        }
                    }
                }
                else
                {
                    Console.WriteLine($"[{letter.Letter.Letter.Char}] - No valid V words");
                }

                if (horizontalWords.Count() == 0 && verticalWords.Count() == 0)
                {
                    return(null);    // letter not in any vertical or horizontal words. Invalid move
                }
            }

            return(horizontalWords.Concat(verticalWords));
        }
Пример #8
0
        public static async Task <MoveCheck> ValidateMove(this Game game, PlayLetter[] letters, ILexiconService lexiconService)
        {
            if (letters.Length < 1)
            {
                return new MoveCheck {
                           Result = "No letters."
                }
            }
            ;

            var existingLetters = game.PlayMoves.SelectMany(x => x.Letters);

            // Check if new letters are out of bounds or overlap existing letters
            string positionCheck = game.Board.CheckTilePositions(existingLetters, letters);

            if (positionCheck != "OK")
            {
                return new MoveCheck {
                           Result = positionCheck
                }
            }
            ;

            // Check word structure
            string structureCheck = game.Board.CheckWordStructure(existingLetters, letters);

            if (structureCheck != "OK")
            {
                return new MoveCheck {
                           Result = structureCheck
                }
            }
            ;

            // Check word position
            string wordPositionCheck = game.Board.CheckWordPosition(existingLetters, letters);

            if (wordPositionCheck != "OK")
            {
                return new MoveCheck {
                           Result = wordPositionCheck
                }
            }
            ;

            // Extract all possible words
            var words = await game.ExtractAllWords(lexiconService, existingLetters, letters);

            if (words == null || words.Count() < 1)
            {
                return(new MoveCheck {
                    Result = "Invalid words"
                });
            }

            var result = new MoveCheck
            {
                Result = "OK",
                Words  = words
            };

            return(result);
        }
Пример #9
0
 public void Setup()
 {
     lexiconService = new MockLexiconService();
 }