public void Score(Guess[] guesses, WordList validList)
        {
            TotalScore = 0;
            StringBuilder builder = new StringBuilder();

            foreach (Guess guess in guesses)
            {
                bool afterQ = false;
                builder.Clear();
                int current = 0;
                short lineNum = 0;
                bool addUToScore = false;

                for (byte charIndex = 0; charIndex < guess.CharIndexes.Length; charIndex++)
                {
                    char ch = Letter[guess.CharIndexes[charIndex]];

                    if (ch == 'U' && afterQ)
                    {
                        builder.Append(ch);
                        addUToScore = false;
                        continue;
                    }
                    afterQ = false;
                    if (builder.Length == 5 ||
                        (addUToScore && builder.Length == 4))
                        break;
                    else
                    {
                        builder.Append(ch);
                        bool hasScore = validList.Contains(ch, current, out lineNum, out current);
                        if (ch == 'Q' && !addUToScore && builder.Length < 5)
                        {
                            hasScore = validList.Contains('U', current, out lineNum, out current);
                            afterQ = true;
                            addUToScore = true;
                        }
                        if (hasScore)
                        {
                            string validWord = builder.ToString();
                            byte score = (byte)(addUToScore ? validWord.Length + 1 : validWord.Length);
                            output.AppendLine(String.Join(" ", validWord,
                                lineNum, score, guess.X, guess.Y, guess.Dir));
                            TotalScore += score;
                        }
                    }
                }
            }
        }
        public Solver(string[] lines, WordList wordList)
        {
            int gameNum = 1;

            _gridList = new List<Grid>();
            foreach (string game in lines)
            {
                if (game.Length < 25)
                    continue;

                _gridList.Add(new Grid(game, gameNum));
                gameNum++;
            }
            _wordList = wordList;
            MakeGuesses();
        }
        static void Main(string[] args)
        {
            string[] gameLines = File.ReadAllLines("games.txt");
            string[] words = File.ReadAllLines("words5.txt");

            Stopwatch stopwatch = new Stopwatch();
            const int TIMING_REPETITIONS = 800;
            double averageTime = 0.0;
            StringBuilder output = new StringBuilder();

            for (int i = 0; i < TIMING_REPETITIONS; ++i)
            {
                stopwatch.Reset();
                stopwatch.Start();

                output.Clear();
                WordList wordList = new WordList(words);
                Solver games = new Solver(gameLines, wordList);
                games.ScoreGames(output);

                stopwatch.Stop();

                averageTime += stopwatch.Elapsed.TotalSeconds;
                GC.Collect();
            }
            averageTime /= (double)TIMING_REPETITIONS;
            output.AppendLine(string.Format("Total Average Time = {0:0.000000} sec", averageTime));
            File.WriteAllText("results.txt", output.ToString());
        }