/// <summary> /// enables you to manually simulate the logic trying to crack your secret code /// </summary> private static string ManualGame() { ComputingLogic logic = new ComputingLogic(disableRepeatingColors: false); int steps = 1; while (true) { var newGuess = logic.MakeGuess(); Console.WriteLine(newGuess.ToString()); var response = new Response(); Console.WriteLine("enter the number of exact hits (B) : "); var input = Console.ReadLine(); int input_int; while ((!int.TryParse(input, out input_int))) { Console.WriteLine("invalid number, please provide an integer"); input = Console.ReadLine(); } response.ExactHits = input_int; if (response.ExactHits == Guess.c_GuessLenght) { return($"manual simulation finished, cracked the code in {steps} steps"); } Console.WriteLine("enter the number of Almost hits (X) : "); input = Console.ReadLine(); while ((!int.TryParse(input, out input_int))) { Console.WriteLine("invalid number, please provide an integer"); input = Console.ReadLine(); } response.AlmostHits = input_int; if (!logic.ReceiveResponse(response)) { return("mistake in at least one of the step's Response, no secret possible for the given results"); } steps++; } }
/// <summary> /// simulates a game where the given logic is trying to crack a random secret /// </summary> /// <param name="disableRepeatingColors"></param> private static void SimulateGameAsync(bool disableRepeatingColors) { Player player = new Player(); ComputingLogic logic = new ComputingLogic(disableRepeatingColors: disableRepeatingColors); var stepsCount = 1; var newGuess = logic.MakeGuess(); var response = player.TryNewGuess(newGuess); while (response.ExactHits != Guess.c_GuessLenght) { logic.ReceiveResponse(response); newGuess = logic.MakeGuess(); response = player.TryNewGuess(newGuess); stepsCount++; } Interlocked.Add(ref total_steps, stepsCount); }