Skip to content

Instantly share code, notes, and snippets.

@Jorger
Created September 16, 2018 21:56
Show Gist options
  • Save Jorger/433ebd90f8820d0c44ec01b690189b32 to your computer and use it in GitHub Desktop.
Save Jorger/433ebd90f8820d0c44ec01b690189b32 to your computer and use it in GitHub Desktop.
const getNeighbour = (pipesInposition, directionPipe) => {
let indexNextPipe = -1;
const posibleDirections = [
[[2], [2], [1, 2, 3], [1, 2], [0, 2]],
[[3], [3], [0, 2, 3], [2, 3], [1, 3]],
[[0], [0], [0, 1, 3], [0, 3], [0, 2]],
[[1], [1], [0, 1, 2], [0, 1], [1, 3]]
][directionPipe];
if (pipesInposition.length !== 0) {
for (let indexPipe of pipesInposition) {
//Buscar si existe un posible conector...
const conectorExpected = posibleDirections[
actualWorld[1][indexPipe][2] - 1
].indexOf(actualWorld[1][indexPipe][3]);
if (conectorExpected >= 0) {
indexNextPipe = indexPipe;
break;
}
}
}
return indexNextPipe;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment