@Test public void testCreateRiddle() { GameMatrix matrix = Creator.createFull(); Riddle riddle = Creator.createRiddle(matrix); for (int i=0; i < GameMatrixImpl.SIZE; i++) { for (int j=0; j < GameMatrixImpl.SIZE; j++) { if (riddle.get(i, j) != GameMatrixImpl.UNSET) { assertEquals(matrix.get(i, j), riddle.get(i, j)); assertFalse(riddle.getWritable(i, j)); } else { assertTrue(riddle.getWritable(i, j)); } } } Solver solver = new Solver(riddle); solver.setLimit(3); List<GameMatrix> results = solver.solve(); assertEquals(1, results.size()); }
public static Riddle createRiddle(final GameMatrix fullMatrix) { Random random = new Random(); RiddleImpl cur = new RiddleImpl(); cur.setAll(fullMatrix.getArray()); int multi = 0; while (multi < CREATE_RIDDLE_RANDOM_CLEAR) { int i = random.nextInt(GameMatrix.SIZE); int j = random.nextInt(GameMatrix.SIZE); if (cur.get(j, i) != GameMatrix.UNSET) { if (canClear(cur, j, i)) { cur.set(j, i, GameMatrix.UNSET); } else { multi++; } } } for (int i = 0; i < GameMatrix.SIZE; i++) { for (int j = 0; j < GameMatrix.SIZE; j++) { if (GameMatrix.UNSET != cur.get(j, i) && canClear(cur, j, i)) { cur.set(j, i, GameMatrix.UNSET); } } } for (int i = 0; i < GameMatrix.SIZE; i++) { for (int j = 0; j < GameMatrix.SIZE; j++) { cur.setWritable(j, i, cur.get(j, i) == GameMatrix.UNSET); } } return cur; }
Creator { public static Riddle createRiddle(final GameMatrix fullMatrix) { Random random = new Random(); RiddleImpl cur = new RiddleImpl(); cur.setAll(fullMatrix.getArray()); int multi = 0; while (multi < CREATE_RIDDLE_RANDOM_CLEAR) { int i = random.nextInt(GameMatrix.SIZE); int j = random.nextInt(GameMatrix.SIZE); if (cur.get(j, i) != GameMatrix.UNSET) { if (canClear(cur, j, i)) { cur.set(j, i, GameMatrix.UNSET); } else { multi++; } } } for (int i = 0; i < GameMatrix.SIZE; i++) { for (int j = 0; j < GameMatrix.SIZE; j++) { if (GameMatrix.UNSET != cur.get(j, i) && canClear(cur, j, i)) { cur.set(j, i, GameMatrix.UNSET); } } } for (int i = 0; i < GameMatrix.SIZE; i++) { for (int j = 0; j < GameMatrix.SIZE; j++) { cur.setWritable(j, i, cur.get(j, i) == GameMatrix.UNSET); } } return cur; } }
Creator { public static Riddle createRiddle(final GameMatrix fullMatrix) { Random random = new Random(); RiddleImpl cur = new RiddleImpl(); cur.setAll(fullMatrix.getArray()); int multi = 0; while (multi < CREATE_RIDDLE_RANDOM_CLEAR) { int i = random.nextInt(GameMatrix.SIZE); int j = random.nextInt(GameMatrix.SIZE); if (cur.get(j, i) != GameMatrix.UNSET) { if (canClear(cur, j, i)) { cur.set(j, i, GameMatrix.UNSET); } else { multi++; } } } for (int i = 0; i < GameMatrix.SIZE; i++) { for (int j = 0; j < GameMatrix.SIZE; j++) { if (GameMatrix.UNSET != cur.get(j, i) && canClear(cur, j, i)) { cur.set(j, i, GameMatrix.UNSET); } } } for (int i = 0; i < GameMatrix.SIZE; i++) { for (int j = 0; j < GameMatrix.SIZE; j++) { cur.setWritable(j, i, cur.get(j, i) == GameMatrix.UNSET); } } return cur; } private  Creator(); }
Creator { public static Riddle createRiddle(final GameMatrix fullMatrix) { Random random = new Random(); RiddleImpl cur = new RiddleImpl(); cur.setAll(fullMatrix.getArray()); int multi = 0; while (multi < CREATE_RIDDLE_RANDOM_CLEAR) { int i = random.nextInt(GameMatrix.SIZE); int j = random.nextInt(GameMatrix.SIZE); if (cur.get(j, i) != GameMatrix.UNSET) { if (canClear(cur, j, i)) { cur.set(j, i, GameMatrix.UNSET); } else { multi++; } } } for (int i = 0; i < GameMatrix.SIZE; i++) { for (int j = 0; j < GameMatrix.SIZE; j++) { if (GameMatrix.UNSET != cur.get(j, i) && canClear(cur, j, i)) { cur.set(j, i, GameMatrix.UNSET); } } } for (int i = 0; i < GameMatrix.SIZE; i++) { for (int j = 0; j < GameMatrix.SIZE; j++) { cur.setWritable(j, i, cur.get(j, i) == GameMatrix.UNSET); } } return cur; } private  Creator(); static GameMatrix createFull(); static GameMatrix createVariant(
            final GameMatrix fullyFilled); static Riddle createRiddle(final GameMatrix fullMatrix); }
Creator { public static Riddle createRiddle(final GameMatrix fullMatrix) { Random random = new Random(); RiddleImpl cur = new RiddleImpl(); cur.setAll(fullMatrix.getArray()); int multi = 0; while (multi < CREATE_RIDDLE_RANDOM_CLEAR) { int i = random.nextInt(GameMatrix.SIZE); int j = random.nextInt(GameMatrix.SIZE); if (cur.get(j, i) != GameMatrix.UNSET) { if (canClear(cur, j, i)) { cur.set(j, i, GameMatrix.UNSET); } else { multi++; } } } for (int i = 0; i < GameMatrix.SIZE; i++) { for (int j = 0; j < GameMatrix.SIZE; j++) { if (GameMatrix.UNSET != cur.get(j, i) && canClear(cur, j, i)) { cur.set(j, i, GameMatrix.UNSET); } } } for (int i = 0; i < GameMatrix.SIZE; i++) { for (int j = 0; j < GameMatrix.SIZE; j++) { cur.setWritable(j, i, cur.get(j, i) == GameMatrix.UNSET); } } return cur; } private  Creator(); static GameMatrix createFull(); static GameMatrix createVariant(
            final GameMatrix fullyFilled); static Riddle createRiddle(final GameMatrix fullMatrix);  }