public void TestRandomSequence() { var generator = new LinearCongruentalGenerator(17); var answers = new[] { 0, 24107, 16552, 12125, 9427, 13152, 21440, 3383, 6873, 16117 }; foreach (var expected in answers) { var actual = generator.GetNext(); Assert.AreEqual(expected, actual); } }
public virtual void ReStart() { var filledCells = problem.filled.ToDictionary(cell => Tuple.Create<int, int>(cell.x, cell.y), cell => cell.Fill()); map = new Map(problem.width, problem.height); for (int x = 0; x < problem.width; x++) for (int y = 0; y < problem.height; y++) { Cell cell; if (filledCells.TryGetValue(Tuple.Create(x, y), out cell)) map[x, y] = cell; else map[x, y] = new Cell { x = x, y = y }; } units = problem.units; for (int i = 0; i < units.Length; i++) { units[i] = SpawnUnit(units[i], problem); } randomGenerator = new LinearCongruentalGenerator(seed); UnitIndeces = new int[problem.sourceLength]; for (int i = 0; i < problem.sourceLength; i++) { UnitIndeces[i] = randomGenerator.GetNext()%units.Length; } state = State.WaitUnit; step = 0; currentUnit = null; forbiddenSequenceChecker = null; moves = null; currentUnitIndex = 0; currentMovesScore = 0; currentSpellsScore = 0; previouslyExplodedLines = 0; enteredString = new StringBuilder(); EnteredMagicSpells = new List<string>(); }
public GameBase([NotNull] Problem problem, int seed, string[] knownMagicSpells) { this.problem = problem; this.seed = seed; this.knownMagicSpells = knownMagicSpells.Select(s => s.ToLower()).ToArray(); units = problem.units; UnitIndeces = new int[problem.sourceLength]; var randomGenerator = new LinearCongruentalGenerator(seed); for (int i = 0; i < problem.sourceLength; i++) UnitIndeces[i] = randomGenerator.GetNext() % units.Length; ReStart(); }