Created
June 13, 2014 13:42
-
-
Save aguimaraes/334f7e97aba89fbb853e to your computer and use it in GitHub Desktop.
Labyrinth.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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