Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gilleain committed Aug 4, 2011
0 parents commit f0e26b7
Show file tree
Hide file tree
Showing 24 changed files with 2,069 additions and 0 deletions.
Binary file added five_five.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
909 changes: 909 additions & 0 deletions five_five.txt

Large diffs are not rendered by default.

Binary file added four_four.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
133 changes: 133 additions & 0 deletions four_four.txt
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]
Binary file added imgA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions src/chessboards/AugmentingChessboardGenerator.java
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;
}

}
77 changes: 77 additions & 0 deletions src/chessboards/BruteForceChessboardGenerator.java
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;
}

}
Loading

0 comments on commit f0e26b7

Please sign in to comment.