public static int [] CreateRandomSolution(RandomNumberInterface random) { int [] array = new int[GameLogic.MAX_NUMBER_OF_POSSIBLE_VALUES]; for (int i = 0; i < array.Length; i++) { array [i] = i; } Shuffle(array, random); int [] result = new int[GameLogic.MAX_NUMBERS]; Array.Copy(array, result, GameLogic.MAX_NUMBERS); return(result); }
//Fisher–Yates Shuffle public static void Shuffle(int [] array, RandomNumberInterface random) { int n = array.Length; while (n > 1) { int k = random.Next(n--); int temp = array[n]; array[n] = array[k]; array[k] = temp; } }
public void SetUp() { command = new PlayerGuessCommand(); command.gameModel = new GameModel(); command.guessResultSignal = new GuessResultSignal(); command.guessResultSignal.AddOnce(GuessResultSignalCallback); command.viewSwitcher = Substitute.For <IViewSwitcher> (); command.gameOverSignal = new GameOverSignal(); command.gameOverSignal.AddOnce(GameOverSignalCallback); command.statsModel = new StatsModel(); command.playSoundSignal = new PlaySoundSignal(); RandomNumberInterface random = Substitute.For <RandomNumberInterface> (); random.Next(Arg.Any <int>()).Returns(0); command.gameModel.randomNumberGenerator = random; command.gameModel.StartGame(); guessResultSignalDispatched = false; gameOverSignalDispatched = false; }