using System; using System.Collections.Generic; using System.Linq; namespace Olympus { [Serializable] public class Question { public string id, realm, answer, image; public int difficulty; public string Normalized => Rules.Normalize(answer); } [Serializable] public class Realm { public string id, name, subtitle; public int fee; } [Serializable] public class RivalConfig { public string name; public double skill; public int avatar; } [Serializable] public class GameConfig { public Question[] questions; public Realm[] realms; public RivalConfig[] rivals; public int[] itemPrices = {400, 500, 300, 600}; public int[] prizes = {1000, 500, 200}; public int[] checkinCoins = {200, 0, 300, 0, 400, 500, 600}; public int[] checkinItems = {-1, 0, -1, 1, -1, -1, -1}; public void Validate() { if (realms == null || realms.Length != 4 || questions == null || questions.Length != 40 || rivals == null || rivals.Length != 5) throw new InvalidOperationException("Expected four realms, 40 questions and five rivals."); if (questions.Select(q => q.id).Distinct().Count() != questions.Length) throw new InvalidOperationException("Duplicate question ID."); foreach (var realm in realms) if (questions.Count(q => q.realm == realm.id) != 10) throw new InvalidOperationException("Each realm needs ten questions."); foreach (var q in questions) if (q.Normalized.Length < 1 || q.Normalized.Length > 16 || string.IsNullOrEmpty(q.image)) throw new InvalidOperationException("Invalid question " + q.id); } } public enum Item { Hint, Time, Reveal, Skip } public static class Rules { public static readonly string[] ItemNames = {"Free Hint", "+5 Seconds", "Reveal +15%", "Skip Shield"}; public static string Normalize(string value) => new string((value ?? "").ToUpperInvariant().Where(c => c >= 'A' && c <= 'Z').ToArray()); public static double Duration(string answer) => Math.Min(46, 24 + Math.Max(0, Normalize(answer).Length - 5) * 3); public static int Round10(double value) => (int)(Math.Floor(value / 10 + .5) * 10); public static int Score(double left, double total, int rank) => Round10(420 + 580 * Math.Max(0, Math.Min(1, left / total))) + (rank == 1 ? 200 : rank == 2 ? 120 : rank == 3 ? 60 : 0); public static int Rank(int score, IEnumerable scores) => 1 + scores.Count(s => s > score); public static void Shuffle(IList values, Random random) { for (int i = values.Count - 1; i > 0; i--) { int j = random.Next(i + 1); var v = values[i]; values[i] = values[j]; values[j] = v; } } public static char[] Pool(string answer, Random random) { var list = Normalize(answer).ToList(); int size = Math.Min(26, Math.Max(12, list.Count * 2 + 2)); list.Add("AEIOU"[random.Next(5)]); while (list.Count < size) list.Add((char)('A' + random.Next(26))); Shuffle(list, random); return list.ToArray(); } // Exact occurrence mapping: typing and tapping use the same multiset. public static int[] UsedTiles(string input, char[] pool) { var used = new List(); foreach (char c in Normalize(input)) { for (int i = 0; i < pool.Length; i++) if (pool[i] == c && !used.Contains(i)) { used.Add(i); break; } } return used.ToArray(); } } }