1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sourceforge.domian.test.benchmark;
17
18
19 import static org.apache.commons.lang.math.RandomUtils.nextInt;
20
21 import net.sourceforge.domian.repository.Repository;
22 import static net.sourceforge.domian.test.benchmark.QueenPuzzleUtils.conditionalLogging;
23 import net.sourceforge.domian.util.StopWatch;
24
25
26 class RandomSequenceQueenPuzzleConstellationFactory {
27
28 final long maximumNumberOfConstellationToProduce;
29 final long logInterval;
30
31 RandomSequenceQueenPuzzleConstellationFactory(final Long maximumNumberOfConstellationToProduce,
32 final Long logInterval) {
33 this.maximumNumberOfConstellationToProduce = maximumNumberOfConstellationToProduce;
34 this.logInterval = logInterval;
35 }
36
37
38 protected boolean constellationConstraintOk(final int[] queenPlacingNumbers, final int index, final int number) {
39 return true;
40 }
41
42 void generateAndPopulate(final Repository repo) {
43 long constellationNumber;
44 QueenPuzzleConstellation queenPuzzleConstellation;
45
46 StopWatch stopWatch = new StopWatch().start();
47 for (constellationNumber = 1; constellationNumber < maximumNumberOfConstellationToProduce; ++constellationNumber) {
48 final int[] constellation = new int[8];
49 int index = 0;
50 while (index < 8) {
51 int number = nextInt(64);
52 while (!constellationConstraintOk(constellation, index, number)) {
53 number = nextInt(64);
54 }
55 constellation[index] = number;
56 ++index;
57 }
58 queenPuzzleConstellation = new QueenPuzzleConstellation(new ChessPiecePlacing(constellation[0]),
59 new ChessPiecePlacing(constellation[1]),
60 new ChessPiecePlacing(constellation[2]),
61 new ChessPiecePlacing(constellation[3]),
62 new ChessPiecePlacing(constellation[4]),
63 new ChessPiecePlacing(constellation[5]),
64 new ChessPiecePlacing(constellation[6]),
65 new ChessPiecePlacing(constellation[7]));
66 repo.put(queenPuzzleConstellation);
67 conditionalLogging(logInterval, constellationNumber, stopWatch, queenPuzzleConstellation, "generated and added to repo so far...");
68 }
69 }
70 }