Back
Close

Basic simulation and evaluation

MadKnight
17K views

Full turn simulation

To simulate a turn, you need to resolve all collisions for the current turn:

void Play(Pod[] pods)
{
    float timeLeft = 1;
    while (timeLeft > 0)
    {
        if (TryFindCollision(out var collision, timeLeft))
        {
            ResolveCollision(collision);
            MovePods(pods, collision.time);
            timeLeft -= collision.time;
        }
        else 
        {
            MovePods(pods, timeLeft);
            break;
        }
    }
    FinishTurn(pods);
}
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io