private boolean isNotSeparatorRoom(Room separatorRoom, Room joinerRoom) { if (separatorRoom == null) return false; if (separatorRoom.isRotatable() && separatorRoom != joinerRoom) { separatorRoom.rotateRightRotatedType(); rotationMap.put( separatorRoom.getDistance() - Math.abs(separatorRoom.getRotation()), separatorRoom); return false; } if (separatorRoom.isRotatable() && separatorRoom == joinerRoom && separatorRoom.getExit() != null) { if (separatorRoom.getRotatedType() == RoomType.TYPE_7) { separatorRoom.rotateRightRotatedType(); } else if (separatorRoom.getRotatedType() == RoomType.TYPE_8 && separatorRoom.getEntrance() == Direction.LEFT) { separatorRoom.rotateLeftRotatedType(); } else if (separatorRoom.getRotatedType() == RoomType.TYPE_8 && separatorRoom.getEntrance() == Direction.RIGHT) { separatorRoom.rotateRightRotatedType(); } else if (separatorRoom.getRotatedType() == RoomType.TYPE_9 && separatorRoom.getEntrance() == Direction.TOP) { separatorRoom.rotateLeftRotatedType(); } else if (separatorRoom.getRotatedType() == RoomType.TYPE_9 && separatorRoom.getEntrance() == Direction.LEFT) { separatorRoom.rotateRightRotatedType(); } rotationMap.put( separatorRoom.getDistance() - Math.abs(separatorRoom.getRotation()), separatorRoom); return false; } return true; }
public void findPathFromStartToEnd(Position startPosition) { System.err.println("move " + getRoom(startPosition).getPosition()); Room actRoom = getRoom(startPosition).getNextRoom(); actRoom.setDistance(1); System.err.println("move " + actRoom.getPosition()); while (actRoom != getRoom(endPosition)) { Room nextRoom = actRoom.getNextRoom(); if (nextRoom == null || nextRoom.isBlocker()) { actRoom.setDistance(0); actRoom = actRoom.getPrev(); } else { nextRoom.setDistance(actRoom.getDistance() + 1); actRoom = nextRoom; } System.err.println("move " + actRoom.getPosition()); } actRoom = getRoom(startPosition).getNext(); while (actRoom != getRoom(endPosition) && actRoom.getRotation() == 0) { actRoom = actRoom.getNext(); } if (actRoom.isRotatable() && actRoom.getRotation() != 0) { rotationMap.put(actRoom.getDistance() - Math.abs(actRoom.getRotation()), actRoom); } }