Skip to content

Commit

Permalink
GUI and tidying up
Browse files Browse the repository at this point in the history
GUI solved cell colour change
Mionr tidying up
  • Loading branch information
SudokuMonster committed Nov 20, 2019
1 parent 7bd27fc commit 5e7ac22
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 17 deletions.
13 changes: 13 additions & 0 deletions diuf/sudoku/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class Cell {

private final int index;
private boolean isGiven;

/**
* Create a new cell
Expand All @@ -21,6 +22,18 @@ public Cell(int index) {
this.index = index;
}

public void setGiven() {
this.isGiven = true;
}

public void resetGiven() {
this.isGiven = false;
}

public boolean isGiven() {
return this.isGiven;
}

/**
* Get the x coordinate of this cell.
* 0 = leftmost, 8 = rightmost
Expand Down
26 changes: 25 additions & 1 deletion diuf/sudoku/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class Grid {
* Cell potential values of the grid, bit 0 is unused.
*/
private BitSet[] cellPotentialValues = new BitSet[81];
private boolean[] isGiven = new boolean[81];

// //cache for Region.getPotentialPositions(value)
// private valueCells valueCellsCache = new valueCells();
Expand Down Expand Up @@ -372,6 +373,23 @@ public static Grid.Region getRegionAt(int regionTypeIndex, int cellIndex) {

//=== Non-static methods ==============

/**
* Is the cell a given or not
* @param index the cell index [0..80]
*/

public void setGiven(int index) {
this.isGiven[index] = true;
}

public void resetGiven(int index) {
this.isGiven[index] = false;
}

public boolean isGiven(int index) {
return this.isGiven[index];
}

/**
* Set the value of a cell
* @param x the horizontal coordinate of the cell
Expand All @@ -380,6 +398,7 @@ public static Grid.Region getRegionAt(int regionTypeIndex, int cellIndex) {
*/
public void setCellValue(int x, int y, int value) {
cellValues[y * 9 + x] = value;
setGiven(y * 9 + x);
}

/**
Expand All @@ -389,6 +408,7 @@ public void setCellValue(int x, int y, int value) {
*/
public void setCellValue(int index, int value) {
cellValues[index] = value;
//setGiven(index);
}

/**
Expand Down Expand Up @@ -535,6 +555,10 @@ public void copyTo(Grid other) {
for (int i = 0; i < 81; i++) {
other.setCellValue(i, this.cellValues[i]);
other.setCellPotentialValues(i, cellPotentialValues[i]);
if (this.isGiven(i))
other.setGiven(i);
else
other.resetGiven(i);
}
// //clone the cache as well
// for(int regionType = 0; regionType < 3; regionType++) {
Expand Down Expand Up @@ -755,7 +779,7 @@ public void adjustPencilmarks() {
}
}
if(isnakedsingle) {
setCellValue(i, singleclue);
setCellValue(i % 9, i / 9, singleclue);
clearCellPotentialValues(i);
}
}
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,8 +17,8 @@
public class Settings {

public final static int VERSION = 1;
public final static int REVISION = 9;
public final static String SUBREV = ".4";
public final static int REVISION = 10;
public final static String SUBREV = ".2";
public final static String releaseDate = "2019-11-14";
public final static String releaseYear = "2019";
public final static String releaseLicence = "Lesser General Public License";
Expand Down
12 changes: 7 additions & 5 deletions diuf/sudoku/gui/SudokuPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class SudokuPanel extends JPanel {
private int LEGEND_GAP_SIZE = 42;
private int CELL_PAD = (CELL_OUTER_SIZE - CELL_INNER_SIZE) / 2;
private int GRID_SIZE = CELL_OUTER_SIZE * 9;
private String FONT_NAME = "Verdana";
private String FONT_NAME = "Arial Black";
private int FONT_SIZE_SMALL = 12;
private int FONT_SIZE_BIG = 36;
private int FONT_SIZE_LEGEND = 24;
Expand Down Expand Up @@ -76,9 +76,9 @@ public SudokuPanel(SudokuFrame parent) {
rescale();
initialize();
super.setOpaque(false);
smallFont = new Font(FONT_NAME, Font.BOLD, FONT_SIZE_SMALL);
bigFont = new Font(FONT_NAME, Font.BOLD, FONT_SIZE_BIG);
legendFont = new Font(FONT_NAME, Font.BOLD, FONT_SIZE_LEGEND);
smallFont = new Font(FONT_NAME, Font.PLAIN, FONT_SIZE_SMALL);
bigFont = new Font(FONT_NAME, Font.PLAIN, FONT_SIZE_BIG);
legendFont = new Font(FONT_NAME, Font.PLAIN, FONT_SIZE_LEGEND);
}

private void rescale() {
Expand Down Expand Up @@ -482,7 +482,9 @@ else if (cell == focusedCell)
}

private void initValueColor(Graphics g, Cell cell, int x, int y) {
Color col = Color.black;
//Modified on request from rjamil using what 1to9only implemented in his 16x16 version but changed to accomodate dobrichev Grid & Cell changes
//Color col = Color.black;
Color col = grid.isGiven(y * 9 + x) ? Color.black : Color.blue;
if (null != selectedCell && grid.getCellValue(selectedCell.getX(), selectedCell.getY()) == grid.getCellValue(x, y))
col = sameCellValueColor;
if (cell == selectedCell)
Expand Down
2 changes: 0 additions & 2 deletions diuf/sudoku/solver/Solver.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ public Solver(Grid grid) {
addIfWorth(SolvingTechnique.HiddenQuad, indirectHintProducers, new HiddenSet(4, false));
addIfWorth(SolvingTechnique.ThreeStrongLinks, indirectHintProducers, new StrongLinks(3));
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.FourStrongLinks, indirectHintProducers, new StrongLinks(4));
addIfWorth(SolvingTechnique.VWXYZWing, indirectHintProducers, new VWXYZWing());
Expand Down
4 changes: 2 additions & 2 deletions diuf/sudoku/solver/rules/GroupedStrongLinksHint.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ <h2>{0}</h2>
value <b>{1}</b> in <b>{11}</b> and <b>{3}</b> that are not part of <b>{12}</b> or <b>{7}</b>.
</p>
<p>
This technique is part of more genralized technique called X- chains which in itself
This technique is part of more generalized technique called X- chains which in itself
is part of more generalized technique called Alternating Inference Chains (AIC).
</p>
<p>
This technique uses logic closely realted to Finned {10} technique logic.
This technique uses logic closely related to {10} technique logic.
</p>
<p>
The grouped strong link when inferred from cells in a block that are
Expand Down
2 changes: 1 addition & 1 deletion diuf/sudoku/solver/rules/StrongLinksHint.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h2>{0}</h2>
a row, column or block with <i>both start and end</i> cells <b>{8}</b> and <b>{9}</b>.
</p>
<p>
This technique is similar to a 2x2x2 Finned {10} technique logic, Coloring
This technique is closely related to {10} technique logic, Coloring
technique or L1-Wing technique. It is a subcategory of X-Chains group of techniques
which is in itself a subgroup of Alternating Inference Chains (AIC) group of techniques.
</p>
Expand Down
12 changes: 9 additions & 3 deletions diuf/sudoku/solver/rules/StrongLinksHint.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,17 @@ public String toString() {
@Override
public String toHtml(Grid grid) {
String result;
if (groupedLinks() > 0)
String fishName = getFishName(linksNumber);
if (groupedLinks() > 0) {
result = HtmlLoader.loadHtml(this, "GroupedStrongLinksHint.html");
else
fishName = "Finned " + fishName;
}
else {
result = HtmlLoader.loadHtml(this, "StrongLinksHint.html");
fishName = "1 Finned Sashimi " + fishName;
for (int i = 1; i < linksNumber; i++)
fishName = "2x" + fishName;
}
String name = getName();
String firstLinkName = this.baseLinkRegion[q[0]].toFullString();
String lastLinkName = this.baseLinkRegion[q[linksNumber - 1]].toFullString();
Expand All @@ -182,7 +189,6 @@ public String toHtml(Grid grid) {
middleShared += ", " +this.shareRegion[i].toFullString();
String numberOfStrongLinks = Integer.toString(linksNumber);
String numberOfWeakLinks = Integer.toString(linksNumber - 1);
String fishName = getFishName(linksNumber);
String value = Integer.toString(this.value);
String cell1 = startCell.toString();
String cell2 = endCell.toString();
Expand Down
10 changes: 9 additions & 1 deletion diuf/sudoku/solver/rules/chaining/Chaining.java
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,15 @@ private Collection<Potential> getAdvancedPotentials(final Grid grid, final Grid
otherRules.add(new HiddenSet(2, false));
otherRules.add(new NakedSet(2));
otherRules.add(new Fisherman(2));

// otherRules.add(new TurbotFish());
// otherRules.add(new XYWing(false));
// otherRules.add(new XYWing(true));
// otherRules.add(new HiddenSet(3, false));
// otherRules.add(new NakedSet(3));
// otherRules.add(new Fisherman(3));
// otherRules.add(new StrongLinks(3));
// otherRules.add(new WXYZWing());

// //otherRules.add(new HiddenSingle());
// //otherRules.add(new Locking(true));
// //otherRules.add(new HiddenSet(2, true));
Expand Down

0 comments on commit 5e7ac22

Please sign in to comment.