public static void scoreCritter(int score, int[] computer, int breakpoint) { ComputerScore entry = new ComputerScore(score, computer, breakpoint); currentGeneration.Add(entry); if (entry.score > hallOfFameScore) { hallOfFameScore = entry.score; hallOfFame.Add(entry.computer); Console.WriteLine("hall of fame entry added: " + score); } }
private void InitRound() { Countdown = 60; int i = 0; int[] numbers = Numbers.ToArray(); PlayerOperands = new List <int>(); PlayerOperators = new List <string>(); timer.Interval = 1000; timer.Tick += new EventHandler(timer_Tick); timer.Start(); lblPlayerScoreDisplay.Text = PlayerScore.ToString(); lblComputerScoreDisplay.Text = ComputerScore.ToString(); lblRoundNo.Text = "Round " + RoundNo; Button[] numberButtons = new Button[] { btnNum1, btnNum2, btnNum3, btnNum4, btnNum5, btnNum6 }; foreach (Button b in numberButtons) { b.Text = numbers[i].ToString(); i++; } switch (Difficulty) { case "easy": ea = new EasyAlgorithm(Goal, Numbers.ToList()); gca = new GetComputerAnswer(ea.GetComputerAnswer); break; case "normal": double Temperature = 1000; a = new Algorithm(Goal, Temperature, Numbers.ToList()); gca = new GetComputerAnswer(a.GetComputerAnswer); break; } AiWorker.RunWorkerAsync(); }
public void Reset() { if (PlayerScore != null) { PlayerScore.Reset(); ComputerScore.Reset(); } Board.Reset(); PlayerSetScoreControl.HideAsync(); HintWindow.ShowAsync(false, false, "Swipe Up to and hit New Game!"); if (GridDeck.Items.Count > 52) { Debug.Assert(false, "Too many cards in your deck after reset!"); } HintWindow.ResetScoreHistory(); ViewCallback.Reset(); }
public static void naturalSelection() { nextGeneration.Clear(); int totalScore = 0; currentGeneration.Sort((a, b) => b.score.CompareTo(a.score)); //collect score data for display maxScores.Add(currentGeneration[0].score); foreach (ComputerScore score in currentGeneration) { totalScore += score.score; } averageScores.Add(totalScore / currentGeneration.Count); //automatically include the top contenders in the next generation. //If the top contenders are mutated, their breakpoints will be used. int topContendersAmt = critterThreads / 6; int[] breakpoints = new int[topContendersAmt]; int breakpointCounter = 0; for (int i = 0; i < topContendersAmt; i++) { nextGeneration.Add(currentGeneration[i].computer); breakpoints[i] = currentGeneration[i].breakpoint; breakpointCounter += currentGeneration[i].breakpoint; } topContendersBreakpointAvg.Add(breakpointCounter / topContendersAmt); int p = critterThreads / 5; while (nextGeneration.Count <= critterThreads) { //take several random selections, and grab the one with the highest score. ComputerScore mother = currentGeneration[rand.Next(currentGeneration.Count)]; ComputerScore father = currentGeneration[rand.Next(currentGeneration.Count)]; for (int i = 0; i < 5; i++) { ComputerScore altMother = currentGeneration[rand.Next(currentGeneration.Count)]; if (altMother.score > mother.score) { mother = altMother; } ComputerScore altFather = currentGeneration[rand.Next(currentGeneration.Count)]; if (altFather.score > father.score) { father = altFather; } } int[] fatherMachine = father.computer; int[] motherMachine = mother.computer; int combiningPoint = rand.Next(StackComputer.tapeSize); int[] childMachine = new int[StackComputer.tapeSize]; for (int k = 0; k < combiningPoint; k++) { childMachine[k] = fatherMachine[k]; } for (int k = combiningPoint; k < childMachine.Length; k++) { childMachine[k] = motherMachine[k]; } nextGeneration.Add(childMachine); p++; } //mutate 25% of contestants for (int i = 0; i < critterThreads * mutationRate; i++) { int accessed = rand.Next(nextGeneration.Count); if (accessed >= topContendersAmt) { nextGeneration[accessed][rand.Next(StackComputer.tapeSize)] = rand.Next(StackComputer.tapeSize); } else { if (breakpoints[accessed] < 0) { nextGeneration[accessed][rand.Next(StackComputer.tapeSize)] = rand.Next(StackComputer.tapeSize); } else { nextGeneration[accessed][breakpoints[accessed]] = rand.Next(9); } } } }