Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let dir = [[1, 0], [-1, 0], [0, 1], [0, -1]];
- let myColor = -1;
- fn pos_ok(x, y) {
- return x >= 0 && x < 50 && y >= 0 && y < 50;
- }
- fn move_to(w, x, y) {
- if (worker(w).x > x) { worker(w).move_left(); }
- else if (worker(w).x < x) { worker(w).move_right(); }
- else if (worker(w).y > y) { worker(w).move_down(); }
- else if (worker(w).y < y) { worker(w).move_up(); }
- }
- for w in 0..8 {
- let pos = [worker(w).x, worker(w).y];
- if (myColor == -1) { myColor = map[pos[0]][pos[1]]; }
- for move in dir {
- info(`move ${move}`);
- let x1 = pos[0] + move[0];
- let y1 = pos[1] + move[1];
- if (pos_ok(x1, y1) && map[x1][y1] != myColor) {
- move_to(w, x1, y1);
- }
- }
- info(`worker ${w} finished with x = ${worker(w).x} and y = ${worker(w).y}.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment