public void Does_Problem_Have_Nine_Cells(ProblemLevels lev) { Problem problem = ProblemGenerator.GetProblem(lev); Assert.IsType <Problem>(problem); int[][] rows = problem.Rows; Assert.Equal <int>(9, rows.Length); }
public void SingleItem() { var problemGenerator = new ProblemGenerator(); var solutionEvaluator = new SolutionEvaluator(problemGenerator); var totalPrice = solutionEvaluator.Evaluate(new[] { 258434 }); Assert.AreEqual(564707.973M, totalPrice); }
public QuizModel() { this._anger = 0; this._contempt = 0; this._disgust = 0; this._neutral = 0; this._sadness = 0; this._surprise = 0; _numberOfConfidenceEvaluations = 0; _problemGenerator = new ProblemGenerator(); }
private void OnMouseDown() { if (audioGenerator == null) { return; } if (Time.time - lastClickTime2 < 1) { return; } lastClickTime2 = Time.time; TutorialProblem tp = GameObject.Find("Problem").GetComponent <TutorialProblem>(); ConcreteProblem cp = GameObject.Find("Problem").GetComponent <ConcreteProblem>(); ProblemGenerator pg = GameObject.Find("Problem").GetComponent <ProblemGenerator>(); if (tp != null) { if (tp.currentlyPlaying) { return; } GameObject.Find("TutorialManager").GetComponent <TutorialManager>().UpdateTutorialText(); tp.submitAnswer(note, octaveShift); } else if (pg != null) { if (cp != null && cp.currentlyPlaying) { return; } pg.submitAnswer(note, octaveShift); } else if (cp != null) { if (cp.currentlyPlaying) { return; } cp.submitAnswer(note, octaveShift); } audioGenerator.pitch = calcPitch((int)note, octaveShift); audioGenerator.Play(); }
// Start is called before the first frame update void Start() { rb = GetComponent <Rigidbody2D>(); sr = GetComponent <SpriteRenderer>(); anim = GetComponent <Animator>(); problemGenerator = GameObject.Find("Generator").GetComponent <ProblemGenerator>(); transform.up = new Vector2(0, 0); correctText = GameObject.Find("Correct_Score").GetComponent <Text>(); incorrectText = GameObject.Find("Incorrect_Score").GetComponent <Text>(); progressBarObject = GameObject.Find("ProgressBar"); curtainAnimator = GameObject.Find("Curtain").GetComponent <Animator>(); isDying = false; //problemGenerator.DrawLevel(); //problemGenerator.secondsPassed = 0; }
public void Does_Sample_Problem_Have_Correct_Values(ProblemLevels lev) { Problem problem = ProblemGenerator.GetProblem(lev); var expectedProblem = (lev == ProblemLevels.Easy) ? SampleProblems.easyProblem() : (lev == ProblemLevels.Medium) ? SampleProblems.mediumProblem() : (lev == ProblemLevels.Hard) ? SampleProblems.hardProblem() : (lev == ProblemLevels.Insane) ? SampleProblems.insaneProblem() : (lev == ProblemLevels.Impossible) ? SampleProblems.impossibleProblem() : SampleProblems.easyProblem(); for (int i = 0; i < problem.Rows.Length; i++) { Assert.Equal(expectedProblem[i], problem.Rows[i]); for (int j = 0; j < problem.Rows[i][j]; j++) { Assert.Equal(expectedProblem[i][j], problem.Rows[i][j]); } } }
public void CAN_I_SOLVE_VARIOUS_PROBLEMS(ProblemLevels diff, int organisms, int maxEpochs, int maxExtinctions) { Problem problem = ProblemGenerator.GetProblem(diff); _evo = new EvolutionSolution(_disp); Debug.WriteLine($"Attempting solution of {diff.ToString()} with {organisms} organisms \n"); int[][] proposedSolution = _evo.SolveB4ExtinctCount_Async(problem.Rows, organisms, maxEpochs, maxExtinctions).Result; var testResult = SudokuTool.Test(proposedSolution); var resultStatus = testResult.resultStatus; var resultErrors = testResult.errorCount; bool optimalResult = testResult.isOptimal; var stats = _evo.Stats; Debug.WriteLine(resultStatus); // show some stats System.Diagnostics.Debug.WriteLine($@"Final Status: {testResult.resultStatus} Errors: {testResult.errorCount} -- Stats -- | Epochs (years): {stats.epochsCompleted} | Mass Extinctions (resets): {stats.extinctions} | Organisms Created: {stats.organismsBorn} | Died of Old Age (>999 years): {stats.diedOfOldAge} | Mutation Fails: {stats.mutationFailed} | Evolution Successes: {stats.evolutionWorked} | Worst Replaced by Mating Results: {stats.culledCount} | Mating Results Were Best: {stats.bestBabies} | Rare Mutation Was Best: {stats.bestMutationsEver} | Random Solution Was Best: {stats.randomWasTheBest} "); var mutationvsevolution = ((double)stats.bestMutationsEver / stats.evolutionWorked); System.Diagnostics.Debug.WriteLine( $@"Evolution that turned out for the best: {mutationvsevolution:P1}"); System.Diagnostics.Debug.WriteLine( $@"Mating that resulted in KHAN: {stats.bestBabies / stats.matingPairs * 100}%"); Debug.WriteLine(resultErrors == 0 ? "Optimal solution found. \n" : "Did not find optimal solution \n"); Debug.WriteLineIf(resultErrors != 0, "\nBest solution found: \n"); _disp.DisplayMatrix(proposedSolution); Assert.True(optimalResult); }
public void Can_I_Get_Problems_From_Generator(ProblemLevels lev) { Problem problem = ProblemGenerator.GetProblem(lev); Assert.IsType <Problem>(problem); }
static void Main() { var generator = new ProblemGenerator(42); var problem = generator.Generate(1000, 100, 1, 1000, 1, 1000); var solvers = new (string name, Func <Problem, Solution> solve)[]
static void Main(string[] args) { Console.WriteLine("For the following parameters, enter a value or press ENTER to take defaults."); Console.WriteLine(" --------------- "); Console.WriteLine("Please select puzzle difficulty"); Console.WriteLine($"E (easy), M (medium), H (hard), I (insane), U (impossible) *default {_thisLevel}*"); string reqDifficulty = Console.ReadLine(); if (reqDifficulty == null) { _thisLevel = ProblemLevels.Medium; } else { switch (reqDifficulty.ToUpperInvariant()) { case "E": _thisLevel = ProblemLevels.Easy; break; case "M": _thisLevel = ProblemLevels.Medium; break; case "H": _thisLevel = ProblemLevels.Hard; break; case "I": _thisLevel = ProblemLevels.Insane; break; case "U": _thisLevel = ProblemLevels.Impossible; break; default: _thisLevel = ProblemLevels.Medium; break; } } Console.WriteLine($" --LEVEL SET TO {_thisLevel}-- "); int mo = 100; int mep = 5000; int me = 20; Console.WriteLine(" "); Console.WriteLine($"Please enter a number of hive organisms to use (50 - 200) *default {mo}*"); var maxOrganisms = Console.ReadLine(); if (!int.TryParse(maxOrganisms, out mo) || mo < 50 || mo > 200) { mo = 100; Console.WriteLine($" DEFAULT TO {mo} "); } Console.WriteLine(" "); Console.WriteLine($"Please enter a number Epochs for the organisms to work the problem (2000 - 5000) *default {mep}*"); var maxEpochs = Console.ReadLine(); if (!int.TryParse(maxEpochs, out mep) || mep < 2000 || mep > 5000) { mep = 5000; Console.WriteLine($" DEFAULT TO {mep} "); } Console.WriteLine(" "); Console.WriteLine($"Please enter a number Mass Extinctions to allow if all Epochs fail to resolve the puzzle (10 - 30) *default {me}*"); var maxExtinctions = Console.ReadLine(); if (!int.TryParse(maxExtinctions, out me) || me < 10 || me > 30) { me = 20; Console.WriteLine($" DEFAULT TO {me} "); } Console.WriteLine(" "); Console.WriteLine($"You have chosen a {_thisLevel} puzzle."); Console.WriteLine($"A hive of {mo} Organisms will spawn and work for {mep} Epochs."); Console.WriteLine($"If they fail to find an optimal solution, the hive will go extinct and another will spawn. (up to {me} times)"); Console.WriteLine(" "); Console.WriteLine(" ---- Press Enter to Begin ----- "); Console.ReadLine(); long startTime = DateTime.UtcNow.Ticks; _disp = new ConsoleDisplayMatrix(); _stats = new EvolutionStats(); _evo = new EvolutionSolution(_disp, _stats); Problem problem = ProblemGenerator.GetProblem(_thisLevel); Console.WriteLine("Starting problem resolution for a " + _thisLevel + " puzzle."); int[][] result = _evo.SolveB4ExtinctCount_Async(problem.Rows, mo, mep, me).Result; var testResults = SudokuTool.Test(result); long stopTime = DateTime.UtcNow.Ticks; _disp.SplashView(testResults, _evo.Stats, problem.Rows, result); Console.WriteLine(); Console.ForegroundColor = (ConsoleColor.Cyan); Console.WriteLine("This run took: " + TimeSpan.FromTicks(stopTime - startTime).TotalSeconds.ToString("#.##") + " seconds"); Console.ReadLine(); }