예제 #1
0
        private void onTriggerEnter(Collider other)
        {
            int[][] genomeKey = { new int[] { 2,  5, 17 }, new int[] {  2,  6, 11 }, new int[] { 6, 13, 15 }, new int[] { 1, 5, 17 },
                                  new int[] { 9, 10, 22 }, new int[] { 11, 21, 23 }, new int[] { 6,  7, 13 }, new int[] { 3, 5, 22 } };

            if (ReproducerReader == null)
            {
                return;
            }

            if (other != null && other.gameObject.tag == "Organism")
            {
                // contact between two organisms, trigger reproduction
                Genome childGenome1 = generateGamete();
                Genome childGenome2 = other.GetComponent <ReproductionBehaviour>()
                                      .generateGamete();

                Coordinates childCoords = MoverReader.Data.position;

                var template = OrganismEntityTemplate.GenerateOrganismEntityTemplate(
                    childCoords, childGenome1, childGenome2, genomeKey
                    );
                SpatialOS.WorkerCommands.CreateEntity("Organism", template, result =>
                {
                    if (result.StatusCode != StatusCode.Success)
                    {
                        Debug.Log("failed to create organism with error: " + result.ErrorMessage);
                        return;
                    }
                    Debug.Log("spawned child organism with ID: " + result.Response.Value);
                });
            }
        }
예제 #2
0
    private static void GenerateSnapshotProgrammatically()
    {
        var snapshotEntities = new Dictionary <EntityId, SnapshotEntity>();
        var currentEntityId  = 0;

        int[][] genomeKey = { new int[] { 2,  5, 17 }, new int[] {  2,  6, 11 }, new int[] { 6, 13, 15 }, new int[] { 1, 5, 17 },
                              new int[] { 9, 10, 22 }, new int[] { 11, 21, 23 }, new int[] { 6,  7, 13 }, new int[] { 3, 5, 22 } };

        for (int i = 0; i < 200; i++)
        {
            for (int j = 0; j < 200; j++)
            {
                Coordinates pos = new Coordinates(i, 0, j);
                Map <Evolution.Material, uint> initialRes = new Map <Evolution.Material, uint>(2);
                foreach (Evolution.Material mat in Enum.GetValues(typeof(Evolution.Material)))
                {
                    initialRes[mat] = (uint)Random.Range(0, 50);
                }
                snapshotEntities.Add(new EntityId(currentEntityId++), EnvironmentNodeEntityTemplate.GenerateEnvironmentNodeEntityTemplate(pos, initialRes));
            }
        }

        for (int id = currentEntityId; id < currentEntityId + 1000; id++)
        {
            Coordinates pos = new Coordinates(Random.Range(5f, 195f), 0.0f, Random.Range(5f, 195f));
            Evolution.Organism.Genome gen1 = new Evolution.Organism.Genome(GetRandomGenome());
            Evolution.Organism.Genome gen2 = new Evolution.Organism.Genome(GetRandomGenome());
            snapshotEntities.Add(new EntityId(id), OrganismEntityTemplate.GenerateOrganismEntityTemplate(pos, gen1, gen2, genomeKey));
        }

        Debug.Log(snapshotEntities.Count);
        SaveSnapshot(snapshotEntities);
    }