// PROGRAM ID: hurdles.cc / The Hurdles Race Task // INSTALLATION: MTSU // REMARKS: Karel runs a mile (=8 blocks) long hurdles race. #include using namespace std; // Function prototypes: void AdvanceACorner(); void JumpHurdle(); void JumpUp(); void JumpDown(); void TurnRight(); int main() { TurnOn(); AdvanceACorner(); AdvanceACorner(); AdvanceACorner(); AdvanceACorner(); AdvanceACorner(); AdvanceACorner(); AdvanceACorner(); AdvanceACorner(); TurnOff(); } // Karel advances to the next corner. void AdvanceACorner() { if (frontIsClear) Move(); else JumpHurdle(); } // Karel jumps over the hurdle. void JumpHurdle() { JumpUp(); Move(); JumpDown(); } // Karel rises to just above the height of the barrier. void JumpUp() { TurnLeft(); Move(); TurnRight(); } // Karel returns to street level 1. void JumpDown() { TurnRight(); Move(); TurnLeft(); } // Pivot Karel 90 degrees to right. void TurnRight() { TurnLeft(); TurnLeft(); TurnLeft(); }