public void StartActualTest(bool useActualGenesForWholeGeneration) { var config = new Mock <IOptimizerConfiguration>(); config.Setup(c => c.PopulationSize).Returns(2); int actualValue = 4; genes.First().ActualInt = actualValue; config.Setup(c => c.Genes).Returns(genes); config.Setup(c => c.UseActualGenesForWholeGeneration).Returns(useActualGenesForWholeGeneration); var fitness = new Mock <OptimizerFitness>(config.Object, null); List <IChromosome> actualChromose = new List <IChromosome>(); fitness.Setup(f => f.Evaluate(It.IsAny <IChromosome>())).Returns(-10).Callback <IChromosome>(c => actualChromose.Add(c)); var unit = new GeneManager(); unit.Initialize(config.Object, fitness.Object); unit.Start(); fitness.Verify(); CollectionAssert.IsNotEmpty(actualChromose.Where(a => (int)((KeyValuePair <string, object>)a.GetGenes().First().Value).Value == actualValue)); var actualCount = actualChromose.Where(a => (int)((KeyValuePair <string, object>)a.GetGenes().First().Value).Value == actualValue).Count(); Assert.AreEqual(useActualGenesForWholeGeneration ? 2 : 1, actualCount); }
public void StartTest() { var config = new Mock <IOptimizerConfiguration>(); config.Setup(c => c.PopulationSize).Returns(2); config.Setup(c => c.Genes).Returns(genes); var fitness = new Mock <OptimizerFitness>(config.Object, null); fitness.Setup(f => f.Evaluate(It.IsAny <IChromosome>())).Returns(-10).Verifiable(); var unit = new GeneManager(); unit.Initialize(config.Object, fitness.Object); unit.Start(); fitness.Verify(); }
static void Main(string[] args) { Console.WindowWidth = 120; Game game = new Game(); if (GENEALGORITHM) { GeneManager manager = new GeneManager(game); manager.Initialize(); // return; } List <Player> players = new List <Player> { new EnhancedAI(), new BasicPlayer(), new StefanAI(), new GeneticAI(true, 1, 1) }; Console.WriteLine("Vilka två spelare skall mötas?"); for (int i = 1; i <= players.Count; i++) { Console.WriteLine(i + ": {0}", players[i - 1].Name); } int p1 = int.Parse(Console.ReadLine()); int p2 = int.Parse(Console.ReadLine()); Player player1 = players[p1 - 1]; Player player2 = players[p2 - 1]; player1.Game = game; player1.PrintPosition = 0; player2.Game = game; player2.PrintPosition = 9; game.Player1 = player1; game.Player2 = player2; Console.WriteLine("Hur många spel skall spelas?"); int numberOfGames = int.Parse(Console.ReadLine()); Console.WriteLine("Skriva ut första spelet? (y/n)"); string print = Console.ReadLine(); Console.Clear(); if (print == "y") { game.Printlevel = 2; } else { game.Printlevel = 0; } game.Initialize(); game.PlayAGame(true); Console.Clear(); bool player1starts = true; for (int i = 1; i < numberOfGames; i++) { game.Printlevel = 0; player1starts = !player1starts; game.Initialize(); game.PlayAGame(player1starts); if (LIVESTATS) { Console.ForegroundColor = ConsoleColor.White; Console.SetCursorPosition(0, 3); Console.Write(player1.Name + ":"); Console.ForegroundColor = ConsoleColor.Green; Console.SetCursorPosition((player1.Wongames * 100 / numberOfGames) + 15, 3); Console.Write("█"); Console.SetCursorPosition((player1.Wongames * 100 / numberOfGames) + 16, 3); Console.ForegroundColor = ConsoleColor.White; Console.Write(player1.Wongames); Console.ForegroundColor = ConsoleColor.White; Console.SetCursorPosition(0, 5); Console.Write(player2.Name + ":"); Console.ForegroundColor = ConsoleColor.Red; Console.SetCursorPosition((player2.Wongames * 100 / numberOfGames) + 15, 5); Console.Write("█"); Console.SetCursorPosition((player2.Wongames * 100 / numberOfGames) + 16, 5); Console.ForegroundColor = ConsoleColor.White; Console.Write(player2.Wongames); } else { Console.SetCursorPosition(0, 3); Console.WriteLine(player1.Name + ": " + player1.Wongames); Console.Write(player2.Name + ": " + player2.Wongames); } } Console.ReadLine(); }