Skip to content

Commit

Permalink
Merge pull request #63 from SudokuMonster/newTechniques
Browse files Browse the repository at this point in the history
New techniques merge
  • Loading branch information
SudokuMonster authored Oct 15, 2019
2 parents 2c78ab1 + e09bb8a commit 51a83f8
Show file tree
Hide file tree
Showing 17 changed files with 1,214 additions and 31 deletions.
15 changes: 15 additions & 0 deletions diuf/sudoku/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ public CellSet getVisibleCells() {
return Grid.visibleCellsSet[index];
}

public boolean canSeeCell(Cell other) {
return Grid.visibleCellsSet[index].contains(other);
}

public boolean canSeeAnyOfCells(CellSet cellSet) {
CellSet currentSet = new CellSet(Grid.visibleCellsSet[index]);
currentSet.retainAll(cellSet);
int currentSetSize = currentSet.size();
if (currentSetSize > 0)
return true;
return false;
}



/**
* Get the cells that form the "house" of this cell. The
* cell indexes have to be greater than this cell index. The "house"
Expand Down
10 changes: 5 additions & 5 deletions diuf/sudoku/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public class Grid {
public static final int[][] cellRegions;
public static final int[][] visibleCellIndex;
public static final int[][] forwardVisibleCellIndex;
private static final Block[] blocks;
private static final Row[] rows;
private static final Column[] columns;
public static final Block[] blocks;
public static final Row[] rows;
public static final Column[] columns;
public static final Region[][] regions;
public static final CellSet[] visibleCellsSet;
public static final CellSet[] forwardVisibleCellsSet;
Expand Down Expand Up @@ -670,7 +670,7 @@ public String toString() {
public String toFullString() {
Settings settings = Settings.getInstance();
if (settings.isRCNotation())
return toString() + " R" + (rowNum + 1);
return toString() + " " + (rowNum + 1);
else
return toString() + " " + (rowNum + 1);
}
Expand Down Expand Up @@ -714,7 +714,7 @@ public String toString() {
public String toFullString() {
Settings settings = Settings.getInstance();
if (settings.isRCNotation())
return toString() + " C" + (columnNum + 1);
return toString() + " " + (columnNum + 1);
else
return toString() + " " + (char)('A' + columnNum);
}
Expand Down
4 changes: 2 additions & 2 deletions diuf/sudoku/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
public class Settings {

public final static int VERSION = 1;
public final static int REVISION = 4;
public final static int REVISION = 6;
public final static String SUBREV = ".1";
public final static String releaseDate = "2019-09-22";
public final static String releaseDate = "2019-10-15";
public final static String releaseYear = "2019";
public final static String releaseLicence = "Lesser General Public License";
public final static String releaseLicenceMini = "LGPL";
Expand Down
2 changes: 2 additions & 0 deletions diuf/sudoku/SolvingTechnique.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum SolvingTechnique {
NakedTriplet("Naked Triplet"),
Swordfish("Swordfish"),
HiddenTriplet("Hidden Triplet"),
TurbotFish("Scraper, Kite, Turbot"),
XYWing("XY-Wing"),
XYZWing("XYZ-Wing"),
// WWing("W-Wing"),
Expand All @@ -27,6 +28,7 @@ public enum SolvingTechnique {
NakedQuad("Naked Quad"),
Jellyfish("Jellyfish"),
HiddenQuad("Hidden Quad"),
ThreeStrongLinks("3 Strong-linked Fishes"),
//VWXYZWing4("VWXYZ-Wing 4"),
//VWXYZWing5("VWXYZ-Wing 5"),
VWXYZWing("VWXYZ-Wing"),
Expand Down
164 changes: 163 additions & 1 deletion diuf/sudoku/gui/GenerateDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,168 @@ public String getnotMaxTechnique2() {
public String getnotMaxTechnique3() {
return "";
}
},
TwoStringKite {

@Override
public double getMinDifficulty() {
return 4.1;
}

@Override
public double getMaxDifficulty() {
return 4.1;
}
@Override
public double getincludeDifficulty1() {
return 0.0;
}
@Override
public double getincludeDifficulty2() {
return 0.0;
}
@Override
public double getincludeDifficulty3() {
return 0.0;
}
@Override
public double getexcludeDifficulty1() {
return 0.0;
}
@Override
public double getexcludeDifficulty2() {
return 0.0;
}
@Override
public double getexcludeDifficulty3() {
return 0.0;
}
@Override
public double getnotMaxDifficulty1() {
return 0.0;
}
@Override
public double getnotMaxDifficulty2() {
return 0.0;
}
@Override
public double getnotMaxDifficulty3() {
return 0.0;
}
public String getexcludeTechnique1() {
return "Skyscraper";
}
@Override
public String getexcludeTechnique2() {
return "";
}
@Override
public String getexcludeTechnique3() {
return "";
}
public String getincludeTechnique1() {
return "";
}
@Override
public String getincludeTechnique2() {
return "";
}
@Override
public String getincludeTechnique3() {
return "";
}
public String getnotMaxTechnique1() {
return "";
}
@Override
public String getnotMaxTechnique2() {
return "";
}
@Override
public String getnotMaxTechnique3() {
return "";
}
},
ThreeStrongLinks {

@Override
public double getMinDifficulty() {
return 5.4;
}

@Override
public double getMaxDifficulty() {
return 5.6;
}
@Override
public double getincludeDifficulty1() {
return 0.0;
}
@Override
public double getincludeDifficulty2() {
return 0.0;
}
@Override
public double getincludeDifficulty3() {
return 0.0;
}
@Override
public double getexcludeDifficulty1() {
return 0.0;
}
@Override
public double getexcludeDifficulty2() {
return 0.0;
}
@Override
public double getexcludeDifficulty3() {
return 0.0;
}
@Override
public double getnotMaxDifficulty1() {
return 0.0;
}
@Override
public double getnotMaxDifficulty2() {
return 0.0;
}
@Override
public double getnotMaxDifficulty3() {
return 0.0;
}
public String getexcludeTechnique1() {
return "";
}
@Override
public String getexcludeTechnique2() {
return "";
}
@Override
public String getexcludeTechnique3() {
return "";
}
public String getincludeTechnique1() {
return " 10";
}
@Override
public String getincludeTechnique2() {
return "";
}
@Override
public String getincludeTechnique3() {
return "";
}
public String getnotMaxTechnique1() {
return "";
}
@Override
public String getnotMaxTechnique2() {
return "";
}
@Override
public String getnotMaxTechnique3() {
return "";
}
},
WXYZ {

Expand Down Expand Up @@ -923,7 +1085,7 @@ public String getexcludeTechnique3() {
return "";
}
public String getincludeTechnique1() {
return "";
return "ligned";
}
@Override
public String getincludeTechnique2() {
Expand Down
6 changes: 6 additions & 0 deletions diuf/sudoku/gui/ThreeStrongLinks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<body>
<b>3 strong links</b>: Requires a fish with 3 strong links (101 or 102 formation)
Rating: 5.5-5.6
</body>
</html>
6 changes: 6 additions & 0 deletions diuf/sudoku/gui/TwoStringKite.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<body>
<b>2-String Kite</b>: The Sudoku requires a 2-String Kite to solve.
Rating: 4.1
</body>
</html>
4 changes: 4 additions & 0 deletions diuf/sudoku/solver/Rule.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ public interface Rule {
* <li>2.8: Claiming
* <li>3.0, 3.2, 3.4: Naked pair, X-Wing, Hidden pair
* <li>3.6, 3.8, 4.0: Naked triplet, Swordfish, Hidden triplet
* <li>4.0, 4.1, 4.2: Skyscraper, 2-String Kite, Turbot Fish
* <li>4.2, 4.4: XY-Wing, XYZ-Wing
// * <li>4.4: W-Wing
* <li>4.5 - 5.0: Unique Rectangles and Loops
* <li>5.0, 5.2, 5.4: Naked quad, Jellyfish, Hidden quad
* <li>5.4, 5.5, 5.6: Skyscraper (3SL) , 3-String Kite, Turbot Fish (3SL)
* <li>5.5: WXYZ-Wing
* <li>5.6 - 6.0: Bivalue Universal Graves
* <li>6.2 - 6.4: VWXYZ-Wing
Expand Down Expand Up @@ -84,10 +86,12 @@ public interface Rule {
* <li>3.1: Direct Hidden Triplet//2.5 ---> 3.0 ---> 3.1
* <li>3.2: X-Wing
* <li>3.6, 3.8, 4.0: Naked triplet, Hidden triplet, Swordfish//3.8 ---> 4.0 4.0 ---> 3.8
* <li>4.0, 4.1, 4.2: Skyscraper, 2-String Kite, Turbot Fish (placed before Swordfish)
* <li>4.2, 4.4: XY-Wing, XYZ-Wing
// * <li>4.4: W-Wing
* <li>4.5 - 5.0: Unique Rectangles and Loops
* <li>5.0, 5.2, 5.4: Naked quad, Hidden quad, Jellyfish//5.2 ---> 5.4 5.4 ---> 5.2
* <li>5.4, 5.5, 5.6: Skyscraper (3SL) , 3-String Kite, Turbot Fish (3SL)
* <li>5.5: WXYZ-Wing
* <li>5.6 - 6.0: Bivalue Universal Graves
* <li>6.2 - 6.4: VWXYZ-Wing
Expand Down
7 changes: 4 additions & 3 deletions diuf/sudoku/solver/Solver.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public Solver(Grid grid) {
addIfWorth(SolvingTechnique.XWing, indirectHintProducers, new Fisherman(2));
addIfWorth(SolvingTechnique.NakedTriplet, indirectHintProducers, new NakedSet(3));
addIfWorth(SolvingTechnique.HiddenTriplet, indirectHintProducers, new HiddenSet(3, false));
addIfWorth(SolvingTechnique.TurbotFish, indirectHintProducers, new TurbotFish());
addIfWorth(SolvingTechnique.Swordfish, indirectHintProducers, new Fisherman(3));
addIfWorth(SolvingTechnique.XYWing, indirectHintProducers, new XYWing(false));
addIfWorth(SolvingTechnique.XYZWing, indirectHintProducers, new XYWing(true));
Expand All @@ -157,8 +158,6 @@ public Solver(Grid grid) {
addIfWorth(SolvingTechnique.HiddenQuad, indirectHintProducers, new HiddenSet(4, false));
addIfWorth(SolvingTechnique.Jellyfish, indirectHintProducers, new Fisherman(4));
addIfWorth(SolvingTechnique.WXYZWing, indirectHintProducers, new WXYZWing());
//addIfWorth(SolvingTechnique.VWXYZWing4, indirectHintProducers, new VWXYZWing(true));
//addIfWorth(SolvingTechnique.VWXYZWing5, indirectHintProducers, new VWXYZWing(false));
addIfWorth(SolvingTechnique.BivalueUniversalGrave, indirectHintProducers, new BivalueUniversalGrave());
addIfWorth(SolvingTechnique.VWXYZWing, indirectHintProducers, new VWXYZWing());
addIfWorth(SolvingTechnique.AlignedPairExclusion, indirectHintProducers, new AlignedPairExclusion());
Expand Down Expand Up @@ -202,14 +201,16 @@ public Solver(Grid grid) {
addIfWorth(SolvingTechnique.NakedTriplet, indirectHintProducers, new NakedSet(3));
addIfWorth(SolvingTechnique.Swordfish, indirectHintProducers, new Fisherman(3));
addIfWorth(SolvingTechnique.HiddenTriplet, indirectHintProducers, new HiddenSet(3, false));
addIfWorth(SolvingTechnique.TurbotFish, indirectHintProducers, new TurbotFish());
addIfWorth(SolvingTechnique.XYWing, indirectHintProducers, new XYWing(false));
addIfWorth(SolvingTechnique.XYZWing, indirectHintProducers, new XYWing(true));
// addIfWorth(SolvingTechnique.WWing, indirectHintProducers, new WWing());
addIfWorth(SolvingTechnique.UniqueLoop, indirectHintProducers, new UniqueLoops());
addIfWorth(SolvingTechnique.NakedQuad, indirectHintProducers, new NakedSet(4));
addIfWorth(SolvingTechnique.Jellyfish, indirectHintProducers, new Fisherman(4));
addIfWorth(SolvingTechnique.HiddenQuad, indirectHintProducers, new HiddenSet(4, false));
addIfWorth(SolvingTechnique.WXYZWing, indirectHintProducers, new WXYZWing());
addIfWorth(SolvingTechnique.ThreeStrongLinks, indirectHintProducers, new ThreeStrongLinks());
addIfWorth(SolvingTechnique.WXYZWing, indirectHintProducers, new WXYZWing());
//addIfWorth(SolvingTechnique.VWXYZWing4, indirectHintProducers, new VWXYZWing(true));
//addIfWorth(SolvingTechnique.VWXYZWing5, indirectHintProducers, new VWXYZWing(false));
addIfWorth(SolvingTechnique.BivalueUniversalGrave, indirectHintProducers, new BivalueUniversalGrave());
Expand Down
Loading

6 comments on commit 51a83f8

@dobrichev
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SudokuMonster
This commit, which is released as version 1.6.1, rates 15 out of 80 puzzles from pg354 differently when using default parameters.

Are all these differences considered obvious bugs in previous releases?
If not, are there non-default parameters introduced that allow rating using the old rules?

Command:
java -cp SukakuExplainer.1.6.1.jar diuf.sudoku.test.serate -i- --format=%g%t1.6.1=%r/%p/%d < pg354.0 > pg354.1.6.1
Puzzles with changed rating:

000000000001020300030405060002500700050004080009060100080109070003070600000000009 #  65    5.1/3.0/2.6	1.6.1=4.0/3.0/2.6*
000000000001020300020405060007800500040006020003090100090108050002070900000000008 #  68    5.6/5.0/2.6	1.6.1=5.4/5.0/2.6*
000000000001020300040506070003700200080002030002040500070609050005080100000000009 #  70    5.8/4.2/3.0	1.6.1=4.2/4.2/3.0*
000000000005010600040203070001400800020005090008020500090702060002060300000000008 #  50    5.9/2.0/2.0	1.6.1=4.5/2.0/2.0*
000000000009070800080405010004900300020004050007080600060201080002030400000000003 #  51    5.9/2.8/2.8	1.6.1=4.5/2.8/2.8*
000000000001020300040105060006400100070008020008030500050609040007080200000000009 #  71    5.9/3.8/2.6	1.6.1=4.0/3.8/2.6*
000000000001020300020405060003200400070003050006070800050607040004080700000000009 #  73    6.1/1.5/1.5	1.6.1=5.5/1.5/1.5*
000000000001020300030401050006700200080002010005030400010609030003050600000000009 #  35    6.2/6.2/6.2	1.6.1=5.6/5.6/5.6*
000000000001020300040305060006700500020008040007060800050603090008070100000000002 #  57    6.5/6.5/2.6	1.6.1=5.5/5.5/2.6*
000000000001020300020405060003200100070003040002080900060508020007090600000000008 #  37    6.6/6.6/6.6	1.6.1=6.3/6.3/6.3*
000000000001020300040506070008300100090008020005070400070109060003080500000000004 #  52    6.7/6.7/3.6	1.6.1=5.4/5.4/3.6*
000000000001020300030405060006100700040008010009040200050306070007050600000000009 #  74    6.7/6.7/4.2	1.6.1=5.4/5.4/4.2*
000000000009070800080405010008900300020004050007050600060201080003040900000000006 #  49    6.9/6.9/3.8	1.6.1=6.6/6.6/3.8*
000000000001020300040305060003400500060003070008070100050709020002080600000000009 #  76    7.9/7.9/7.8	1.6.1=7.8/7.8/7.8*
000000000001020300040503060007800100030002080002060400060105090004080500000000007 #  53    8.0/8.0/7.1	1.6.1=8.0/8.0/6.4*

@SudokuMonster
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes to Uniqueness & BUG were bug fixes by lksudoku to the original SE code that I committed to Master without an option to disable like the chaining fix which was debatabale. I tested on a variety of puzzles and they resulted in all test cases having no change or reduction in rating as demonstrated.

This issue has been highlighted as well in previous discussion on the players forum

@dobrichev
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any plans how to resolve this?
Could this be a neglected default activation of some of the new techniques?

@SudokuMonster
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mis-read your original question

  -~, --techs=TECHSTRING
      Specific techniques only, set which techniques to use
      the techniques string TECHSTRING is a string consisting of the letters '0' and '1',
      where '1' means the technique should be used and '0' means it should not be used
      To see which technique is in which letter, and how many techniques are
      there, just type --techs= without any string after the = in TECHSTRING

By default all techniques are activated (including new ones) so all have "1" by default. To have the old ratings. use techs= & a series of 0 and 1 to choose whatever techniques you need to deactivate

@SudokuMonster
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My next task after finalizing the current new techniques update and a new release would be to add an option to use Sukaku explainer to rate exactly as the version used in the current patterns game.

This would mean visiting the code I committed to Master with lksudoku's bug fixes to (uniqueness and BUG) and allow removing them as an option. Disabling the new techniques through --techs=TECHSTRING and disabling lksudoku's bug fixes would then allow complete backward compatibility.

This could be later complemented with similar feature in GUI

@SudokuMonster
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue is now sorted

	private boolean islkSudokuBUG = true; //Fix to BUG algorithm by lkSudoku
	private boolean islkSudokuURUL = true; //Fix to UR and UL algorithm by lkSudoku

The above would control the fixes to BUG and unique loops respectively. These can be controlled from Command line solver and I have also coded optional control as well from GUI. As you can control which techniques to enable/disable already then in theory you can revert to SE121 style ratings/ technique order and the buggy algorithm. I will upload to master within 1 week

Please sign in to comment.