public Game(NeatPlayer p, int id) { threadId = id; player = p; listener = new UdpClient(0); port = ((IPEndPoint)listener.Client.LocalEndPoint).Port; }
static void Main(string[] args) { //Initialise log4net (log to console). XmlConfigurator.Configure(new FileInfo("log4net.properties")); // Experiment classes encapsulate much of the nuts and bolts of setting up a NEAT search. GameExperiment experiment = new GameExperiment(); // Load config XML. XmlDocument xmlConfig = new XmlDocument(); xmlConfig.Load("game.config.xml"); experiment.Initialize("BrainGene", xmlConfig.DocumentElement); if (LEARN) { // Create evolution algorithm and attach update event. _ea = experiment.CreateEvolutionAlgorithm(); _ea.UpdateEvent += new EventHandler(ea_UpdateEvent); //Start algorithm (it will run on a background thread). _ea.StartContinue(); //Hit return to quit. Console.ReadLine(); } else { // Have the user choose the genome XML file. NeatGenome genome = null; // Try to load the genome from the XML document. using (XmlReader xr = XmlReader.Create("C:\\Users\\Cantino\\Documents\\School\\Capstone\\NeatTicTacToe\\BrainGene\\bin\\Debug\\game_champion_gen_0.xml")) genome = NeatGenomeXmlIO.ReadCompleteGenomeList(xr, false, (NeatGenomeFactory)experiment.CreateGenomeFactory())[0]; // Get a genome decoder that can convert genomes to phenomes. var genomeDecoder = experiment.CreateGenomeDecoder(); // Decode the genome into a phenome (neural network). var phenome = genomeDecoder.Decode(genome); // Set the NEAT player's brain to the newly loaded neural network. NeatPlayer player = new NeatPlayer(null); player.Brain = phenome; Game game = new Game(player, 0); Console.WriteLine(game.PlayGameToEnd()); // Show the option to select the NEAT player Console.ReadLine(); } }
public FitnessInfo Evaluate(IBlackBox phenome) { double fitness = 0; NeatPlayer neatPlayer = new NeatPlayer(phenome); int threadId = Thread.CurrentThread.ManagedThreadId; Game game = new Game(neatPlayer, threadId); fitness = game.PlayGameToEnd(); // Update the evaluation counter. _evalCount++; if (fitness >= 4000) { _stopConditionSatisfied = true; } return(new FitnessInfo(fitness, fitness)); }