示例#1
0
    private const float PARALLEL_POSITION_OFFSET = 25;   // how far off from the origin are these people swinging


    // Called when the user clicks the "Begin Simulation" button
    // Processes the input
    public void BeginComplexSimulation()
    {
        // Get numbers from the input fields
        try
        {
            numAgents     = int.Parse(numAgentsInput.text);
            holeDist      = float.Parse(holeDistInput.text);
            holeDistRand  = float.Parse(holeDistRandInput.text);
            timePerGen    = float.Parse(timePerGenInput.text);
            crossoverProb = float.Parse(crossoverProbInput.text);
            mutationProb  = float.Parse(mutationProbInput.text);
            numGens       = int.Parse(numGensInput.text);
            numElites     = int.Parse(elitismInput.text);
            if (mutationProb < 0 || mutationProb > 1 || crossoverProb < 0 || crossoverProb > 1)
            {
                Debug.LogWarning("Crossover and mutation values should be between 0 and 1!");
                return;
            }
            if (numAgents < 0 || holeDist < 0 || holeDistRand < 0 || timePerGen < 0 || numGens < 0)
            {
                Debug.LogWarning("None of these numbers should be negative!");
                return;
            }
        }
        catch
        {
            Debug.LogWarning("Only numbers are allowed in the input fields!");
            return;
        }
        // Get the values from the dropdown options
        fitnessFunc    = (GolferSettings.Fitness)fitnessDropdown.value;
        moveableJoints = (GolferSettings.MoveableJointsExtent)jointsDropdown.value;
        clubGrip       = (GolferSettings.ClubGrip)gripDropdown.value;

        // Create the GolferSettings object
        settings = new GolferSettings(fitnessFunc, moveableJoints, clubGrip, holeDist);

        // hide the main menu UI
        menuUIParent.SetActive(false);
        // display the simulation UI
        simulationUI.SetActive(true);
        // Begin the simulation coroutine
        StartCoroutine(Simulate());
    }
示例#2
0
    // This should be called right after the golfer is instantiated
    public void InitializeAgent(Chromosome2 newChrom, GolferSettings newSettings, float holeDistOffset = 0)
    {
        chrom       = newChrom;
        jointsInUse = new Rigidbody[chrom.jointMovements.Length];
        settings    = newSettings;
        // hide the golf hole if we don't need it
        if (settings.fitnessFunc == GolferSettings.Fitness.drivingDist)
        {
            hole.gameObject.SetActive(false);
        }
        else
        {   // position the hole based on the distance it's supposed to be from the golfer, maintaining the y-coordinate
            hole.position  = transform.position - Vector3.right * (settings.holeDist + holeDistOffset) + new Vector3(0, hole.position.y, 0);
            actualHoleDist = Vector3.Distance(transform.position, hole.position);
        }

        // Destroy the joint connecting the club to the second hand if we're going one-handed
        if (settings.clubGrip == GolferSettings.ClubGrip.oneHand)
        {
            Destroy(secondHandJoint);
        }
    }