@Test public void testCreateVariant() { GameMatrix original = Creator.createFull(); GameMatrix variant1 = Creator.createVariant(original); GameMatrix variant2 = Creator.createVariant(original); GameMatrix variant3 = Creator.createVariant(original); assertTrue(original.isValid()); assertEquals(9*9, original.getSetCount()); assertTrue(variant1.isValid()); assertEquals(9*9, variant1.getSetCount()); assertTrue(variant2.isValid()); assertEquals(9*9, variant2.getSetCount()); assertTrue(variant3.isValid()); assertEquals(9*9, variant3.getSetCount()); }
public static GameMatrix createVariant( final GameMatrix fullyFilled) { GameMatrix target = new GameMatrixImpl(); Random random = new Random(); byte[] substitution = createNumbersToDistribute(random, 1); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte original = fullyFilled.get(row, column); if (original == GameMatrix.UNSET) { throw new IllegalArgumentException( "There are unset fields in the given GameMatrix"); } byte substitute = substitution[original - 1]; target.set(row, column, substitute); } } for (int i = 0; i < GameMatrix.BLOCK_COUNT; i++) { boolean swap = random.nextBoolean(); if (swap) { int distance = 1 + random.nextInt(2); int offset = 0; if (distance != 2) { offset = random.nextInt(2); } swapRow(target, i * GameMatrix.BLOCK_SIZE + offset, i * GameMatrix.BLOCK_SIZE + offset + distance); } } for (int i = 0; i < GameMatrix.BLOCK_COUNT; i++) { boolean swap = random.nextBoolean(); if (swap) { int distance = 1 + random.nextInt(2); int offset = 0; if (distance != 2) { offset = random.nextInt(2); } swapColumn(target, i * GameMatrix.BLOCK_SIZE + offset, i * GameMatrix.BLOCK_SIZE + offset + distance); } } return target; }
Creator { public static GameMatrix createVariant( final GameMatrix fullyFilled) { GameMatrix target = new GameMatrixImpl(); Random random = new Random(); byte[] substitution = createNumbersToDistribute(random, 1); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte original = fullyFilled.get(row, column); if (original == GameMatrix.UNSET) { throw new IllegalArgumentException( "There are unset fields in the given GameMatrix"); } byte substitute = substitution[original - 1]; target.set(row, column, substitute); } } for (int i = 0; i < GameMatrix.BLOCK_COUNT; i++) { boolean swap = random.nextBoolean(); if (swap) { int distance = 1 + random.nextInt(2); int offset = 0; if (distance != 2) { offset = random.nextInt(2); } swapRow(target, i * GameMatrix.BLOCK_SIZE + offset, i * GameMatrix.BLOCK_SIZE + offset + distance); } } for (int i = 0; i < GameMatrix.BLOCK_COUNT; i++) { boolean swap = random.nextBoolean(); if (swap) { int distance = 1 + random.nextInt(2); int offset = 0; if (distance != 2) { offset = random.nextInt(2); } swapColumn(target, i * GameMatrix.BLOCK_SIZE + offset, i * GameMatrix.BLOCK_SIZE + offset + distance); } } return target; } }
Creator { public static GameMatrix createVariant( final GameMatrix fullyFilled) { GameMatrix target = new GameMatrixImpl(); Random random = new Random(); byte[] substitution = createNumbersToDistribute(random, 1); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte original = fullyFilled.get(row, column); if (original == GameMatrix.UNSET) { throw new IllegalArgumentException( "There are unset fields in the given GameMatrix"); } byte substitute = substitution[original - 1]; target.set(row, column, substitute); } } for (int i = 0; i < GameMatrix.BLOCK_COUNT; i++) { boolean swap = random.nextBoolean(); if (swap) { int distance = 1 + random.nextInt(2); int offset = 0; if (distance != 2) { offset = random.nextInt(2); } swapRow(target, i * GameMatrix.BLOCK_SIZE + offset, i * GameMatrix.BLOCK_SIZE + offset + distance); } } for (int i = 0; i < GameMatrix.BLOCK_COUNT; i++) { boolean swap = random.nextBoolean(); if (swap) { int distance = 1 + random.nextInt(2); int offset = 0; if (distance != 2) { offset = random.nextInt(2); } swapColumn(target, i * GameMatrix.BLOCK_SIZE + offset, i * GameMatrix.BLOCK_SIZE + offset + distance); } } return target; } private  Creator(); }
Creator { public static GameMatrix createVariant( final GameMatrix fullyFilled) { GameMatrix target = new GameMatrixImpl(); Random random = new Random(); byte[] substitution = createNumbersToDistribute(random, 1); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte original = fullyFilled.get(row, column); if (original == GameMatrix.UNSET) { throw new IllegalArgumentException( "There are unset fields in the given GameMatrix"); } byte substitute = substitution[original - 1]; target.set(row, column, substitute); } } for (int i = 0; i < GameMatrix.BLOCK_COUNT; i++) { boolean swap = random.nextBoolean(); if (swap) { int distance = 1 + random.nextInt(2); int offset = 0; if (distance != 2) { offset = random.nextInt(2); } swapRow(target, i * GameMatrix.BLOCK_SIZE + offset, i * GameMatrix.BLOCK_SIZE + offset + distance); } } for (int i = 0; i < GameMatrix.BLOCK_COUNT; i++) { boolean swap = random.nextBoolean(); if (swap) { int distance = 1 + random.nextInt(2); int offset = 0; if (distance != 2) { offset = random.nextInt(2); } swapColumn(target, i * GameMatrix.BLOCK_SIZE + offset, i * GameMatrix.BLOCK_SIZE + offset + distance); } } return target; } private  Creator(); static GameMatrix createFull(); static GameMatrix createVariant(
            final GameMatrix fullyFilled); static Riddle createRiddle(final GameMatrix fullMatrix); }
Creator { public static GameMatrix createVariant( final GameMatrix fullyFilled) { GameMatrix target = new GameMatrixImpl(); Random random = new Random(); byte[] substitution = createNumbersToDistribute(random, 1); for (int row = 0; row < GameMatrix.SIZE; row++) { for (int column = 0; column < GameMatrix.SIZE; column++) { byte original = fullyFilled.get(row, column); if (original == GameMatrix.UNSET) { throw new IllegalArgumentException( "There are unset fields in the given GameMatrix"); } byte substitute = substitution[original - 1]; target.set(row, column, substitute); } } for (int i = 0; i < GameMatrix.BLOCK_COUNT; i++) { boolean swap = random.nextBoolean(); if (swap) { int distance = 1 + random.nextInt(2); int offset = 0; if (distance != 2) { offset = random.nextInt(2); } swapRow(target, i * GameMatrix.BLOCK_SIZE + offset, i * GameMatrix.BLOCK_SIZE + offset + distance); } } for (int i = 0; i < GameMatrix.BLOCK_COUNT; i++) { boolean swap = random.nextBoolean(); if (swap) { int distance = 1 + random.nextInt(2); int offset = 0; if (distance != 2) { offset = random.nextInt(2); } swapColumn(target, i * GameMatrix.BLOCK_SIZE + offset, i * GameMatrix.BLOCK_SIZE + offset + distance); } } return target; } private  Creator(); static GameMatrix createFull(); static GameMatrix createVariant(
            final GameMatrix fullyFilled); static Riddle createRiddle(final GameMatrix fullMatrix);  }