Skip to content

Commit

Permalink
+Pencilmark-only functionalities by 1to9only
Browse files Browse the repository at this point in the history
  • Loading branch information
dobrichev committed Aug 10, 2019
1 parent a2ca96c commit 251aedb
Show file tree
Hide file tree
Showing 5 changed files with 549 additions and 39 deletions.
54 changes: 27 additions & 27 deletions Make-Jar.jardesc
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<jardesc>
<jar path="Sudoku/SudokuExplainer.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/Sudoku/Make-Jar.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>
<manifest generateManifest="true" mainClassHandleIdentifier="=Sudoku/&lt;diuf.sudoku.gui{SudokuExplainer.java[SudokuExplainer" manifestLocation="" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
<sealing sealJar="false">
<packagesToSeal/>
<packagesToUnSeal/>
</sealing>
</manifest>
<selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
<javaElement handleIdentifier="=Sudoku/&lt;diuf.sudoku.test"/>
<javaElement handleIdentifier="=Sudoku/&lt;diuf.sudoku.solver"/>
<javaElement handleIdentifier="=Sudoku/&lt;diuf.sudoku.generator"/>
<javaElement handleIdentifier="=Sudoku/&lt;diuf.sudoku.solver.rules"/>
<javaElement handleIdentifier="=Sudoku/&lt;diuf.sudoku.tools"/>
<javaElement handleIdentifier="=Sudoku/&lt;diuf.sudoku.solver.rules.chaining"/>
<javaElement handleIdentifier="=Sudoku/&lt;diuf.sudoku"/>
<javaElement handleIdentifier="=Sudoku/&lt;diuf.sudoku.io"/>
<javaElement handleIdentifier="=Sudoku/&lt;diuf.sudoku.solver.checks"/>
<javaElement handleIdentifier="=Sudoku/&lt;diuf.sudoku.solver.rules.unique"/>
<javaElement handleIdentifier="=Sudoku/&lt;diuf.sudoku.applet"/>
<javaElement handleIdentifier="=Sudoku/&lt;diuf.sudoku.gui"/>
</selectedElements>
</jardesc>
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<jardesc>
<jar path="SukakuExplainer/SukakuExplainer.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/SukakuExplainer/Make-Jar.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/>
<manifest generateManifest="true" mainClassHandleIdentifier="=SukakuExplainer/&lt;diuf.sudoku.gui{SudokuExplainer.java[SudokuExplainer" manifestLocation="" manifestVersion="1.0" reuseManifest="false" saveManifest="false" usesManifest="true">
<sealing sealJar="false">
<packagesToSeal/>
<packagesToUnSeal/>
</sealing>
</manifest>
<selectedElements exportClassFiles="true" exportJavaFiles="false" exportOutputFolder="false">
<javaElement handleIdentifier="=SukakuExplainer/&lt;diuf.sudoku.solver"/>
<javaElement handleIdentifier="=SukakuExplainer/&lt;diuf.sudoku"/>
<javaElement handleIdentifier="=SukakuExplainer/&lt;diuf.sudoku.generator"/>
<javaElement handleIdentifier="=SukakuExplainer/&lt;diuf.sudoku.gui"/>
<javaElement handleIdentifier="=SukakuExplainer/&lt;diuf.sudoku.io"/>
<javaElement handleIdentifier="=SukakuExplainer/&lt;diuf.sudoku.solver.rules.chaining"/>
<javaElement handleIdentifier="=SukakuExplainer/&lt;diuf.sudoku.applet"/>
<javaElement handleIdentifier="=SukakuExplainer/&lt;diuf.sudoku.solver.checks"/>
<javaElement handleIdentifier="=SukakuExplainer/&lt;diuf.sudoku.test"/>
<javaElement handleIdentifier="=SukakuExplainer/&lt;diuf.sudoku.solver.rules.unique"/>
<javaElement handleIdentifier="=SukakuExplainer/&lt;diuf.sudoku.solver.rules"/>
<javaElement handleIdentifier="=SukakuExplainer/&lt;diuf.sudoku.tools"/>
</selectedElements>
</jardesc>
227 changes: 216 additions & 11 deletions diuf/sudoku/solver/Solver.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public Solver(Grid grid) {
experimentalHintProducers = new ArrayList<IndirectHintProducer>(); // Two levels of nesting !?
addIfWorth(SolvingTechnique.NestedForcingChain, experimentalHintProducers, new Chaining(true, true, false, 4));
addIfWorth(SolvingTechnique.NestedForcingChain, experimentalHintProducers, new Chaining(true, true, false, 5));
addIfWorth(SolvingTechnique.NestedForcingChain, experimentalHintProducers, new Chaining(true, true, false, 6));
}

