-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f0e26b7
Showing
24 changed files
with
2,069 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
[0000|0000|0000|0000] | ||
[1000|0000|0000|0000] | ||
[1010|0000|0000|0000] | ||
[1010|0100|0000|0000] | ||
[1010|0101|0000|0000] | ||
[1010|0101|1000|0000] | ||
[1010|0101|1010|0000] | ||
[1010|0101|1010|0100] | ||
[1010|0101|1010|0101] | ||
[1010|0101|1000|0100] | ||
[1010|0101|1000|0101] | ||
[1010|0101|1000|0010] | ||
[1010|0101|1000|0001] | ||
[1010|0101|0010|0000] | ||
[1010|0101|0010|1000] | ||
[1010|0101|0010|1001] | ||
[1010|0101|0010|0100] | ||
[1010|0101|0010|0101] | ||
[1010|0101|0010|0001] | ||
[1010|0101|0000|1000] | ||
[1010|0101|0000|1010] | ||
[1010|0101|0000|1001] | ||
[1010|0101|0000|0100] | ||
[1010|0101|0000|0101] | ||
[1010|0101|0000|0010] | ||
[1010|0101|0000|0001] | ||
[1010|0100|1000|0000] | ||
[1010|0100|1010|0000] | ||
[1010|0100|1010|0001] | ||
[1010|0100|1001|0000] | ||
[1010|0100|1001|0010] | ||
[1010|0100|1000|0001] | ||
[1010|0100|0010|0000] | ||
[1010|0100|0010|1000] | ||
[1010|0100|0010|1001] | ||
[1010|0100|0010|0100] | ||
[1010|0100|0010|0101] | ||
[1010|0100|0010|0001] | ||
[1010|0100|0001|0000] | ||
[1010|0100|0001|1000] | ||
[1010|0100|0001|1010] | ||
[1010|0100|0001|0100] | ||
[1010|0100|0001|0010] | ||
[1010|0100|0000|1000] | ||
[1010|0100|0000|1010] | ||
[1010|0100|0000|1001] | ||
[1010|0100|0000|0100] | ||
[1010|0100|0000|0010] | ||
[1010|0001|0000|0000] | ||
[1010|0001|1000|0000] | ||
[1010|0001|1010|0000] | ||
[1010|0001|1010|0100] | ||
[1010|0001|1000|0100] | ||
[1010|0001|1000|0101] | ||
[1010|0001|1000|0010] | ||
[1010|0001|0100|0000] | ||
[1010|0001|0100|1000] | ||
[1010|0001|0100|1001] | ||
[1010|0001|0100|0010] | ||
[1010|0001|0100|0001] | ||
[1010|0001|0010|0000] | ||
[1010|0001|0010|1000] | ||
[1010|0001|0010|0100] | ||
[1010|0001|0000|0100] | ||
[1010|0001|0000|0101] | ||
[1010|0001|0000|0010] | ||
[1010|0001|0000|0001] | ||
[1010|0000|1000|0000] | ||
[1010|0000|1010|0000] | ||
[1010|0000|1010|0001] | ||
[1010|0000|1001|0000] | ||
[1010|0000|1001|0010] | ||
[1010|0000|1000|0001] | ||
[1010|0000|0100|0000] | ||
[1010|0000|0101|0000] | ||
[1010|0000|0101|1000] | ||
[1010|0000|0101|0010] | ||
[1010|0000|0100|1000] | ||
[1010|0000|0100|1001] | ||
[1010|0000|0100|0010] | ||
[1010|0000|0100|0001] | ||
[1010|0000|0010|0000] | ||
[1010|0000|0010|1000] | ||
[1010|0000|0010|1001] | ||
[1010|0000|0010|0100] | ||
[1010|0000|0010|0101] | ||
[1010|0000|0010|0001] | ||
[1010|0000|0001|0000] | ||
[1010|0000|0001|1000] | ||
[1010|0000|0001|1010] | ||
[1010|0000|0001|0100] | ||
[1010|0000|0001|0010] | ||
[1010|0000|0000|0100] | ||
[1010|0000|0000|0101] | ||
[1010|0000|0000|0010] | ||
[1000|0100|0000|0000] | ||
[1000|0100|0010|0000] | ||
[1000|0100|0010|0100] | ||
[1000|0100|0010|0001] | ||
[1000|0100|0001|0000] | ||
[1000|0100|0001|0100] | ||
[1000|0100|0001|0010] | ||
[1000|0100|0000|0100] | ||
[1000|0010|0000|0000] | ||
[1000|0010|0100|0000] | ||
[1000|0010|0101|0000] | ||
[1000|0010|0101|0010] | ||
[1000|0010|0100|0001] | ||
[1000|0010|0001|0000] | ||
[1000|0010|0001|0100] | ||
[1000|0010|0001|0010] | ||
[1000|0010|0000|0100] | ||
[1000|0010|0000|0010] | ||
[1000|0010|0000|0001] | ||
[1000|0000|0010|0000] | ||
[1000|0000|0010|1000] | ||
[1000|0000|0010|1001] | ||
[1000|0000|0010|0100] | ||
[1000|0000|0010|0101] | ||
[1000|0000|0010|0001] | ||
[1000|0000|0001|0000] | ||
[1000|0000|0001|1000] | ||
[1000|0000|0001|1010] | ||
[1000|0000|0001|0100] | ||
[1000|0000|0001|0010] | ||
[1000|0000|0000|1000] | ||
[1000|0000|0000|1010] | ||
[1000|0000|0000|1001] | ||
[1000|0000|0000|0100] | ||
[1000|0000|0000|0101] | ||
[1000|0000|0000|0001] | ||
[0000|0000|0010|0000] | ||
[0000|0000|0001|0000] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package chessboards; | ||
|
||
import chessboards.handler.EnumerationHandler; | ||
import chessboards.handler.StdOutEnumerationHandler; | ||
import group.Permutation; | ||
import group.SSPermutationGroup; | ||
|
||
public class AugmentingChessboardGenerator implements ChessboardGenerator { | ||
|
||
private EnumerationHandler handler; | ||
|
||
public AugmentingChessboardGenerator() { | ||
this(new StdOutEnumerationHandler()); | ||
} | ||
|
||
public AugmentingChessboardGenerator(EnumerationHandler handler) { | ||
this.handler = handler; | ||
} | ||
|
||
public void generate(int dim) { | ||
DiscreteChessboardPartitionRefiner refiner = new DiscreteChessboardPartitionRefiner(); | ||
Chessboard emptyBoard = new Chessboard(dim); | ||
SSPermutationGroup group = refiner.getAutomorphismGroup(emptyBoard); | ||
generate(dim, emptyBoard, group); | ||
} | ||
|
||
public void generate(int dim, Chessboard chessboard, SSPermutationGroup group) { | ||
if (isOk(chessboard, group)) { | ||
handler.handle(chessboard); | ||
int next = chessboard.getMaxColor() + 1; | ||
for (; next < dim * dim; next++) { | ||
if (chessboard.allowed(next)) { | ||
generate(dim, new Chessboard(dim, chessboard, next), group); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public boolean isOk(Chessboard chessboard, SSPermutationGroup group) { | ||
if (chessboard.numberOfColors() == 0) return true; | ||
String initial = chessboard.getColorString(); | ||
for (Permutation permutation : group.all()) { | ||
String permuted = chessboard.getPermutedColorString(permutation); | ||
if (initial.compareTo(permuted) > 0) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package chessboards; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import chessboards.handler.EnumerationHandler; | ||
import chessboards.handler.StdOutEnumerationHandler; | ||
|
||
public class BruteForceChessboardGenerator implements ChessboardGenerator { | ||
|
||
private EnumerationHandler handler; | ||
|
||
private List<Chessboard> generated; | ||
|
||
private int attempts = 0; | ||
|
||
public BruteForceChessboardGenerator() { | ||
this(new StdOutEnumerationHandler()); | ||
} | ||
|
||
public BruteForceChessboardGenerator(EnumerationHandler handler) { | ||
this.handler = handler; | ||
this.generated = new ArrayList<Chessboard>(); | ||
} | ||
|
||
public void generate(int dim) { | ||
for (int current = 0; current < dim * dim; current++) { | ||
generate(dim, new Chessboard(dim, current), current); | ||
} | ||
System.out.println(attempts + " attempts"); | ||
System.out.println(generated.size() + " generated"); | ||
} | ||
|
||
public void generate(int dim, Chessboard chessboard, int current) { | ||
// System.out.println("trying " + chessboard + " " + current); | ||
attempts++; | ||
for (Chessboard alreadySeen : generated) { | ||
if (isIsomorphic(chessboard, alreadySeen)) { | ||
return; | ||
} | ||
} | ||
generated.add(chessboard); | ||
handler.handle(chessboard); | ||
for (int next = current + 1; next < dim * dim; next++) { | ||
if (chessboard.allowed(next)) { | ||
generate(dim, new Chessboard(dim, chessboard, next), next); | ||
} | ||
} | ||
} | ||
|
||
public boolean isIsomorphic(Chessboard boardA, Chessboard boardB) { | ||
if (boardA.sameAs(boardB)) { | ||
return true; | ||
} | ||
if (boardB.flipHorizontal().sameAs(boardA)) { | ||
return true; | ||
} | ||
if (boardB.flipVertical().sameAs(boardA)) { | ||
return true; | ||
} | ||
Chessboard rotatedBoard; | ||
for (int r = 0; r < 3; r++) { | ||
rotatedBoard = boardB.rotateClockwise(); | ||
if (boardA.sameAs(rotatedBoard)) { | ||
return true; | ||
} | ||
if (rotatedBoard.flipHorizontal().sameAs(boardA)) { | ||
return true; | ||
} | ||
if (rotatedBoard.flipVertical().sameAs(boardA)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
} |
Oops, something went wrong.