Esempio n. 1
0
  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;
  }
Esempio n. 2
0
  @Test
  public void testOfType() {
    Collection<A> collection = new HashSet<A>();
    collection.add(new A());
    collection.add(new B());
    collection.add(new B());
    collection.add(new A());
    collection.add(new B());
    collection.add(new A());
    collection.add(new A());
    collection.add(new C());

    assertTrue(Groups.ofType(A.class, collection).size() == 8);
    assertTrue(Groups.ofType(B.class, collection).size() == 3);
    assertTrue(Groups.ofType(C.class, collection).size() == 1);
  }