Guest User

Easy Bot

a guest
Apr 30th, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. let dir = [[1, 0], [-1, 0], [0, 1], [0, -1]];
  2. let myColor = -1;
  3.  
  4. fn pos_ok(x, y) {
  5. return x >= 0 && x < 50 && y >= 0 && y < 50;
  6. }
  7.  
  8. fn move_to(w, x, y) {
  9. if (worker(w).x > x) { worker(w).move_left(); }
  10. else if (worker(w).x < x) { worker(w).move_right(); }
  11. else if (worker(w).y > y) { worker(w).move_down(); }
  12. else if (worker(w).y < y) { worker(w).move_up(); }
  13. }
  14.  
  15. for w in 0..8 {
  16. let pos = [worker(w).x, worker(w).y];
  17. if (myColor == -1) { myColor = map[pos[0]][pos[1]]; }
  18. for move in dir {
  19. info(`move ${move}`);
  20. let x1 = pos[0] + move[0];
  21. let y1 = pos[1] + move[1];
  22. if (pos_ok(x1, y1) && map[x1][y1] != myColor) {
  23. move_to(w, x1, y1);
  24. }
  25. }
  26.  
  27. info(`worker ${w} finished with x = ${worker(w).x} and y = ${worker(w).y}.`);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment