public bool randomSolve(CellGenerator cell) { cell.setVisited(); if (cell.isDeadEnd() && error == 0 && cell != start) { endX = cell.getX(); endY = cell.getY(); return(true); } if (cell.isDeadEnd() && error == 0 && cell == start) { return(false); } if (cell.isDeadEnd() && cell != start) { error -= 1; } List <int> possible = getPossibleWay(cell); while (possible.Count > 0) { int direction = possible[rd.Next(possible.Count)]; if (randomSolve(move(cell, direction))) { return(true); } } return(false); }
public bool inOrder(CellGenerator cell) { cell.setVisited(); if (cell.isDeadEnd() && error == 0 && cell != start) { endX = cell.getX(); endY = cell.getY(); return(true); } if (cell.isDeadEnd() && error == 0 && cell == start) { return(false); } if (cell.isDeadEnd() && cell != start) { error -= 1; return(false); } if (cell.getX() > 0 && !getCell(cell.getX() - 1, cell.getY()).isVisited() && !cell.getNorth() && inOrder(getCell(cell.getX() - 1, cell.getY()))) { return(true); } if (cell.getY() < width && !getCell(cell.getX(), cell.getY() + 1).isVisited() && !cell.getEast() && inOrder(getCell(cell.getX(), cell.getY() + 1))) { return(true); } if (cell.getY() > 0 && !getCell(cell.getX(), cell.getY() - 1).isVisited() && !cell.getWest() && inOrder(getCell(cell.getX(), cell.getY() - 1))) { return(true); } if (cell.getX() < lenght && !getCell(cell.getX() + 1, cell.getY()).isVisited() && !cell.getSouth() && inOrder(getCell(cell.getX() + 1, cell.getY()))) { return(true); } return(false); }
public bool rightHand(CellGenerator cell, int facing) { cell.setVisited(); if (cell.isDeadEnd() && error == 0 && cell != start) { endX = cell.getX(); endY = cell.getY(); return(true); } if (cell.isDeadEnd() && error == 0 && cell == start) { return(false); } if (cell.isDeadEnd() && cell != start) { error -= 1; } if (move(cell, (facing + 1) % 4) != cell && !move(cell, (facing + 1) % 4).isVisited() && rightHand(move(cell, (facing + 1) % 4), (facing + 1) % 4)) { return(true); } if (move(cell, facing) != cell && !move(cell, facing).isVisited() && rightHand(move(cell, facing), facing)) { return(true); } if (move(cell, (facing + 3) % 4) != cell && !move(cell, (facing + 3) % 4).isVisited() && rightHand(move(cell, (facing + 3) % 4), (facing + 3) % 4)) { return(true); } if (move(cell, (facing + 2) % 4) != cell && !move(cell, (facing + 2) % 4).isVisited() && rightHand(move(cell, (facing + 2) % 4), (facing + 2) % 4)) { return(true); } return(false); }
public bool shorterDistance(CellGenerator cell) { int direction = 0; CellGenerator position = cell; position.setVisited(); while (true) { directionStraight[0] = (position.getNorth() || getCell(position.getX() - 1, position.getY()).isVisited()) ? 0 : GetStraightLenghtInDirection(position, 0); directionStraight[1] = (position.getEast() || getCell(position.getX(), position.getY() + 1).isVisited()) ? 0 : GetStraightLenghtInDirection(position, 1); directionStraight[2] = (position.getSouth() || getCell(position.getX() + 1, position.getY()).isVisited()) ? 0 : GetStraightLenghtInDirection(position, 2); directionStraight[3] = (position.getWest() || getCell(position.getX(), position.getY() - 1).isVisited()) ? 0 : GetStraightLenghtInDirection(position, 3); if (directionStraight[3] > 0 && (directionStraight[3] <= directionStraight[1] || directionStraight[1] == 0) && (directionStraight[3] <= directionStraight[2] || directionStraight[2] == 0) && (directionStraight[3] <= directionStraight[0] || directionStraight[0] == 0)) { direction = 3; Debug.Log(direction + " " + directionStraight[0]); position = MoveInDirection(position, direction); } else if (directionStraight[2] > 0 && (directionStraight[2] <= directionStraight[1] || directionStraight[1] == 0) && (directionStraight[2] <= directionStraight[0] || directionStraight[0] == 0)) { direction = 2; Debug.Log(direction + " " + directionStraight[1]); position = MoveInDirection(position, direction); } else if (directionStraight[1] > 0 && (directionStraight[1] <= directionStraight[0] || directionStraight[0] == 0)) { direction = 1; Debug.Log(direction + " " + directionStraight[2]); position = MoveInDirection(position, direction); } else if (directionStraight[0] > 0) { direction = 0; Debug.Log(direction + " " + directionStraight[3]); position = MoveInDirection(position, direction); } else { lastVisitedIntersection.Remove(position); if (lastVisitedIntersection.Count > 0) { position = lastVisitedIntersection[lastVisitedIntersection.Count - 1]; } } if (position.isDeadEnd() && error == 0 && position != start) { endX = position.getX(); endY = position.getY(); return(true); } if (position.isDeadEnd() && error == 0 && position == start) { return(false); } if (position.isDeadEnd() && position != start) { error -= 1; if (lastVisitedIntersection.Count > 0) { position = lastVisitedIntersection[lastVisitedIntersection.Count - 1]; } } } }