private static Rule[][] GenerateRules(MonoRandom rnd, ref FACScript FAC) { FAC.Audio.PlaySoundAtTransform("start", FAC.Module.transform); if (rnd.Seed == 1) { return(new Rule[0][]); } var rules = new Rule[2][] { new Rule[24], new Rule[8] }; int[] ranges = { 10, 30 }; for (int i = 0; i < rules.Length; i++) { for (int j = 0; j < rules[i].Length; j++) { rules[i][j] = new Rule { Number = rnd.Next(ranges[i]) }; } } return(rules); }
private void GenerateRules() { MonoRandom rnd = RuleSeedable.GetRNG(); Debug.LogFormat(@"[VaricoloredSquares #{0}] Rule Generator: generating rules according to rule seed {1}", _moduleId, rnd.Seed); // Add more random spread for (int i = 0; i < 13; i++) { rnd.Next(); } // Generate color pentagons _table = new SquareColor[5][]; for (int i = 0; i < 5; i++) { _colorCandidates.Shuffle(rnd); _table[i] = _colorCandidates.ToArray(); Debug.LogFormat(@"[VaricoloredSquares #{0}] Rule Generator: {1} pentagon is: {2}", _moduleId, (SquareColor)i, string.Join("-", _table[i].Select(c => "RBGYM"[(int)c].ToString()).ToArray())); } // Random spread rnd.Next(); rnd.Next(); rnd.Next(); // Generate directions _ruleOneDirection = (rnd.Next(2) * 2) - 1; _backupDirection = (rnd.Next(2) * 2) - 1; Debug.LogFormat(@"[VaricoloredSquares #{0}] Rule Generator: rule one direction is: {1}", _moduleId, _ruleOneDirection == -1 ? "counter-clockwise" : "clockwise"); Debug.LogFormat(@"[VaricoloredSquares #{0}] Rule Generator: backup rule direction is: {1}", _moduleId, _backupDirection == -1 ? "counter-clockwise" : "clockwise"); }
public static Instruction[,] GetRules(int ruleSeed) { var random = new MonoRandom(ruleSeed); var weights = new WeightMap <Instruction, string>(i => i.Key); var rules = new Instruction[NumStages, 4]; for (int i = 0; i < NumStages; ++i) { for (int j = 0; j < 4; ++j) { var digit = random.Next(1, 5); var stage = random.Next(1, i + 1); var instructions = new List <Instruction>() { Instruction.Position1, Instruction.Position2, Instruction.Position3, Instruction.Position4, Instruction.PressDigit(digit) }; if (i > 0) { var instruction = i % 2 == 0 ? Instruction.PressLabelFromStage(stage) : Instruction.PressPositionFromStage(stage); if (i > 2) { weights.SetWeight(instruction, 1); } instructions.Add(instruction); } var instruction2 = weights.Roll(instructions, random); rules[i, j] = instruction2; } } return(rules); }
HashSet <int> VisitConfigurations(int startConfiguration, MonoRandom rnd) { var visitedConfigurations = new HashSet <int>(); var visitStack = new Stack <int>(); visitStack.Push(startConfiguration); while (true) { if (visitedConfigurations.Count >= (1 << _numSwitches) - _numForbiddenConfigurations) { return(visitedConfigurations); } int configToVisit = visitStack.Pop(); if (!visitedConfigurations.Add(configToVisit)) { continue; } var adjacentConfigurations = GetAdjacentConfigurations(configToVisit).ToList(); while (adjacentConfigurations.Count > 0) { var ix = rnd.Next(0, adjacentConfigurations.Count); visitStack.Push(adjacentConfigurations[ix]); adjacentConfigurations.RemoveAt(ix); } } }
public static void Rules(Rule Rules) { //This shouldn't be reached? I saw it in Morse-A-Maze's code if (_rng != null && _rng.Seed == Rules.rng.Seed) { return; } _rng = Rules.rng; if (_rng.Seed != 1) { _rng.ShuffleFisherYates(coordX); _rng.ShuffleFisherYates(coordY); _rng.ShuffleFisherYates(ManualTable); } AddToOptions(Rules); //ManualTable is a double array, which ShuffleFisherYates does not work on //As such, the ManualTable must be recreated using for statements Rule.ManualTable = new int[6, 6]; for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { Rule.ManualTable[i, j] = ManualTable[6 * i + j]; } } }
void Start() { rnd = RuleSeed.GetRNG(); var ixs = Enumerable.Range(0, allConditions.Count).ToList(); rnd.ShuffleFisherYates(ixs); for (int i = 0; i < 4; i++) { leftSwitch.Add(new Switch { Explanation = allConditions[ixs.First()].Explanation, Cond = allConditions[ixs.First()].Cond, SwitchValue = rnd.Next(1, 5) }); ixs.RemoveAt(0); rightSwitch.Add(new Switch { Explanation = allConditions[ixs.First()].Explanation, Cond = allConditions[ixs.First()].Cond, SwitchValue = rnd.Next(1, 5) }); ixs.RemoveAt(0); } leftSwitch.Add(new Switch { Explanation = "Otherwise", Cond = button => true, SwitchValue = rnd.Next(1, 5) }); rightSwitch.Add(new Switch { Explanation = "Otherwise", Cond = button => true, SwitchValue = rnd.Next(1, 5) }); MixButtons(); StartCoroutine(Game()); }
void Start() { startingTime = BombInfo.GetTime(); startingModuleCount = BombInfo.GetSolvableModuleNames().Count; MonoRandom ruleSeedRnd = RuleSeedModifier.GetRNG(); FizzBuzzRuleGenerator generator = new FizzBuzzRuleGenerator(ruleSeedRnd, this); table = generator.GenerateOffsetTable(); ruleSet = generator.GenerateRuleSet(); divisibilityRules = generator.GenerateDivisibilityRules(); moduleId = moduleIdCounter++; GetComponent <KMBombModule>().OnActivate += OnActivate; for (int i = 0; i < 3; i++) { var j = i; SelectionButtons[i].OnInteract += delegate { HandlePress(j); return(false); }; Nums[i] = GenNum(); Labels[i].text = ""; int color = Random.Range(0, 5); Colors[i] = color; Labels[i].color = ColorMats[color]; } SubmitButton.OnInteract += delegate { Submit(); return(false); }; }
public void Start() { bombInfo = GetComponent <KMBombInfo>(); needyModule = GetComponent <KMNeedyModule>(); bombAudio = GetComponent <KMAudio>(); data = GetComponent <TechSupportData>(); interruptableModules = new List <InterruptableModule>(); options = new List <Tuple <string, int> >(); allErrors = new List <ErrorData>(); needyModule.OnActivate += OnActivate; needyModule.OnNeedyActivation += Interrupt; needyModule.OnTimerExpired += OnTimerExpired; screenOverlay.Toggle(false); // TODO: do something with KMSeedable here. monoRandom = new MonoRandom(0); data.Generate(monoRandom, 16, 12, 9, 9, 9); // Adds methods to buttons. okButton.AddListener(OnOKClicked); upButton.AddListener(OnUpClicked); downButton.AddListener(OnDownClicked); StartCoroutine(DelayedStart()); }
private void Init() { key = Random.Range(2, 10000); keyText.text = key.ToString(); rnd = new MonoRandom(key); Debug.LogFormat("[Bureaucratic Maze #{0}] The module key is {1}.", _moduleId, key.ToString()); StartOfMaze = new Department(5, "Start"); HumanResources = new Department(0, "HR"); InformationManagement = new Department(1, "IM"); Marketing = new Department(2, "M"); CorporateCompliance = new Department(3, "CC"); EmployeeBenefits = new Department(4, "EB"); departments = new Department[] { HumanResources, InformationManagement, Marketing, CorporateCompliance, EmployeeBenefits, StartOfMaze }; setupKey(); currentDepartment = 5; previousDepartment = 5; Department.setPossibleMoves(new List <Department> { HumanResources }); UpdateDisplay(); }
private static int[] GenerateTableOfNumbers(MonoRandom rnd) { // Generate the 12×12 grid of numbers 1–5 (still part of rule seed) var _table = new int[144]; var nmbrs = new List <int>(); for (var i = 0; i < 144; i++) { nmbrs.Clear(); var x = i % 12; var y = (i / 12) | 0; for (var j = 0; j < 5; j++) { if ((x == 0 || j != _table[i - 1]) && (y == 0 || j != _table[i - 12]) && (x == 0 || y == 0 || j != _table[i - 13])) { nmbrs.Add(j); } } var n = nmbrs[rnd.Next(0, nmbrs.Count)]; _table[i] = n; } return(_table); }
public static Glyph[][] GetColumns(int ruleSeed) { var random = new MonoRandom(ruleSeed); var unusedGlyphs = new List <Glyph>() { Copyright, FilledStar, HollowStar, SmileyFace, DoubleK, Omega, SquidKnife, Pumpkin, HookN, Teepee, Six, SquigglyN, AT, Ae, MeltedThree, Euro, Circle, NWithHat, Dragon, QuestionMark, Paragraph, RightC, LeftC, Pitchfork, Tripod, Cursive, Tracks, Balloon, WeirdNose, UpsideDownY, BT }; var columns = new Glyph[6][]; var singleGlyphs = new List <Glyph>(); for (var i = 0; i < 6; i++) { var column = new Glyph[7]; columns[i] = column; var j = 0; // Repeat up to 3 glyphs from previous columns. // (No glyph will appear in more than two columns.) if (i > 0) { while (j < 3) { if (singleGlyphs.Count == 0) { break; } var glyph = Utils.RemoveRandom(singleGlyphs, random); column[j] = glyph; j++; } } // Add unused glyphs. (These may be repeated later.) while (j < 7) { var glyph = Utils.RemoveRandom(unusedGlyphs, random); column[j] = glyph; singleGlyphs.Add(glyph); j++; } // Shuffle the column. for (j = 0; j < column.Length; j++) { var hold = column[j]; var index = random.Next(column.Length); column[j] = column[index]; column[index] = hold; } } return(columns); }
public void PopulateMaze(MonoRandom rng) { var cellStack = new Stack <MazeCell>(); var x = rng.Next(0, Size); var y = rng.Next(0, Size); var cell = GetCell(x, y); VisitCell(cell, cellStack, rng); }
bool[] FindGrid(bool[] grid, int ix, List <bool[]> gridsAlready, MonoRandom rnd) { if (ix % 5 == 0) { for (var prevRow = 0; prevRow * 5 < ix - 5; prevRow++) { if (Enumerable.Range(0, 5).All(x => grid[prevRow * 5 + x] == grid[ix - 5 + x])) { return(null); } } } if (ix == 25) { for (var col = 0; col < 5; col++) { for (var col2 = 0; col2 < col; col2++) { if (Enumerable.Range(0, 5).All(y => grid[y * 5 + col] == grid[y * 5 + col2])) { return(null); } } } if (gridsAlready.All(gr => { for (var j = 0; j < 25; j++) { if (gr[j] != grid[j]) { return(true); } } return(false); })) { return(grid); } return(null); } var pixel = rnd.Next(0, 2) != 0; grid[ix] = pixel; var success = FindGrid(grid, ix + 1, gridsAlready, rnd); if (success != null) { return(success); } grid[ix] = !pixel; return(FindGrid(grid, ix + 1, gridsAlready, rnd)); }
IEnumerable <int> GetForbiddenConfigurations(MonoRandom rnd) { var startPoint = rnd.Next(0, 1 << _numSwitches); var visitedConfigurations = VisitConfigurations(startPoint, rnd); for (var i = 0; i < (1 << _numSwitches); i++) { if (!visitedConfigurations.Contains(i)) { yield return(i); } } }
public static void Shuffle <T>(this IList <T> list, MonoRandom random) { int n = list.Count; while (n > 1) { n--; int k = random.Next(0, n + 1); T value = list[k]; list[k] = list[n]; list[n] = value; } }
// Fisher-Yates Shuffle public static IList <T> Shuffle <T>(this IList <T> list, MonoRandom rnd) { int i = list.Count; while (i > 1) { int index = rnd.Next(i); i--; T value = list[index]; list[index] = list[i]; list[i] = value; } return(list); }
public void Generate(MonoRandom monoRandom, int s, int e, int pf, int v, int pa) { this.monoRandom = monoRandom; extentionText = extentions.text; modulePrefixText = modulePrefixes.text; moduleSuffixtext = moduleSuffixes.text; GenerateSourceFileNames(s, 4, 8); GenerateErrorCodes(e, 6); GeneratePatchFiles(pf, 4, 8); GenerateVersions(v); GenerateParameters(pa, 1, 4); GenerateCrossTable(v); }
public static void GenerateRules(MonoRandom rng) { if (_rng != null && _rng.Seed == rng.Seed) { return; } _rng = rng; Mazes.Clear(); for (int i = 0; i < 10; i++) { var maze = new Maze(); Mazes.Add(maze); maze.BuildMaze(rng); } }
public static Instruction[] GetRules(int seed) { var array = new Instruction[16]; var weights = new Dictionary <Instruction, double>(); var random = new MonoRandom(seed); for (int i = 1; i < 16; ++i) { array[i] = GetInstruction(weights, random); } if (seed != 1 && array.Count(i => i == Instruction.Cut) >= 2) { array[0] = GetInstruction(weights, random); } return(array); }
public static void GenerateRules(MonoRandom rng) { if (_rng != null && _rng.Seed == rng.Seed) { return; } _rng = rng; Mazes.Clear(); for (var i = 0; i < 18; i++) { var maze = new Maze(); Mazes.Add(maze); maze.BuildMaze(rng); } var words = new List <string>(PossibleWords); words.AddRange(ExtendedWords); // Choose 8 base words var numBaseWords = 18; var chosenWords = words.OrderBy(x => rng.NextDouble()).Take(numBaseWords).ToList(); Debug.LogFormat("[Morse Code Rule Seed Generator] + Base words: {0}", string.Join(", ", chosenWords.ToArray())); // Find other words that are similar to these (low cycling Levenshtein distance) for (var i = 0; i < numBaseWords && chosenWords.Count < 36; i++) { var prefix = chosenWords[i].Substring(1); var toAdd = words .Where(w => !chosenWords.Contains(w) && !w.EndsWith(prefix)) .Select(w => (new { word = w, pref = rng.NextDouble(), dist = Similarity(w, chosenWords[i]) })) .ToList(); toAdd.Sort((a, b) => { var r = a.dist - b.dist; return(r == 0 ? Math.Sign(a.pref - b.pref) : r); }); var howmany = Math.Min(Math.Min(rng.Next(1, 4), 36 - chosenWords.Count), toAdd.Count); Debug.LogFormat(@"[Password rule seed] From {0}, adding words: {1}", chosenWords[i], string.Join(", ", toAdd.Take(howmany).Select(w => string.Format("{0}/{1}/{2}", w.word, w.dist, w.pref)).ToArray())); chosenWords.AddRange(toAdd.Take(howmany).Select(inf => inf.word)); } Words.Clear(); Words.AddRange(chosenWords.Take(36).OrderBy(x => rng.NextDouble())); }
public void VisitCell(MazeCell cell, Stack <MazeCell> cellStack, MonoRandom rng) { while (cell != null) { cell.Visited = true; var mazeCell = GetNextNeigbour(cell, rng); if (mazeCell != null) { MazeCell.RemoveWalls(cell, mazeCell); cellStack.Push(cell); } else if (cellStack.Count > 0) { mazeCell = cellStack.Pop(); } cell = mazeCell; } }
public static T Shuffle <T>(this T list, MonoRandom rnd) where T : IList { if (list == null) { throw new ArgumentNullException("list"); } for (int j = list.Count; j >= 1; j--) { int item = rnd.Next(0, j); if (item < j - 1) { var t = list[item]; list[item] = list[j - 1]; list[j - 1] = t; } } return(list); }
public static Colour[,,] GetRules(int ruleSeed) { if (ruleSeed == 1) { return new[, , ] { // If the serial number does not contain a vowel { { Blue, Yellow, Green, Red }, { Red, Blue, Yellow, Green }, { Yellow, Green, Blue, Red } }, // If the serial number contains a vowel { { Blue, Red, Yellow, Green }, { Yellow, Green, Blue, Red }, { Green, Red, Yellow, Blue } } } } ; var random = new MonoRandom(ruleSeed); var colours = new Colour[2, 3, 4]; for (int i = 1; i >= 0; --i) { for (int j = 0; j < 3; ++j) { for (int k = 0; k < 4; ++k) { colours[i, j, k] = (Colour)random.Next(4); } // Make sure they're not all the same. while (colours[i, j, 1] == colours[i, j, 0] && colours[i, j, 2] == colours[i, j, 0] && colours[i, j, 3] == colours[i, j, 0]) { colours[i, j, random.Next(4)] = (Colour)random.Next(4); } } } return(colours); }
private void initDicts(MonoRandom rng) { if (rng.Seed == 1) { addSymbol('ใ', new int[] { 5, 0, 4 }, new char[] { 'G', 'D', 'G' }); addSymbol('ɮ', new int[] { 4, 0, 5 }, new char[] { 'Z', 'D', 'R' }); addSymbol('ʖ', new int[] { 0, -1, 4 }, new char[] { 'C', 'S', 'O' }); addSymbol('ฬ', new int[] { 0, 2, 5 }, new char[] { 'J', 'X', 'Y' }); addSymbol('น', new int[] { 2, 1, 2 }, new char[] { 'V', 'B', 'L' }); addSymbol('Þ', new int[] { -2, 5, 5 }, new char[] { 'T', 'L', 'J' }); addSymbol('ฏ', new int[] { 4, 1, 2 }, new char[] { 'L', 'A', 'O' }); addSymbol('Ѩ', new int[] { 3, 5, 4 }, new char[] { 'G', 'A', 'S' }); addSymbol('Ԉ', new int[] { 4, 4, 2 }, new char[] { 'F', 'S', 'M' }); addSymbol('Ԓ', new int[] { 3, 2, 3 }, new char[] { 'P', 'O', 'F' }); addSymbol('ด', new int[] { -1, 3, 4 }, new char[] { 'K', 'Q', 'K' }); addSymbol('ล', new int[] { -1, -2, 4 }, new char[] { 'D', 'N', 'L' }); addSymbol('Ж', new int[] { 5, 0, 5 }, new char[] { 'Q', 'O', 'Z' }); //addSymbol('Ⴟ', new int[] { 5, 5, 3 }, new char[] { 'W', 'M', 'C' }); } else { for (var index = 0; index < rng.Next(0, 25); index++) { rng.NextDouble(); } var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; foreach (var c in "ใɮʖฬนÞฏѨԈԒดลЖႿ".OrderBy(x => rng.NextDouble()).Take(13)) { var x = rng.Next(0, 8) - 2; var y = rng.Next(0, 8) - 2; var z = rng.Next(2, 6); var i = alphabet[rng.Next(0, 26)]; var j = alphabet[rng.Next(0, 26)]; var k = alphabet[rng.Next(0, 26)]; addSymbol(c, new int[] { x, y, z }, new char[] { i, j, k }); } labels = labels.OrderBy(x => rng.NextDouble()).ToArray(); } chars = new List <char>(answers.Keys); }
void Start() { moduleId = moduleIdCounter++; for (int i = 0; i < Displays.Length; i++) { Displays[i].OnInteract += DisplayPress(i); } Displays[4].OnInteractEnded += delegate { release = true; }; rnd = RuleSeedable.GetRNG(); Debug.LogFormat(@"[Navinums #{0}] Using Ruleseed {1}", moduleId, rnd.Seed); gridDigits = Enumerable.Range(1, 9).ToList(); Setup(); }
public static RuleSet GetRules(int ruleSeed) { if (ruleSeed == 1) { return(new RuleSet( new[] { CutC, CutB, CutA, CutA | CutC, CutB, CutA | CutC, CutA | CutB | CutC, CutA | CutB, CutB }, new[] { CutB, CutA | CutC, CutB, CutA, CutB, CutB | CutC, CutC, CutA | CutC, CutA }, new[] { CutA | CutB | CutC, CutA | CutC, CutB, CutA | CutC, CutB, CutB | CutC, CutA | CutB, CutC, CutC } )); } var random = new MonoRandom(ruleSeed); return(new RuleSet( GetInstructions(random), GetInstructions(random), GetInstructions(random) )); }
private void Start() { rnd = RuleSeedable.GetRNG(); int seed = rnd.Seed; if (seed == 1) { YesAns = YesButton; NoAns = NoButton; UsesVanillaRuleModifierAPI = false; } else { int yes = rnd.Next(0, 2); int no = rnd.Next(0, 2); switch (yes) { case 0: YesAns = NoButton; break; default: YesAns = YesButton; break; } switch (no) { case 0: NoAns = YesButton; break; default: NoAns = NoButton; break; } UsesVanillaRuleModifierAPI = true; } _moduleId = _moduleIdCounter++; Module.OnActivate += Activate; }
public List <bool> Rules() { var list = new List <bool>(); //var log = new List<string>(); rng = Module.RuleSeed.GetRNG(); var one = rng.Seed == 1; ColBacking = UnityEngine.Random.Range(0, 8); ColButton = UnityEngine.Random.Range(0, 9); if (!Generator.pass) { Generator.Rules(this); } if (!one) { Counter = UnityEngine.Random.Range(0, 2); Module.DebugLog(0, "Chosen rules:"); } Module.coordX = coordX; Module.coordY = coordY; Module.BGManualTable = ManualTable; Possibilities = Generator.Swaps(Generator.Possibilities(this)); //Rules that check if the submit button contains a digit var Submit = Module.Submit.GetComponentInChildren <UnityEngine.TextMesh>(); if ((Generator.RuleIndicies.Contains(2) || Generator.RuleIndicies.Contains(3)) && Counter == 1) { Submit.text = Submit.text + " 0"; } foreach (int index in Generator.RuleIndicies) { list.Add(Possibilities[index].Func()); //log.Add(Possibilities[index].Descrip); if (!one) { Module.DebugLog(0, Possibilities[index].Descrip); } } //Module.DebugLog(string.Join("\n", log.Select(x => Generator.RuleIndicies[log.IndexOf(x)] + ": " + x + " - " + list[log.IndexOf(x)]).ToArray())); return(list.Concat(new[] { true }).ToList()); }
public void BuildMaze(MonoRandom rng) { for (var i = 0; i < Size; i++) { for (var j = 0; j < Size; j++) { if (i > 0) { rng.Next(); } if (j > 0) { rng.Next(); } } } PopulateMaze(rng); rng.Next(); rng.Next(); //Burn the coordinate circles. }
private static string[] GetWordsInternal(int ruleSeed) { if (ruleSeed == 1) { return((string[])vanillaPasswords.Clone()); } var random = new MonoRandom(ruleSeed); // Start with 17 random words from the list. var words1 = new string[passwords.Length]; Array.Copy(passwords, words1, passwords.Length); words1 = random.Shuffle(words1); var words = new string[35]; Array.Copy(words1, words, 17); // Add more words that are similar to the base words. int count = 17; for (var i = 0; i < 17 && count < 35; i++) { var toAdd = (from w in passwords where !words.Contains(w) select(word: w, pref: random.NextDouble(), dist: HammingDistance(w, words[i]))).ToArray(); Array.Sort(toAdd, (a, b) => { var r = a.dist - b.dist; return(r == 0 ? a.pref.CompareTo(b.pref) : r); }); var numberToAdd = Math.Min(random.Next(1, 5), 35 - count); for (int j = 0; j < numberToAdd; ++j) { words[count] = toAdd[j].word; ++count; } } Array.Sort(words); return(words); }