/** * Assigns an AI brain to this player. This is used when * loading a brain from an existing neural network xml champion file. */ public AIFighter getFighterBrain() { //try to load a champion file. If any issues, use default AI. try { // 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. AIExperiment experiment = new AIExperiment(new AIFighterEvaluatorFactory()); // Load config XML. XmlDocument xmlConfig = new XmlDocument(); xmlConfig.Load("ai.config.xml"); experiment.Initialize("AI", xmlConfig.DocumentElement); // assign genome decoder for reading champion files IGenomeDecoder <NeatGenome, IBlackBox> decoder = experiment.CreateGenomeDecoder(); //load existing champion file into a genome string championFileLocation = "coevolution_champion.xml"; XmlReader xr = XmlReader.Create(championFileLocation); NeatGenome genome = NeatGenomeXmlIO.ReadCompleteGenomeList(xr, false)[0]; //decode genome into a usable AIFighter brain. return(new AIFighter(decoder.Decode(genome))); } catch (System.Exception e) { Debug.Log("Unable to load CHAMPION xml file. It may not exist.\n" + e); return(null); } }
// Use this for initialization void Start() { // 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. AIExperiment experiment = new AIExperiment(new AIFighterEvaluatorFactory()); // Load config XML. XmlDocument xmlConfig = new XmlDocument(); xmlConfig.Load("ai.config.xml"); experiment.Initialize("AI", xmlConfig.DocumentElement); // 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(); }