RotationSolver { static boolean solve(RaidRoom[] rooms) { if (rooms == null) { return false; } List<RaidRoom> match = null; Integer start = null; Integer index = null; int known = 0; for (int i = 0; i < rooms.length; i++) { if (rooms[i] == null || rooms[i].getType() != RoomType.COMBAT || rooms[i] == UNKNOWN_COMBAT) { continue; } if (start == null) { start = i; } known++; } if (known < 2) { return false; } if (known == rooms.length) { return true; } for (List rotation : ROTATIONS) { COMPARE: for (int i = 0; i < rotation.size(); i++) { if (rooms[start] == rotation.get(i)) { for (int j = start + 1; j < rooms.length; j++) { if (rooms[j].getType() != RoomType.COMBAT || rooms[j] == UNKNOWN_COMBAT) { continue; } if (rooms[j] != rotation.get(floorMod(i + j - start, rotation.size()))) { break COMPARE; } } if (match != null && match != rotation) { return false; } index = i - start; match = rotation; } } } if (match == null) { return false; } for (int i = 0; i < rooms.length; i++) { if (rooms[i] == null) { continue; } if (rooms[i].getType() != RoomType.COMBAT || rooms[i] == UNKNOWN_COMBAT) { rooms[i] = match.get(floorMod(index + i, match.size())); } } return true; }    }
@Test public void testSolve1() { RaidRoom[] rooms = new RaidRoom[]{VESPULA, UNKNOWN_COMBAT, UNKNOWN_COMBAT, VANGUARDS}; RotationSolver.solve(rooms); assertArrayEquals(new RaidRoom[]{VESPULA, SHAMANS, VASA, VANGUARDS}, rooms); }
@Test public void testSolve2() { RaidRoom[] rooms = new RaidRoom[]{UNKNOWN_COMBAT, UNKNOWN_COMBAT, MUTTADILES, TEKTON}; RotationSolver.solve(rooms); assertArrayEquals(new RaidRoom[]{VESPULA, GUARDIANS, MUTTADILES, TEKTON}, rooms); }
@Test public void testSolve3() { RaidRoom[] rooms = new RaidRoom[]{TEKTON, UNKNOWN_COMBAT, GUARDIANS, MYSTICS}; RotationSolver.solve(rooms); assertArrayEquals(new RaidRoom[]{TEKTON, VASA, GUARDIANS, MYSTICS}, rooms); }
@Test public void testSolve4() { RaidRoom[] rooms = new RaidRoom[]{VASA, UNKNOWN_COMBAT, UNKNOWN_COMBAT, GUARDIANS}; RotationSolver.solve(rooms); assertArrayEquals(new RaidRoom[]{VASA, SHAMANS, VESPULA, GUARDIANS}, rooms); }
@Test public void testSolve5() { RaidRoom[] rooms = new RaidRoom[]{GUARDIANS, UNKNOWN_COMBAT, SHAMANS, VASA}; RotationSolver.solve(rooms); assertArrayEquals(new RaidRoom[]{GUARDIANS, VESPULA, SHAMANS, VASA}, rooms); }
@Test public void testSolve6() { RaidRoom[] rooms = new RaidRoom[]{UNKNOWN_COMBAT, UNKNOWN_COMBAT, TEKTON, MUTTADILES}; RotationSolver.solve(rooms); assertArrayEquals(new RaidRoom[]{VANGUARDS, MYSTICS, TEKTON, MUTTADILES}, rooms); }