示例#1
0
    void SearchPlayers()
    {
        if (otherPlayer != null)
        {
            return;
        }

        GameObject[] players = GameObject.FindGameObjectsWithTag("Player");

        //Debug.Log("Found " + players.Length + " player(s)");

        bool bandera = true;

        for (int i = 0; i < players.Length; i++)
        {
            MovementNet movenet = players[i].GetComponent <MovementNet>();
            if (movenet != null)
            {
                print(!movenet.isLocalPlayer);
                print(movenet != this);
                if (movenet != this)
                {
                    otherPlayer             = movenet;
                    otherPlayer.otherPlayer = this;
                    Debug.Log("Found the other player");
                    bandera = false;
                    break;
                }
            }
        }
        if (bandera)
        {
            Debug.Log("Didn't Found the other player");
        }
    }
示例#2
0
    private void createTemplatePrefabs()
    {
        CarnivorePrefab = Instantiate <MovementNet>(CarnivorePrefab);
        if (SimulationSettings.Instance)
        {
            CarnivorePrefab.hiddenLayers = SimulationSettings.Instance.CarnivoreLayers;
        }
        CarnivorePrefab.gameObject.SetActive(false);

        HerbivorePrefab = Instantiate <MovementNet>(HerbivorePrefab);
        if (SimulationSettings.Instance)
        {
            HerbivorePrefab.hiddenLayers = SimulationSettings.Instance.HerbivoreLayers;
        }
        HerbivorePrefab.gameObject.SetActive(false);
    }
示例#3
0
    void fillAnimal(Transform parent, int population, MovementNet animalPrefab, IEnumerable <NeuralNet.Net> fittestNets)
    {
        if (parent.childCount < population)
        {
            while (parent.childCount < population)
            {
                Vector3 position = new Vector3(
                    (UnityEngine.Random.value - 0.5f) * fieldBounds.x * 0.9f,
                    GrassPrefab.transform.position.y,
                    (UnityEngine.Random.value - 0.5f) * fieldBounds.z * 0.9f);

                // TODO MOVE ALL THIS TO A BREEDER.....
                List <NeuralNet.Net> nets = new List <NeuralNet.Net>();
                if (fittestNets != null)
                {
                    nets.AddRange(fittestNets);
                }

                //if (parent.childCount > 0)
                //{
                //    Transform source = parent.GetChild(UnityEngine.Random.Range(0, parent.childCount));
                //    nets.Add(source.GetComponent<MovementNet>().Net);
                //}

                Debug.Log("POOL Size for " + animalPrefab.tag + ": " + nets.Count);
                if (nets.Count > 0)
                {
                    List <NeuralNet.Net> mutants = NextMutator(nets);
                    foreach (NeuralNet.Net net in mutants)
                    {
                        MovementNet animal = Instantiate <MovementNet>(animalPrefab, position, Quaternion.identity, parent);
                        animal.TransplantNet(net);
                        animal.gameObject.SetActive(true);
                    }
                }
                else
                {
                    // Random
                    MovementNet animal = Instantiate <MovementNet>(animalPrefab, position, Quaternion.identity, parent);
                    animal.gameObject.SetActive(true);
                }
            }
        }
    }
示例#4
0
    /**
     * When someone dies update the cache if they were the fittest.
     */
    public void OnDie(GameObject dead)
    {
        string      tag = dead.tag;
        MovementNet net = dead.GetComponent <MovementNet>();


        if (net != null && net.Net != null && net.Net.Fitness > 0)
        {
            string        type  = String.Join(".", net.Net.layerSizes.Select(p => p.ToString()).ToArray());
            string        name  = tag + "-" + type;
            NetCacheEntry entry = new NetCacheEntry
            {
                name    = name,
                tag     = tag,
                net     = net.Net,
                fitness = net.Net.Fitness
            };

            if (addFittestList(entry))
            {
                save();
            }
        }
    }