You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
913 B

  1. function robotOnGrid() {
  2. // robot starts in the lower left corner
  3. int robotX := 1; int robotY := 20;
  4. // janitor starts in the grid middle
  5. int janitorX := ceil(20 / 2); int janitorY := ceil(20 / 2);
  6. // iterates as long as the robot is not in the upper right corner
  7. while(!(robotX = 20 & robotY = 1)) {
  8. // robot perfoms one step at max each iteration
  9. // checks whether we can go to the right and the janitor is not there
  10. if(robotX < 20 & !((janitorX = robotX + 1) & (janitorY = robotY))) {
  11. robotX := robotX + 1;
  12. }
  13. // checks whether we can go up and the janitor is not there
  14. if(robotX = 20 & !((janitorX = robotX) & (janitorY = robotY - 1))) {
  15. robotY := robotY - 1;
  16. }
  17. // moves the janitor randomly in one direction, not limited by any borders
  18. {janitorX := janitorX + 1;}[0.25]{{janitorX := janitorX - 1;}[1/3]{{janitorY := janitorY + 1;}[0.375]{janitorY := janitorY - 1;}}}
  19. }
  20. }