Beispiel #1
0
	protected override void UpdatePhenome() {
		Feelers.Feel(transform, DIRECTIONS, 0.5f, sensors, true);

		float[] outputs = neuralNet.Evaluate(sensors);

		float leftTheta = outputs[0] * 6;
		float rightTheta = outputs[1] * 6;
		float speed = outputs[2] * 6;

		float dt = Time.fixedDeltaTime;

		float angle = transform.rotation.eulerAngles.z;
		angle += (leftTheta - rightTheta) * dt * 200;

		float x = Mathf.Cos(Mathf.Deg2Rad * angle);
		float y = Mathf.Sin(Mathf.Deg2Rad * angle);
		Vector3 heading = new Vector3(x, y, 0);

		heading *= speed * dt;
		totalDistance += Vector3.Magnitude(heading);
		transform.position += heading;
		gameObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, angle));

		Vector2 pos = new Vector2(transform.position.x, transform.position.y);
		CACHE[0] = null;
		Physics2D.OverlapCircleNonAlloc(pos, 0.1f, CACHE);
		if (CACHE[0] != null) {
			// Debug.Log(leftTheta + " " + rightTheta + " " + speed);
			SetAsDone();
		}

		if (totalDistance > 25)
			SetAsDone();
	}
Beispiel #2
0
        private void AddFeeler()
        {
            Feeler newFeeler = new Feeler(this, AmountOfFeelers, true);

            newFeeler.AddAndMesh();
            Feelers.Add(newFeeler);
        }
Beispiel #3
0
    // Use this for initialization
    protected override void initializeAgent()
    {
        numInputs = 4;
        numOutputs = 2;
        numLayers = 1;
        numNeuronsPerLayer = 6;

        targetsEnabled = true;
        mouseIsTarget = false;

        userControl = false;

        //Create sensors
        feelers = new Feelers(this, radius*3); 		//TODO add perpendicular feelers to allow agent to know when it's moving along a wall.
        adjAgents = new AdjacentAgents(this, radius*3, grid);
        pieSlices = new PieSlices(this, adjAgents);

        //Create brain and genetic algorithm
        brain = new NeuralNet(numInputs, numOutputs, numLayers, numNeuronsPerLayer);
        setGeneticAlgorithm( new GeneticAlgorithmOld(40, numInputs, numOutputs, numLayers, numNeuronsPerLayer));

        startLocation = transform.position;
        startRotation = transform.rotation;

        createFourTargets();

        reset ();
    }
Beispiel #4
0
    // Use this for initialization
    protected override void initializeAgent()
    {
        seekMouse = false;

        //Sensors
        feelers = new Feelers(this, radius*3);
        adjAgents = new AdjacentAgents(this, radius*3, grid);
        pieSlices = new PieSlices(this, adjAgents);
    }