few more thingies, ready for prerelease

This commit is contained in:
Master Kwoth
2016-03-03 18:24:58 +01:00
parent 827b5bae0c
commit a6ebff0a17
31 changed files with 190 additions and 185 deletions

View File

@ -21,7 +21,7 @@ namespace NadekoBot.Classes.Trivia {
private CancellationTokenSource triviaCancelSource { get; set; }
public TriviaQuestion CurrentQuestion { get; private set; }
public List<TriviaQuestion> oldQuestions { get; } = new List<TriviaQuestion>();
public HashSet<TriviaQuestion> oldQuestions { get; } = new HashSet<TriviaQuestion>();
public ConcurrentDictionary<User, int> Users { get; } = new ConcurrentDictionary<User, int>();

View File

@ -7,7 +7,7 @@ using System.Text.RegularExpressions;
namespace NadekoBot.Classes.Trivia {
public class TriviaQuestion {
//represents the min size to judge levDistance with
public static List<Tuple<int, int>> strictness = new List<Tuple<int, int>>() {
private static readonly HashSet<Tuple<int, int>> strictness = new HashSet<Tuple<int, int>> {
new Tuple<int, int>(6, 0),
new Tuple<int, int>(7, 1),
new Tuple<int, int>(12, 2),

View File

@ -6,12 +6,11 @@ using System.Linq;
namespace NadekoBot.Classes.Trivia {
public class TriviaQuestionPool {
private static readonly TriviaQuestionPool _instance = new TriviaQuestionPool();
public static TriviaQuestionPool Instance => _instance;
public static TriviaQuestionPool Instance { get; } = new TriviaQuestionPool();
public List<TriviaQuestion> pool = new List<TriviaQuestion>();
public HashSet<TriviaQuestion> pool = new HashSet<TriviaQuestion>();
private Random _r { get; } = new Random();
private Random rng { get; } = new Random();
static TriviaQuestionPool() { }
@ -19,22 +18,21 @@ namespace NadekoBot.Classes.Trivia {
Reload();
}
public TriviaQuestion GetRandomQuestion(List<TriviaQuestion> exclude) {
public TriviaQuestion GetRandomQuestion(IEnumerable<TriviaQuestion> exclude) {
var list = pool.Except(exclude).ToList();
var rand = _r.Next(0, list.Count);
var rand = rng.Next(0, list.Count);
return list[rand];
}
internal void Reload() {
JArray arr = JArray.Parse(File.ReadAllText("data/questions.txt"));
var arr = JArray.Parse(File.ReadAllText("data/questions.txt"));
foreach (var item in arr) {
TriviaQuestion tq;
tq = new TriviaQuestion(item["Question"].ToString(), item["Answer"].ToString(), item["Category"]?.ToString());
var tq = new TriviaQuestion(item["Question"].ToString(), item["Answer"].ToString(), item["Category"]?.ToString());
pool.Add(tq);
}
var r = new Random();
pool = pool.OrderBy(x => r.Next()).ToList();
pool = new HashSet<TriviaQuestion>(pool.OrderBy(x => r.Next()));
}
}
}