Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Crée un tableau global qui associe une cellule à ses voisins (non nul et non obstacle)
- if (getTurn() == 1) {
- var x, y, newCell;
- var neighbors = [];
- var isNeighbor = function (aCell) {
- if (aCell == null) {
- return false;
- }
- if (isObstacle(aCell)) {
- return false;
- }
- return true;
- };
- for (var cell = 0; cell < 613; cell++) {
- if (!isObstacle(cell)) {
- neighbors = [];
- x = getCellX(cell);
- y = getCellY(cell);
- newCell = getCellFromXY(x - 1, y);
- if (isNeighbor(newCell)) push(neighbors, newCell);
- newCell = getCellFromXY(x + 1, y);
- if (isNeighbor(newCell)) push(neighbors, newCell);
- newCell = getCellFromXY(x, y - 1);
- if (isNeighbor(newCell)) push(neighbors, newCell);
- newCell = getCellFromXY(x, y + 1);
- if (isNeighbor(newCell)) push(neighbors, newCell);
- neighborsCells[cell] = neighbors;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement