More common refactorings like renaming variables, removing empty statements and unused variables, etc

This commit is contained in:
Kwoth
2022-01-09 16:46:08 +01:00
parent 2ce3262d59
commit f07a855912
75 changed files with 447 additions and 465 deletions

View File

@@ -6,10 +6,10 @@ namespace NadekoBot.Modules.Games.Common.Trivia;
public class TriviaQuestion
{
public const int maxStringLength = 22;
public const int MAX_STRING_LENGTH = 22;
//represents the min size to judge levDistance with
private static readonly HashSet<Tuple<int, int>> strictness = new()
private static readonly HashSet<Tuple<int, int>> _strictness = new()
{
new(9, 0), new(14, 1), new(19, 2), new(22, 3)
};
@@ -56,7 +56,7 @@ public class TriviaQuestion
private static bool JudgeGuess(int guessLength, int answerLength, int levDistance)
{
foreach (var level in strictness)
foreach (var level in _strictness)
if (guessLength <= level.Item1 || answerLength <= level.Item1)
{
if (levDistance <= level.Item2)
@@ -78,7 +78,7 @@ public class TriviaQuestion
str = Regex.Replace(str, "^\\s+", "");
str = Regex.Replace(str, "\\s+$", "");
//Trim the really long answers
str = str.Length <= maxStringLength ? str : str[..maxStringLength];
str = str.Length <= MAX_STRING_LENGTH ? str : str[..MAX_STRING_LENGTH];
return str;
}

View File

@@ -10,14 +10,14 @@ public class TriviaQuestionPool
=> _cache.LocalData.PokemonMap;
private readonly IDataCache _cache;
private readonly int maxPokemonId;
private readonly int _maxPokemonId;
private readonly NadekoRandom _rng = new();
public TriviaQuestionPool(IDataCache cache)
{
_cache = cache;
maxPokemonId = 721; //xd
_maxPokemonId = 721; //xd
}
public TriviaQuestion GetRandomQuestion(HashSet<TriviaQuestion> exclude, bool isPokemon)
@@ -27,7 +27,7 @@ public class TriviaQuestionPool
if (isPokemon)
{
var num = _rng.Next(1, maxPokemonId + 1);
var num = _rng.Next(1, _maxPokemonId + 1);
return new("Who's That Pokémon?",
Map[num].ToTitleCase(),
"Pokemon",
@@ -36,7 +36,15 @@ public class TriviaQuestionPool
}
TriviaQuestion randomQuestion;
while (exclude.Contains(randomQuestion = Pool[_rng.Next(0, Pool.Length)])) ;
while (exclude.Contains(randomQuestion = Pool[_rng.Next(0, Pool.Length)]))
{
// if too many questions are excluded, clear the exclusion list and start over
if (exclude.Count > Pool.Length / 10 * 9)
{
exclude.Clear();
break;
}
}
return randomQuestion;
}