Esempio n. 1
0
        public int Score(Guid playerId, Guid boardId, string word)
        {
            int points;

            word = word.ToLower();
            BoggleTracker tracker = FindTracker(playerId, boardId);

            if (tracker.WordPointDict.TryGetValue(word, out points))
            {
                return(0);
            }

            if (IsWordInDictionary(word))
            {
                if (tracker.Board.FindWord(word) != null)
                {
                    points = Rules.Score(word.Length);
                }
                else
                {
                    points = BoggleRules.IncorrectWordScore;
                }
            }
            else
            {
                points = BoggleRules.IncorrectWordScore;
            }

            tracker.Update(word, points);

            return(points);
        }
Esempio n. 2
0
        private BoggleTracker CreateTracker(IBogglePlayer player, BoggleBoard board)
        {
            BoggleTracker tracker = new BoggleTracker(player.Id, board);

            Trackers.Add(tracker);
            return(tracker);
        }
Esempio n. 3
0
        private BoggleResult CreateResult(BoggleTracker tracker)
        {
            BoggleResult result = new BoggleResult(tracker.Board, tracker.WordPointDict,
                                                   tracker.Points, tracker.Stopwatch.Elapsed);

            return(result);
        }
Esempio n. 4
0
        public BoggleResult Play(IBogglePlayer player, int randomSeed = 0, int boardSize = BoggleRules.BoardSizeDefault)
        {
            BoggleBoard   board   = Rules.GenerateBoard(randomSeed, boardSize);
            BoggleTracker tracker = CreateTracker(player, board);

            tracker.Start();

            try
            {
                player.Solve(board);
                tracker.Stop();
            }
            catch (Exception)
            {
                tracker.Stop();
                tracker.Update(string.Empty, BoggleRules.CatastrophicScore);
                throw;
            }

            BoggleResult result = CreateResult(tracker);

            DeleteTracker(player.Id, board.Id);
            return(result);
        }
Esempio n. 5
0
        public int TotalScore(Guid playerId, Guid boardId)
        {
            BoggleTracker tracker = FindTracker(playerId, boardId);

            return(tracker.Points);
        }
Esempio n. 6
0
        private void DeleteTracker(Guid playerId, Guid boardId)
        {
            BoggleTracker tracker = Trackers.FirstOrDefault(t => t.PlayerId == playerId && t.Board.Id == boardId);

            Trackers.Remove(tracker);
        }
Esempio n. 7
0
        private BoggleTracker FindTracker(Guid playerId, Guid boardId)
        {
            BoggleTracker tracker = Trackers.FirstOrDefault(t => t.PlayerId == playerId && t.Board.Id == boardId);

            return(tracker);
        }