/**
Expand Down Expand Up @@ -366,7 +367,7 @@ public int compare(Rule r1, Rule r2) {
return -1;
else if (d1 > d2)
return 1;
else
else
return r1.getName().compareTo(r2.getName());
}

Expand Down Expand Up @@ -499,7 +500,7 @@ public void getDifficulty() {
} catch (InterruptedException willHappen) {}
Hint hint = accu.getHint();
if (hint == null) {
difficulty = 20.0;
difficulty = 20.0;
break;
}
assert hint instanceof Rule;
Expand All @@ -508,19 +509,19 @@ public void getDifficulty() {
if (ruleDiff > difficulty)
difficulty = ruleDiff;
hint.apply();
if (pearl == 0.0) {
if (diamond == 0.0)
diamond = difficulty;
if (hint.getCell() != null) {
if (pearl == 0.0) {
if (diamond == 0.0)
diamond = difficulty;
if (hint.getCell() != null) {
if (want == 'd' && difficulty > diamond) {
difficulty = 20.0;
difficulty = 20.0;
break;
}
pearl = difficulty;
}
pearl = difficulty;
}
}
else if (want != 0 && difficulty > pearl) {
difficulty = 20.0;
else if (want != 0 && difficulty > pearl) {
difficulty = 20.0;
break;
}
}
Expand All @@ -529,6 +530,210 @@ else if (want != 0 && difficulty > pearl) {
}
}

// public void getHintsHint() {
// Grid backup = new Grid();
// grid.copyTo(backup);
// try {
// difficulty = Double.NEGATIVE_INFINITY;
// pearl = 0.0;
// diamond = 0.0;
// while (!isSolved()) {
// SingleHintAccumulator accu = new SingleHintAccumulator();
// try {
// for (HintProducer producer : directHintProducers)
// producer.getHints(grid, accu);
// for (IndirectHintProducer producer : indirectHintProducers)
// producer.getHints(grid, accu);
// for (IndirectHintProducer producer : chainingHintProducers)
// producer.getHints(grid, accu);
// for (IndirectHintProducer producer : chainingHintProducers2)
// producer.getHints(grid, accu);
// for (IndirectHintProducer producer : advancedHintProducers)
// producer.getHints(grid, accu);
// for (IndirectHintProducer producer : experimentalHintProducers)
// producer.getHints(grid, accu);
// } catch (InterruptedException willHappen) {}
// Hint hint = accu.getHint();
// if (hint == null) {
// difficulty = 20.0;
// break;
// }
// assert hint instanceof Rule;
// Rule rule = (Rule)hint;
// double ruleDiff = rule.getDifficulty();
// if (ruleDiff > difficulty)
// difficulty = ruleDiff;
// hint.apply();
//
// String s = "";
// for (int i = 0; i < 81; i++) {
// int n = grid.getCellValue(i % 9, i / 9);
// s += (n==0)?".":n;
// }
// s += " ";
// int w = (int)((ruleDiff + 0.05) * 10);
// int p = w % 10;
// w /= 10;
// s += w + "." + p;
// s += ", " + hint.toString();
// System.out.println(s);
// System.out.flush();
//
// if (pearl == 0.0) {
// if (diamond == 0.0)
// diamond = difficulty;
// if (hint.getCell() != null) {
// if (want == 'd' && difficulty > diamond) {
// difficulty = 20.0;
// break;
// }
// pearl = difficulty;
// }
// }
// else if (want != 0 && difficulty > pearl) {
// difficulty = 20.0;
// break;
// }
// }
// } finally {
// backup.copyTo(grid);
// }
// }
public void getHintsHint() {
Grid backup = new Grid();
grid.copyTo(backup);
try {
difficulty = Double.NEGATIVE_INFINITY;
pearl = 0.0;
diamond = 0.0;
while (!isSolved()) {
String s = "";

int crd = 1;
for (int i = 0; i < 81; i++) {
int n = grid.getCell(i % 9, i / 9).getPotentialValues().cardinality();
if ( n > crd ) { crd = n; }
}
if ( crd > 1 )
{
for (int i=0; i<3; i++ ) {
s = "+";
for (int j=0; j<3; j++ ) {
for (int k=0; k<3; k++ ) { s += "-";
for (int l=0; l<crd; l++ ) { s += "-";
}
}
s += "-+";
}
System.out.println(s);
System.out.flush();

for (int j=0; j<3; j++ ) {
s = "|";
for (int k=0; k<3; k++ ) {
for (int l=0; l<3; l++ ) {
s += " ";
int cnt = 0;
int c = ((((i*3)+j)*3)+k)*3+l;
Cell cell = grid.getCell(c % 9, c / 9);
int n = cell.getValue();
if ( n != 0 ) {
s += n;
cnt += 1;
}
if ( n == 0 ) {
for (int pv=1; pv<=9; pv++ ) {
if ( cell.hasPotentialValue( pv) ) {
s += pv;
cnt += 1;
}
}
}
for (int pad=cnt; pad<crd; pad++ ) { s += " ";
}
}
s += " |";
}
System.out.println(s);
System.out.flush();
}

}

s = "+";
for (int j=0; j<3; j++ ) {
for (int k=0; k<3; k++ ) { s += "-";
for (int l=0; l<crd; l++ ) { s += "-";
}
}
s += "-+";
}
System.out.println(s);
System.out.flush();
}

SingleHintAccumulator accu = new SingleHintAccumulator();
try {
for (HintProducer producer : directHintProducers)
producer.getHints(grid, accu);
for (IndirectHintProducer producer : indirectHintProducers)
producer.getHints(grid, accu);
for (IndirectHintProducer producer : chainingHintProducers)
producer.getHints(grid, accu);
for (IndirectHintProducer producer : chainingHintProducers2)
producer.getHints(grid, accu);
for (IndirectHintProducer producer : advancedHintProducers)
producer.getHints(grid, accu);
for (IndirectHintProducer producer : experimentalHintProducers)
producer.getHints(grid, accu);
} catch (InterruptedException willHappen) {}
Hint hint = accu.getHint();
if (hint == null) {
difficulty = 20.0;
break;
}
assert hint instanceof Rule;
Rule rule = (Rule)hint;
double ruleDiff = rule.getDifficulty();
if (ruleDiff > difficulty)
difficulty = ruleDiff;
hint.apply();

s = "";
for (int i = 0; i < 81; i++) {
int n = grid.getCellValue(i % 9, i / 9);
s += (n==0)?".":n;
}
s += " ";
int w = (int)((ruleDiff + 0.05) * 10);
int p = w % 10;
w /= 10;
s += w + "." + p;
s += ", " + hint.toString();
System.out.println(s);
System.out.flush();

if (pearl == 0.0) {
if (diamond == 0.0)
diamond = difficulty;
if (hint.getCell() != null) {
if (want == 'd' && difficulty > diamond) {
difficulty = 20.0;
break;
}
pearl = difficulty;
}
}
else if (want != 0 && difficulty > pearl) {
difficulty = 20.0;
break;
}
}
} finally {
backup.copyTo(grid);
}
}

public Map<String, Integer> toNamedList(Map<Rule, Integer> rules) {
Map<String, Integer> hints = new LinkedHashMap<String, Integer>();
for (Rule rule : rules.keySet()) {
Expand Down
3 changes: 2 additions & 1 deletion diuf/sudoku/solver/rules/AlignedExclusion.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ else if (exclCardinality >= 2 && exclCardinality <= degree)
* continue the iteration on these remaining cells.
*/
// First iterate on the first two cells
Permutations cellSetPerm2 = new Permutations(2, candidateList.size());
//Permutations cellSetPerm2 = new Permutations(2, candidateList.size());
Twomutations cellSetPerm2 = new Twomutations(2, candidateList.size());
while (cellSetPerm2.hasNext()) {
int[] indexes = cellSetPerm2.nextBitNums();
// Setup the first two cells
Expand Down
Loading

0 comments on commit 251aedb

Please sign in to comment.