Skip to content

Instantly share code, notes, and snippets.

@cipher982
Created February 16, 2018 00:44
Show Gist options
  • Save cipher982/72b7930427f3b2484f5199806e38fa8e to your computer and use it in GitHub Desktop.
Save cipher982/72b7930427f3b2484f5199806e38fa8e to your computer and use it in GitHub Desktop.
if (car_ahead)
{
cout << "Car Ahead!!!\n\n\n\n\n\n"
<< endl;
if (!car_left && lane > 0) // no left-car, yes left-lane
{
lane--; // Change lane left
}
else if (!car_right && lane != 2) // no right-car, yes right-lane
{
lane++; // Change lane right
}
else
{
speed_diff -= max_acl; // else slow down
}
}
else
{
if (lane != 1) // not in center lane
{
if ((lane == 0 && !car_right) || (lane == 2 && !car_left)) // left-right is clear
{
lane = 1; // Back to center.
}
}
if (ref_vel < max_vel)
{
speed_diff += max_acl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment