Ejemplo n.º 1
0
        async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Species.Clear();
                var species = await DataStore.GetItemsAsync(true);

                foreach (var species2 in species)
                {
                    Species.Add(species2);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
        public SimulationViewModel()
        {
            this.Simulation = new Simulation();
            this.World      = new WorldViewModel(Simulation.World);
            this.Species    = new List <SpeciesViewModel>();

            Vector = Cell.Create(new Vector2D(50, 50));


            foreach (BoidSpecies item in Simulation.Species)
            {
                Species.Add(new SpeciesViewModel(item, this));
            }

            int i = 10;

            foreach (var item in this.Simulation.Species)
            {
                item.CreateBoid(new Vector2D(i, i));
                i += 100;
            }

            this.SelectedSpecies   = Cell.Create(Species[0]);
            this.ControllerSpecies = Species.First(s => s.Name.Equals("controller"));

            StartStopTime = new StartStopTimerCommand(this);
        }
Ejemplo n.º 3
0
        private static Species GetIndividualsFromSaveGenome(List <SaveGenome> saveGenomes)
        {
            Random  rand        = new Random();
            Species individuals = new Species();

            for (int i = 0; i < saveGenomes.Count; i++)
            {
                individuals.Add(new Individual(i,
                                               saveGenomes[i].x,
                                               saveGenomes[i].y,
                                               saveGenomes[i].dx,
                                               saveGenomes[i].dy,
                                               saveGenomes[i].dx2,
                                               saveGenomes[i].dy2,
                                               new Parameters(saveGenomes[i].neighborhoodRadius,
                                                              saveGenomes[i].normalSpeed,
                                                              saveGenomes[i].maxSpeed,
                                                              saveGenomes[i].c1,
                                                              saveGenomes[i].c2,
                                                              saveGenomes[i].c3,
                                                              saveGenomes[i].c4,
                                                              saveGenomes[i].c5),
                                               saveGenomes[i].type,
                                               saveGenomes[i].isMobile)
                                );
            }

            return(individuals);
        }
Ejemplo n.º 4
0
    private void LoadSpecies()
    {
        const int maxIndexNumber = 190;

        int numBaseStats = IsYellow ? 151 : 150;

        byte[]     pokedex = ROM.Subarray(SYM["PokedexOrder"], maxIndexNumber);
        ReadStream data    = ROM.From("BaseStats");

        for (int i = 0; i < numBaseStats; i++)
        {
            byte indexNumber = (byte)Array.IndexOf(pokedex, data.Peek());
            Species.Add(new RbySpecies(this, ++indexNumber, data));
        }

        if (this is RedBlue)
        {
            Species.Add(new RbySpecies(this, 21, ROM.From(SYM["MewBaseStats"])));
        }

        // Add MISSINGNO data
        for (int i = 1; i <= maxIndexNumber; i++)
        {
            if (pokedex[i - 1] == 0)
            {
                RbySpecies species = new RbySpecies(this, (byte)i);
                Species.Add(new RbySpecies(this, (byte)i));
            }
        }
    }
Ejemplo n.º 5
0
        public void Init(int inputNodesCount, int outputNodesCount)
        {
            var initSpecie = new Specie();

            var progenitorGenome = new Genome();

            for (int j = 0; j < inputNodesCount; j++)
            {
                var inputNode = new NodeGene(NodeGeneType.Input);
                progenitorGenome.AddNodeGene(inputNode, inputNode.Id);
            }
            for (int j = 0; j < outputNodesCount; j++)
            {
                var outputNode = new NodeGene(NodeGeneType.Output);
                progenitorGenome.AddNodeGene(outputNode, outputNode.Id);
            }

            for (int i = 0; i < Config.Population; i++)
            {
                var newGenome = new Genome(progenitorGenome);
                newGenome.TryMutate();
                initSpecie.Genomes.Add(newGenome);
            }

            Species.Add(initSpecie);
            CurrentSpecie = Species.First();
            CurrentPlayer = CurrentSpecie.Genomes.First();
        }
Ejemplo n.º 6
0
        private static Species GetIndividualsFromSaveGenome(List<SaveGenome> saveGenomes)
        {
            Random rand = new Random();
            Species individuals = new Species();
            for (int i = 0; i < saveGenomes.Count; i++ )
            {
                individuals.Add(new Individual(i,
                    saveGenomes[i].x,
                    saveGenomes[i].y,
                    saveGenomes[i].dx,
                    saveGenomes[i].dy,
                    saveGenomes[i].dx2,
                    saveGenomes[i].dy2,
                    new Parameters(saveGenomes[i].neighborhoodRadius,
                                   saveGenomes[i].normalSpeed,
                                   saveGenomes[i].maxSpeed,
                                   saveGenomes[i].c1,
                                   saveGenomes[i].c2,
                                   saveGenomes[i].c3,
                                   saveGenomes[i].c4,
                                   saveGenomes[i].c5),
                    saveGenomes[i].type,
                    saveGenomes[i].isMobile)
                 );
            }

            return individuals;
        }
Ejemplo n.º 7
0
        private async Task InitAsync(Film film)
        {
            IsLoading = true;
            if (film != null)
            {
                Film = film;

                Species.Clear();
                foreach (var specy in film.species)
                {
                    var currentSpecy = await _speciesRepository.GetSpecieAsync(specy) ??
                                       await _dataService.GetSingleByUrl <Specie>(specy);

                    Species.Add(currentSpecy);
                }
                Species = Species.OrderBy(item => item.name).ToObservableCollection();

                Starships.Clear();
                foreach (var starship in film.starships)
                {
                    var currentStarship = await _starshipRepository.GetStarshipAsync(starship) ??
                                          await _dataService.GetSingleByUrl <Starship>(starship);

                    Starships.Add(currentStarship);
                }
                Starships = Starships.OrderBy(item => item.name).ToObservableCollection();

                Vehicles.Clear();
                foreach (var vehicle in film.vehicles)
                {
                    var currentVehicle = await _vehiclesRepository.GetVehicleAsync(vehicle) ??
                                         await _dataService.GetSingleByUrl <Vehicle>(vehicle);

                    Vehicles.Add(currentVehicle);
                }
                Vehicles = Vehicles.OrderBy(item => item.name).ToObservableCollection();

                People.Clear();
                foreach (var character in film.characters)
                {
                    var currentPeople = await _peopleRepository.GetPeopleAsync(character) ??
                                        await _dataService.GetSingleByUrl <People>(character);

                    People.Add(currentPeople);
                }
                People = People.OrderBy(item => item.name).ToObservableCollection();

                Planets.Clear();
                foreach (var planet in film.planets)
                {
                    var currentPlanet = await _planetRepository.GetPlanetAsync(planet) ??
                                        await _dataService.GetSingleByUrl <Planet>(planet);

                    Planets.Add(currentPlanet);
                }
                Planets = Planets.OrderBy(item => item.name).ToObservableCollection();
            }
            IsLoading = false;
        }
Ejemplo n.º 8
0
    public static void Speciacte(this List <Species> species, List <Agent> population)
    {
        //find new reprezentatives
#if EXISTING_REPRESENTATIVE
        foreach (var s in species)
        {
            Agent closest_a = null;
            float min_score = Constants.Con.new_representative_max_distance;
            int   i         = 0;
            int   mini      = 0;
            foreach (var agent in population)
            {
                float score = agent.brain.Distance(s.Reprezentative);
                if (score < min_score)
                {
                    min_score = score;
                    closest_a = agent;
                    mini      = i;
                }
                i++;
            }
            if (closest_a != null)
            {
                s.Reprezentative = closest_a.brain;
                s.Add(closest_a);
                population.RemoveAt(mini);
            }
            else
            {
                s.Dead = true;
            }
        }
        species.RemoveAll(s => s.Dead);
#endif

        //assign every agent to closest species
        foreach (var agent in population)
        {
            Species closest   = null;
            float   min_score = Constants.Con.delta_t;
            foreach (var s in species)
            {
                float score = agent.brain.Distance(s.Reprezentative);
                if (score < min_score)
                {
                    min_score = score;
                    closest   = s;
                }
            }
            if (closest != null)
            {
                closest.Add(agent);
            }
            else
            {
                species.Add(new Species(agent));
            }
        }
    }
Ejemplo n.º 9
0
        /// <inheritdoc/>
        public ISpecies CreateSpecies()
        {
            ISpecies species = new BasicSpecies();

            species.Population = this;
            Species.Add(species);
            return(species);
        }
Ejemplo n.º 10
0
        public void Load(string path)
        {
            DoAutosave = false;

            Path = path;

            using (Stream SettingsStream = File.OpenRead(path))
            {
                XPathDocument  Doc    = new XPathDocument(SettingsStream);
                XPathNavigator Reader = Doc.CreateNavigator();
                Reader.MoveToRoot();
                Reader.MoveToChild("Population", "");

                ReadFromXML(Reader);

                List <Species> AllSpecies = new List <Species>();
                foreach (XPathNavigator nav in Reader.Select("Species/Species"))
                {
                    Guid   SpeciesGUID = Guid.Parse(nav.GetAttribute("GUID", ""));
                    string SpeciesPath = nav.GetAttribute("Path", "");

                    Species LoadedSpecies = Sociology.Species.FromFile(SpeciesPath);
                    if (LoadedSpecies.GUID != SpeciesGUID)
                    {
                        throw new Exception("Stored GUID does not match that of the species.");
                    }

                    AllSpecies.Add(LoadedSpecies);
                }
                foreach (var species in AllSpecies)
                {
                    species.ResolveChildren(AllSpecies);
                }

                Species.Clear();
                foreach (var toplevel in AllSpecies.Where(s => s.Parent == null))
                {
                    Species.Add(toplevel);
                }

                foreach (XPathNavigator nav in Reader.Select("Sources/Source"))
                {
                    string Path       = nav.GetAttribute("Path", "");
                    Guid   SourceGUID = Guid.Parse(nav.GetAttribute("GUID", ""));

                    DataSource LoadedSource = DataSource.FromFile(Path);
                    if (SourceGUID != LoadedSource.GUID)
                    {
                        throw new Exception("Stored GUID does not match that of the data source.");
                    }

                    Sources.Add(LoadedSource);
                }
            }

            DoAutosave = true;
        }
Ejemplo n.º 11
0
    private void LoadSpecies()
    {
        ByteStream dataStream = ROM.From("BaseData");
        ByteStream nameStream = ROM.From("PokemonNames");

        for (int index = 0; index <= 0xff; index++)
        {
            Species.Add(new GscSpecies(this, dataStream, nameStream));
        }
    }
Ejemplo n.º 12
0
        public void Init(JToken json)
        {
            CurrentFrame      = 0;
            Timeout           = Config.Timeout;
            RightmostPosition = 0;
            Generation        = json.Value <int>("Generation");

            foreach (var specieJson in json["Species"].Children())
            {
                Species.Add(new Specie(specieJson));
            }

            CurrentSpecie = Species.First();
            CurrentPlayer = CurrentSpecie.Genomes.First();

            _gameInformationHandler.LoadSaveState();
        }
 private void Culture_SelectedIndexChanged(object sender, EventArgs e)
 {
     selectedCulture = Culture.CreateCulture(GenerationConfiguration.Culture, GenerationConfiguration.UseCitizens, GenerationConfiguration.UseMishaps);
     if (selectedCulture is Classic.Zhodani.Culture)
     {
         // Psionic training and the like are handled at the "Culture" level
         ((Classic.Zhodani.Culture)selectedCulture).SkillOffered += SkillOffered;
     }
     if (selectedCulture != null)
     {
         Species.Clear();
         var list = selectedCulture.Species(generationStyle).Keys.ToList();
         foreach (var s in list)
         {
             Species.Add(s);
         }
     }
 }
Ejemplo n.º 14
0
 public void InitializeSpecies(List <CritterTypeSetting> critterTypes)
 {
     // Initialize origin species with a random genotype
     foreach (CritterTypeSetting critterTypeSetting in critterTypes)
     {
         var     originGenotype = (AbstractBrainGenotype)Activator.CreateInstance(BrainTypes.BrainTypeMap[critterTypeSetting.BrainType]);
         Species originSpecies  = new Species()
         {
             Id             = NextSpeciesId,
             Representative = originGenotype,
             TimeCreated    = 0,
         };
         NextSpeciesId++;
         Species.Add(critterTypeSetting.TypeTag, new List <Species>()
         {
             originSpecies
         });
     }
 }
        /// <summary>
        /// Create an initial random population.
        /// </summary>
        public void Reset()
        {
            // create the genome factory
            if (IsHyperNEAT)
            {
                CODEC         = new HyperNEATCODEC();
                GenomeFactory = new FactorHyperNEATGenome();
            }
            else
            {
                CODEC         = new NEATCODEC();
                GenomeFactory = new FactorNEATGenome();
            }

            // create the new genomes
            Species.Clear();

            // reset counters
            GeneIdGenerate.CurrentID       = 1;
            InnovationIDGenerate.CurrentID = 1;

            EncogRandom rnd = RandomNumberFactory.Factor();

            // create one default species
            BasicSpecies defaultSpecies = new BasicSpecies();

            defaultSpecies.Population = this;

            // create the initial population
            for (int i = 0; i < PopulationSize; i++)
            {
                NEATGenome genome = GenomeFactory.Factor(rnd, this,
                                                         InputCount, OutputCount,
                                                         InitialConnectionDensity);
                defaultSpecies.Add(genome);
            }
            defaultSpecies.Leader = defaultSpecies.Members[0];
            Species.Add(defaultSpecies);

            // create initial innovations
            Innovations = new NEATInnovationList(this);
        }
Ejemplo n.º 16
0
        public override void Reproduce()
        {
            //Currently it will just fill up to max population

            // TODO: add something to prevent mating with self
            //for (int i = 0; i < 1; i++) {
            //	ChaoticSeer _seerX = Species.Random;
            //	ChaoticSeer _seerY = Species[i];
            //	ChaoticSeer _seerChild = _seerY.MateWith(_seerX);
            //	_seerChild.Identity = _seerX.Identity + _seerY.Identity;
            //	Species.Add(_seerChild);
            //}

            do
            {
                ChaoticSeer _seerX     = Species.Random;
                ChaoticSeer _seerY     = Species.Random;
                ChaoticSeer _seerChild = _seerX.MateWith(_seerY);
                _seerChild.Identity = _seerX.Identity + _seerY.Identity;
                Species.Add(_seerChild);
            } while (Species.Count < MAX_POPULATION);
        }
Ejemplo n.º 17
0
        private async Task InitAsync(People person)
        {
            IsLoading = true;

            if (person != null)
            {
                Person = person;

                Species.Clear();
                if (person.species != null && person.species.Count() > 1)
                {
                    foreach (var specy in person.species)
                    {
                        var currentSpecy = await _speciesRepository.GetSpecieAsync(specy) ??
                                           await _dataService.GetSingleByUrl <Specie>(specy);

                        Species.Add(currentSpecy);
                    }
                    Species = Species.OrderBy(item => item.name).ToObservableCollection();
                }
                else
                {
                    var specy = person.species.FirstOrDefault();
                    if (specy != null)
                    {
                        CurrentSpecie = await _speciesRepository.GetSpecieAsync(specy) ??
                                        await _dataService.GetSingleByUrl <Specie>(specy);
                    }
                }

                Starships.Clear();
                foreach (var starship in person.starships)
                {
                    var currentStarship = await _starshipRepository.GetStarshipAsync(starship) ??
                                          await _dataService.GetSingleByUrl <Starship>(starship);

                    Starships.Add(currentStarship);
                }
                Starships = Starships.OrderBy(item => item.name).ToObservableCollection();

                Vehicles.Clear();
                foreach (var vehicle in person.vehicles)
                {
                    var currentVehicle = await _vehiclesRepository.GetVehicleAsync(vehicle) ??
                                         await _dataService.GetSingleByUrl <Vehicle>(vehicle);

                    Vehicles.Add(currentVehicle);
                }
                Vehicles = Vehicles.OrderBy(item => item.name).ToObservableCollection();

                var movies = new ObservableCollection <Film>();
                foreach (var film in person.films)
                {
                    var currentFilm = await _filmRepository.GetFilmAsync(film) ??
                                      await _dataService.GetSingleByUrl <Film>(film);

                    movies.Add(currentFilm);
                }
                Movies = movies.OrderBy(item => item.episode_id).ToObservableCollection();

                HomeWorld = await _planetRepository.GetPlanetAsync(Person?.homeworld) ??
                            await _dataService.GetSingleByUrl <Planet>(Person?.homeworld);
            }
            IsLoading = false;
        }
Ejemplo n.º 18
0
        public List<Species> CreatePopulation(int width, int height)
        {
            if (parameters == null)
                return null;

            List<Species> newListSpecies = new List<Species>();
            Parameters tempParam;

            for (int i = 0; i < parameters.Count; i++)
            {
                tempParam = parameters[i];
                var spcs = new Species(new List<Individual>());
                for (int j = 1; j < popCounts[i]; j++)
                {
                    spcs.Add(new Individual(j, rand.NextDouble() * width,
                            rand.NextDouble() * height, rand.NextDouble() * 10 - 5,
                            rand.NextDouble() * 10 - 5, new Parameters(
                                    tempParam)));

                }
                newListSpecies.Add(spcs);
            }
            //mutate();
            return newListSpecies;
        }
Ejemplo n.º 19
0
        private void AddGenomeToSpecies(Genome genome)
        {
            List<Species> possibleSpecies = new List<Species>(species);

            // Attempt to find a compatable species
            while (possibleSpecies.Count > 0) {
                // Select a random species from the list
                Species selectedSpecies = possibleSpecies[evoConfig.rng.Next(possibleSpecies.Count)];

                // If the select species is within range of the compatability threshold add it to the species
                if (selectedSpecies.genomes.First() - genome < evoConfig.CompatablilityThresholdConstant) {
                    selectedSpecies.Add(genome);
                    return;
                }

                // Cross this species attempt off our list (literally, because its a list)
                possibleSpecies.Remove(selectedSpecies);
            }

            // We could not find a species, make a new one
            Species newSpecies = new Species();

            // Add the genome to the species
            newSpecies.Add(genome);

            // Add the species to the species list
            species.Add(newSpecies);
        }