예제 #1
0
    public override IEnumerator Enter(Machine owner, Brain controller)
    {
        mainMachine = owner;
        myBrain = controller;
        Legs myLeg = myBrain.legs;

        arriveBehaviour = new PathfindToPoint();
        seekBehaviour = new Seek();

        arriveBehaviour.Init(myLeg,myBrain.levelGrid);
        seekBehaviour.Init(myLeg);

        myLeg.addSteeringBehaviour(arriveBehaviour);
        myLeg.addSteeringBehaviour(seekBehaviour);

        //set speed back to normal
        myBrain.legs.maxSpeed = 5f;

        if(firstActivation)
        {
            //set cowardLevel for sheep. Random.value returns a random number between 0.0 [inclusive] and 1.0 [inclusive].
            float coward = 0.5f;

            myBrain.memory.SetValue("cowardLevel", coward);
            myBrain.memory.SetValue("chasedBy", new List<Brain>());
            myBrain.memory.SetValue("BeingEaten", false);
            myBrain.memory.SetValue("HP", 100f);

            firstActivation = false;
        }

        time = 0f;
        seekingTime = 0f;
        yield return null;
    }
예제 #2
0
    public override IEnumerator Enter(Machine owner, Brain controller)
    {
        mainMachine = owner;
        myBrain = controller;
        Legs myLeg = myBrain.legs;
        arriveBehaviour = new PathfindToPoint();
        seekBehaviour = new Seek();

        arriveBehaviour.Init(myLeg, myBrain.levelGrid);
        seekBehaviour.Init(myLeg);

        myLeg.addSteeringBehaviour(arriveBehaviour);
        myLeg.addSteeringBehaviour(seekBehaviour);

        myLeg.maxSpeed = 11f;
        time = 0f;
        ferocityRate = controller.memory.GetValue<float>("ferocity");

        sheepTarget = myBrain.memory.GetValue<SensedObject>("hasCommand");
        sheepMemory = sheepTarget.getMemory();
        sheepBrain = (Brain)sheepTarget.getObject().GetComponent("Brain");

        arriveBehaviour.setTarget(sheepTarget.getObject());

        //for machine learning
        float panic = sheepBrain.memory.GetValue<float>("Panic");
        float courage = sheepBrain.memory.GetValue<float>("cowardLevel");
        float chasedBy = sheepBrain.memory.GetValue<List<Brain>>("chasedBy").Count;
        float distanceWithMe = Vector2.Distance(sheepBrain.legs.getPosition(), myBrain.legs.getPosition());
        float distanceWithSheperd = Vector2.Distance(sheepBrain.legs.getPosition(), ((Legs)GameObject.FindGameObjectWithTag("Player").GetComponent<Legs>()).getPosition());
        float hungry = myBrain.memory.GetValue<float>("hungryLevel");
        float sheepHP = sheepBrain.memory.GetValue<float>("HP");

        string sheep = panic + "," + courage + "," + chasedBy + "," + distanceWithMe + "," + distanceWithSheperd + "," + hungry + "," + sheepHP;

        myBrain.memory.SetValue("targeting", sheep);

        yield return null;
    }