Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for (let i = 0; i < queue.length; i++) {
- const neighbors = new Array();
- const cur_x = queue[i].x;
- const cur_y = queue[i].y;
- if (is_location_valid(cur_x + 1, cur_y))
- neighbors.push(map[cur_x + 1][cur_y]);
- if (is_location_valid(cur_x - 1, cur_y))
- neighbors.push(map[cur_x - 1][cur_y]);
- if (is_location_valid(cur_x, cur_y + 1))
- neighbors.push(map[cur_x][cur_y + 1]);
- if (is_location_valid(cur_x, cur_y - 1))
- neighbors.push(map[cur_x][cur_y - 1]);
- for (let j = 0; j < neighbors.length; j++) {
- const tile = neighbors[j];
- if (!tile.blocked && tile.actual_cost == Number.MAX_VALUE) {
- tile.actual_cost = queue[i].actual_cost + 1;
- queue.push(tile);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement