Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int obstaclesCounter = 0;
- int i;
- int j;
- putLeaf();
- int length = countLength();
- turnRight();
- int width = countWidth();
- removeLeaf();
- turnLeft();
- for (j = 0; j < width; j++) {
- for (i = 0; i < (length - 1); i++) {
- if (!mushroomFront() && !treeFront()) {
- move();
- }
- else {
- obstaclesCounter++;
- goAround();
- i++;
- }
- }
- if (i < length) {
- goDownBack();
- }
- else {
- goDownFront();
- }
- }
- showMessage("# Hindernisse: %d", obstaclesCounter);
- }
- int countLength() {
- int i = 0;
- if (treeFront() || mushroomFront()) {
- goAround();
- i = i + 2;
- }
- else {
- move();
- i++;
- }
- while (!onLeaf()) {
- if (treeFront() || mushroomFront()) {
- goAround();
- i = i + 2;
- }
- else {
- move();
- i++;
- }
- }
- return i;
- }
- int countWidth() {
- int j = 0;
- if (treeFront() || mushroomFront()) {
- goAround();
- j = j + 2;
- }
- else {
- move();
- j++;
- }
- while (!onLeaf()) {
- if (treeFront() || mushroomFront()) {
- goAround();
- j = j + 2;
- }
- else {
- move();
- j++;
- }
- }
- return j;
- }
- void goAround() {
- turnRight();
- move();
- turnLeft();
- move();
- move();
- turnLeft();
- move();
- turnRight();
- }
- void goDownBack() {
- if (!(treeFront() && mushroomFront())) {
- move();
- turnRight();
- if (!(treeFront() || mushroomFront())) {
- move();
- turnLeft();
- }
- else {
- turnLeft();
- move();
- turnRight();
- move();
- turnLeft();
- }
- }
- else {
- turnRight();
- move();
- turnLeft();
- move();
- }
- }
- void goDownFront() {
- turnRight();
- move();
- turnLeft();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement