Exemplo n.º 1
0
 /// <summary>
 /// As long as we have individuals we need to simulate, we need to simulate them
 /// otherwise we signal the event handler that all the simulations have finished
 /// </summary>
 private static void doNextSim()
 {
     if (numberSimulated < MutationManager.Instance.generationSize - 1)
     {
         if (toBeDone.Count < 1)
         {
             return;
         }
         numberSimulated++;
         IndividualFunctions.Simulate(toBeDone.Pop());
     }
     else
     {
         numberSimulated = 0;
         finishGenerationSimulation();
     }
 }
Exemplo n.º 2
0
    public void finish(Generation gen)
    {
        Individual best = gen.currentBest;

        Debug.Log("Cost : " + best.cost);
        Debug.Log("Fuel (m^3) : " + best.fuelVolume);
        Debug.Log("Weight : " + best.weight);
        Debug.Log("Score : " + best.score);
        Debug.Log("Height : " + best.maxHeight);
        Debug.Log("Time in Air : " + best.timeInAir);

        Individual copy = new Individual(best);

        GameObject bestObject = IndividualFunctions.Instantiate(copy);

        UnityEngine.Object.Destroy(bestObject.GetComponent <Rigidbody>());
        follow = bestObject;
    }
Exemplo n.º 3
0
    /// <summary>
    /// Fixed update because I do not want to be dependant on frame-rate.
    /// Every tick, we do the following
    /// if height > -100
    ///     1: For each block in children
    ///             Find velocity, and raycast from it to the block.
    ///             if the block is hit (i.e. nothing was in the way)
    ///                 find the velocity in the axis perpendicular to the normal hit.
    ///                 calculate the drag of that velocity
    ///                 apply that force opposite the normal
    ///     2: For each block in thrusters
    ///             If fuel amount > 0
    ///                 add force to facing = fuelForce;
    ///                 fuel amount -= fuel burn
    ///    height = max(height, transform.position)
    /// else
    ///     set individuals height to our maxheight
    ///     kill this script
    /// </summary>
    public void FixedUpdate()
    {
        if (this.Equals(null))
        {
            return;
        }
        if (transform.position.y > -50)
        {
            foreach (GameObject body in children)
            {
                Vector3    v = me.GetRelativePointVelocity(body.transform.position);
                RaycastHit hit;
                ///if we hit something (pretty much impossible not to)
                if (Physics.Raycast(v * 30, -v, out hit))
                {
                    ///Calculating the force of drag on the collider
                    Vector3 norm  = hit.normal;
                    float   theta = Vector3.Angle(norm, v);
                    Vector3 dragV = v * (Mathf.Cos(theta));
                    dragV *= dragV.magnitude;
                    Vector3 oppForce = -dragV / 2;

                    ///Applying that force opposite to the normal
                    me.AddForceAtPosition(oppForce, body.transform.position);
                }
            }
            ///For each thruster, we add a force
            foreach (GameObject body in thruster)
            {
                if (fuelAmount > 0)
                {
                    PropelThruster(body);
                    fuelAmount -= fuelBurn;
                }
            }
            maxheight = Mathf.Max(transform.position.y, maxheight);
            if (this.Equals(null))
            {
                return;
            }
            if (myParent.Equals(null))
            {
                return;
            }
            myParent.timeInAir += 1;
        }
        ///If we're done, we signal to kill ourselves to the event handler
        else
        {
            if (this.Equals(null))
            {
                return;
            }
            if (myParent.Equals(null))
            {
                return;
            }
            myParent.maxHeight = maxheight;
            IndividualFunctions.ScoreIndividual(myParent);
            CustomEventHandler.SelfDestruct(this.gameObject);
        }
    }
Exemplo n.º 4
0
 /// <summary>
 /// We want to simulate each individual in this generation
 /// </summary>
 /// <param name="g"></param>
 public static void createNextGen()
 {
     IndividualFunctions.Simulate(toBeDone.Pop());
 }