示例#1
0
    /// <summary>
    /// Helper method which performs the setup of balls using chromosome data from the genetic algorithm.
    /// </summary>
    private void SetupBallsUsingChromosomeData()
    {
        // Setup each ball with chromosome data
        for (int ballIndex = 0; ballIndex < PopulationSize; ballIndex++)
        {
            Chromosome aChromosome = BasketballGA.GetChromosomeAtIndex(ballIndex);
            SpawnerForPlayer.ApplyForceToSpecificBall(aChromosome.UpwardForce, aChromosome.ForwardForce, ballIndex);
        }

        // Update UI
        GenerationNumber++;
        TriggerUIEvent(UIEventKeys.KEY_GENERATIONNUMBER, GenerationNumber);
    }
示例#2
0
    public IEnumerator ApplyForcesToBallTest()
    {
        // Spawn player and balls
        PlayerSpawnerComponent.SpawnPlayer();
        yield return(new WaitForSeconds(0.1f));

        PlayerSpawnerComponent.SpawnBalls(10, PlayerSpawnerComponent.transform);

        // Get last ball, reference initial position
        BallController aBallController;

        PlayerSpawnerComponent.TryGetBallAtSpecificIndex(9, out aBallController);
        float initialYPosition = aBallController.transform.position.y;

        // Apply force to last ball
        PlayerSpawnerComponent.ApplyForceToSpecificBall(30f, 30f, 9);
        yield return(new WaitForSeconds(0.1f));

        // Assert status based on if ball moved
        Assert.AreNotEqual(initialYPosition, aBallController.transform.position.y);

        // Garbage collection
        PlayerSpawnerComponent.DestroySpawnedPlayer();
    }