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; } } } } }
private void MakeGuesses() { short ordinal = 0; for (byte y = 0; y < LastY; y++) { for (byte x = 0; x < LastX; x++) { for (Dir dir = Dir.First; dir < Dir.Last; dir++) { List<byte> charIndexes = new List<byte>(); short nextX = x; short nextY = y; byte len; for (len = 1; len <= 5; len++) { charIndexes.Add((byte)(nextX + nextY * LastY)); nextX += DirOffset[(int)dir - 1, 0]; nextY += DirOffset[(int)dir - 1, 1]; if (!IsInRange(nextX, nextY)) break; } if (len >= MinWordLength) { _guesses[ordinal] = new Guess(x, y, (byte)dir, charIndexes.ToArray(), ordinal); ordinal++; } } } } }