@Test public void testFirstEmpty() { Collection<String> collection = new HashSet<String>(); assertTrue(Groups.first(collection) == null); collection.add("Hello World"); assertTrue(Groups.first(collection).equals("Hello World")); collection.add("Goodbye World"); assertTrue(collection.contains(Groups.first(collection))); }
public Action choose(LightsOut.Player actor, Set<Action> options) { if (presses == null) { presses = new HashSet<Location>(); // linear algebra solution boolean[][] state = actor.state(); boolean[] s = stateVector(state); boolean[][] M = stateMatrix(state[0].length, state.length); gauss(M, s); // translate to locations Location[][] locations = actor.locations(); for (int x = 0; x < s.length; x++) { if (s[x]) { presses.add(locations[x / state.length][x % state[0].length]); } } } Location next = Groups.first(presses); presses.remove(next); for (Action action : Groups.ofType(LightsOut.Move.class, options)) { if (((LightsOut.Move) action).target.location().equals(next)) { return action; } } return null; }