Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.IO;
- namespace Genetics
- {
- internal class Program
- {
- private const string PathForTest = "maybebest.save";
- private const string PathBotToSubmit = "../../save/bot.save";
- public static void Main ( string[] args )
- {
- RessourceLoad.InitMap ();
- string[] levels = GetLevels ();
- RessourceLoad.SetCurrentMap ( "flat" );
- NewTraining ( 5 );
- foreach ( string level in levels )
- {
- RessourceLoad.SetCurrentMap ( level );
- Train ( 5 );
- }
- /*
- Thread t1 = new Thread(() => Train(10000));
- RessourceLoad.SetCurrentMap("long");
- t1.Start();
- */
- /*
- Thread t3 = new Thread(() => Train(10);
- RessourceLoad.SetCurrentMap(levels[2]);
- t3.Start();
- if(!t1.IsAlive && !t2.IsAlive && !t3.IsAlive)
- */
- SaveBest ();
- }
- private static string[] GetLevels ()
- {
- List <string> levels = new List <string> ();
- foreach ( string s in Directory.GetFiles ( "../../map" ) )
- {
- int start = 0;
- while ( s [start] != 'p' )
- start++;
- start += 2;
- string fulllevelname = s.Substring ( start );
- int len = 0;
- while ( fulllevelname [len] != '.' )
- len++;
- string level = fulllevelname.Substring ( 0, len );
- levels.Add ( level );
- }
- foreach ( string s in levels )
- {
- Console.WriteLine ( s );
- }
- return levels.ToArray ();
- }
- private static void NewTraining ( Object n )
- {
- NewTraining ( ( int ) n );
- }
- private static void Train ( Object n )
- {
- Train ( ( int ) n );
- }
- /// <summary>
- /// This function create a whole new population
- /// and trains a population of 200 players by using new players at each generation
- /// </summary>
- /// <param name="n">number of generations you want to proceed</param>
- private static void NewTraining ( int n )
- {
- Factory.SetPathSave ( PathBotToSubmit );
- Factory.Init ();
- Factory.TrainWithNew ( n );
- Factory.PrintScore ();
- Factory.SaveState ();
- }
- /// <summary>
- /// This function trains a population of 200 players by using new players at each generation
- /// </summary>
- /// <param name="n">number of generations you want to proceed</param>
- private static void TrainWithNew ( int n )
- {
- Factory.SetPathLoadAndSave ( PathBotToSubmit );
- Factory.Init ();
- Factory.TrainWithNew ( n );
- Factory.PrintScore ();
- Factory.SaveState ();
- }
- /// <summary>
- /// This function trains a population of 200 players by duplicating and applying modification to the copy of
- /// the best players
- /// </summary>
- /// <param name="n">number of generations you want to proceed</param>
- private static void Train ( int n )
- {
- Factory.SetPathLoadAndSave ( PathBotToSubmit );
- Factory.Init ();
- Factory.Train ( n );
- Factory.PrintScore ();
- Factory.SaveState ();
- }
- /// <summary>
- /// Show the current best player
- /// </summary>
- private static void Showbest ()
- {
- Game1 game = new Game1 ();
- Factory.SetPathLoadAndSave ( PathBotToSubmit );
- Factory.Init ();
- Factory.GetBestPlayer ().SetStart ( RessourceLoad.GetCurrentMap () );
- game.SetPlayer ( Factory.GetBestPlayer () );
- game.Run ();
- }
- /// <summary>
- /// Show the nth player sorted by score in increasing order
- /// </summary>
- /// <param name="nth">player you want to access to, should be between 0 and 199</param>
- private static void ShowNth ( int nth )
- {
- Game1 game = new Game1 ();
- Factory.SetPathLoadAndSave ( PathBotToSubmit );
- Factory.Init ();
- Factory.PrintScore ();
- game.SetPlayer ( Factory.GetNthPlayer ( nth ) );
- game.Run ();
- }
- /// <summary>
- /// This function allows you to try the game
- /// </summary>
- private static void PlayAsHuman ()
- {
- Game1 game = new Game1 ();
- Player player = new Player ( false );
- player.SetStart ( RessourceLoad.GetCurrentMap () );
- game.SetPlayer ( player, true );
- game.Run ();
- }
- /// <summary>
- /// save best player in folder save, you will be marked on this, so DON'T forget it!
- /// </summary>
- private static void SaveBest ()
- {
- Factory.SetPathLoad ( PathBotToSubmit );
- Factory.Init ();
- var soloList = new List <Player> {Factory.GetBestPlayer ()};
- SaveAndLoad.Save ( PathBotToSubmit, soloList );
- Console.WriteLine ( "Saved Best Player" );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement