Skip to content

Instantly share code, notes, and snippets.

@aguimaraes
Created June 13, 2014 13:42
Show Gist options
  • Select an option

  • Save aguimaraes/334f7e97aba89fbb853e to your computer and use it in GitHub Desktop.

Select an option

Save aguimaraes/334f7e97aba89fbb853e to your computer and use it in GitHub Desktop.
Labyrinth.c
extern void object::Labyrinth()
{
object finish, barrier;
while (true) {
RideToClearSquare();
finish = LookForTheFinish();
if (finish != null) {
break;
}
}
}
extern object object::LookForTheFinish()
{
object front, left, right, barrier;
front = radar(GoalArea, 0, 45, 0, 5);
if (front != null) {
barrier = radar(Barrier, 0 ,45, 0, 5);
if (barrier == null) {
return front;
}
left = radar(GoalArea, 90, 45, 0, 5);
if (left != null) {
barrier = radar(Barrier, 0 ,45, 0, 5);
if (barrier == null ) {
return left;
}
}
right = radar(GoalArea, -90, 45, 0, 5);
if (right != null) {
barrier = radar(Barrier, 0 ,45, 0, 5);
if (barrier == null) {
return right;
}
}
return null;
}
}
extern bool object::RideToClearSquare()
{
object front, left, right;
front = radar(Barrier, 0, 45, 0, 5);
if (front == null) {
move(5);
return true;
}
left = radar(Barrier, 90, 45, 0, 5);
if (left == null) {
turn(90);
move(5);
return true;
}
right = radar(Barrier, -90, 45, 0, 5);
if (right == null) {
turn(-90);
move(5);
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment