示例#1
0
        public EvolutionRunner(WorldDbContext dbContext, MutantManager mutantManager, EvolverSettings settings, int[] mutants = null)
        {
            this.dbContext     = dbContext;
            this.mutantManager = mutantManager;
            this.settings      = settings;
            this.mutants       = mutants;
            numMutants         = mutants == null ? dbContext.NumMutants : mutants.Length;
            mutantMemory       = new sbyte[numMutants][];

            SetUpMap();

            mutantsByScore = new SortedDictionary <long, HashSet <int> >();
            for (int i = 0; i < numMutants; ++i)
            {
                var mutantStat = dbContext.Mutants.Find(GetMutantId(i));
                AddMutantScore(i, mutantStat.Score);
            }
        }
示例#2
0
        public EvolverApplicationContext()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            worldPath = Path.Combine(Application.StartupPath, "world");
            dbPath    = Path.Combine(worldPath, "world.db");

            if (Directory.Exists(worldPath))
            {
                try
                {
                    Directory.CreateDirectory(worldPath);
                    var connectionString = new SQLiteConnectionStringBuilder()
                    {
                        DataSource = dbPath
                    }.ConnectionString;
                    var conn = new SQLiteConnection(connectionString);
                    conn.Open();
                    dbContext     = new WorldDbContext(conn, true);
                    mutantManager = new MutantManager(dbContext, worldPath);
                    mutantManager.LoadMutants();
                    ShowWorld();
                }
                catch (Exception e)
                {
                    while (e.InnerException != null)
                    {
                        e = e.InnerException;
                    }
                    MessageBox.Show("Failed to load world: " + e.Message, "Fatal Error");
                    Environment.Exit(-1);
                }
            }
            else
            {
                var createWorldForm = new CreateWorldForm();
                createWorldForm.Closed            += OnCreateWorldFormClosed;
                createWorldForm.CreateWorldHandler = CreateWorld;
                createWorldForm.Show();
            }
        }