function CheckWay(y, x, y1, x1, from, to, PipeType) { if (x1 < 0 || y1 < 0 || x1 >= size || y1 >= size) { return; } if (exits[pipes[y][x]][from] === exits[pipes[y1][x1]][to] && !used[y1][x1]) { queue.push([y1, x1]); } } function CheckLeftWay1(y, x, PipeType) { CheckWay(y, x, y, x - 1, left, right); }