Skip to content

Commit

Permalink
GUI changes. Hint files modified to reflect variants
Browse files Browse the repository at this point in the history
  • Loading branch information
SudokuMonster committed Dec 18, 2019
1 parent 7c8b634 commit be210f7
Show file tree
Hide file tree
Showing 39 changed files with 604 additions and 74 deletions.
4 changes: 2 additions & 2 deletions diuf/sudoku/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class Settings {

public final static int VERSION = 1;
public final static int REVISION = 14;
public final static String SUBREV = ".5";
public final static String releaseDate = "2019-12-15";
public final static String SUBREV = ".7";
public final static String releaseDate = "2019-12-18";
public final static String releaseYear = "2019";
public final static String releaseLicence = "Lesser General Public License";
public final static String releaseLicenceMini = "LGPL";
Expand Down
23 changes: 14 additions & 9 deletions diuf/sudoku/gui/SudokuFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ private void repaintHint() {
//SudokuMonster: Some changes in gui to limit colour salad in DG
if (!Settings.getInstance().isDG())
sudokuPanel.setGreenCells(Collections.singleton(dHint.getCell()));
else
sudokuPanel.setHighlightedCells(new Cell[] {dHint.getCell()});
BitSet values = new BitSet(10);
values.set(dHint.getValue());
sudokuPanel.setGreenPotentials(Collections.singletonMap(
Expand All @@ -210,8 +212,11 @@ private void repaintHint() {
sudokuPanel.setGreenPotentials(iHint.getGreenPotentials(sudokuPanel.getSudokuGrid(), viewNum));
sudokuPanel.setRedPotentials(iHint.getRedPotentials(sudokuPanel.getSudokuGrid(), viewNum));
sudokuPanel.setBluePotentials(iHint.getBluePotentials(sudokuPanel.getSudokuGrid(), viewNum));
if (iHint.getSelectedCells() != null && !Settings.getInstance().isDG())
sudokuPanel.setGreenCells(Arrays.asList(iHint.getSelectedCells()));
if (iHint.getSelectedCells() != null)
if (!Settings.getInstance().isDG())
sudokuPanel.setGreenCells(Arrays.asList(iHint.getSelectedCells()));
else
sudokuPanel.setHighlightedCells(iHint.getSelectedCells());
if (iHint instanceof WarningHint)
sudokuPanel.setRedCells(((WarningHint)iHint).getRedCells());
// Set links (rendered as arrows)
Expand Down Expand Up @@ -1511,7 +1516,7 @@ public void itemStateChanged(java.awt.event.ItemEvent e) {
private JCheckBoxMenuItem getMitX() {
if (mitX == null) {
mitX = new JCheckBoxMenuItem();
mitX.setText("Add X main diagonals");
mitX.setText("X main diagonals");
mitX.setSelected(false);
mitX.setToolTipText("Adds the 2 main diagonals (X) as constraints");
mitX.addItemListener(new java.awt.event.ItemListener() {
Expand All @@ -1534,7 +1539,7 @@ public void itemStateChanged(java.awt.event.ItemEvent e) {
private JCheckBoxMenuItem getMitDG() {
if (mitDG == null) {
mitDG = new JCheckBoxMenuItem();
mitDG.setText("Add Disjoint Groups");
mitDG.setText("Disjoint Groups");
mitDG.setSelected(false);
mitDG.setToolTipText("Add 9 disjoint groups");
mitDG.addItemListener(new java.awt.event.ItemListener() {
Expand All @@ -1557,9 +1562,9 @@ public void itemStateChanged(java.awt.event.ItemEvent e) {
private JCheckBoxMenuItem getMitWindows() {
if (mitWindows == null) {
mitWindows = new JCheckBoxMenuItem();
mitWindows.setText("Add Windows");
mitWindows.setText("Windows");
mitWindows.setSelected(false);
mitWindows.setToolTipText("Add Window groups (Use for Windoku)");
mitWindows.setToolTipText("Add Window groups (Use for Windoku, Hypersudoku)");
mitWindows.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent e) {
Settings.getInstance().setWindows(mitWindows.isSelected());
Expand All @@ -1580,7 +1585,7 @@ public void itemStateChanged(java.awt.event.ItemEvent e) {
private JCheckBoxMenuItem getMitAsterisk() {
if (mitAsterisk == null) {
mitAsterisk = new JCheckBoxMenuItem();
mitAsterisk.setText("Add Asterisk");
mitAsterisk.setText("Asterisk");
mitAsterisk.setSelected(false);
mitAsterisk.setToolTipText("Adds 9-cell ASTERISK extra group");
mitAsterisk.addItemListener(new java.awt.event.ItemListener() {
Expand Down Expand Up @@ -1609,7 +1614,7 @@ public void itemStateChanged(java.awt.event.ItemEvent e) {
private JCheckBoxMenuItem getMitCD() {
if (mitCD == null) {
mitCD = new JCheckBoxMenuItem();
mitCD.setText("Add CD");
mitCD.setText("Center Dot");
mitCD.setSelected(false);
mitCD.setToolTipText("Adds 9-cell CENTER DOT extra group");
mitCD.addItemListener(new java.awt.event.ItemListener() {
Expand Down Expand Up @@ -1638,7 +1643,7 @@ public void itemStateChanged(java.awt.event.ItemEvent e) {
private JCheckBoxMenuItem getMitGirandola() {
if (mitGirandola == null) {
mitGirandola = new JCheckBoxMenuItem();
mitGirandola.setText("Add Girandola");
mitGirandola.setText("Girandola");
mitGirandola.setSelected(false);
mitGirandola.setToolTipText("Adds 9-cell GIRANDOLA extra group");
mitGirandola.addItemListener(new java.awt.event.ItemListener() {
Expand Down
34 changes: 32 additions & 2 deletions diuf/sudoku/gui/SudokuPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class SudokuPanel extends JPanel {
private Collection<Cell> greenCells;
private Collection<Cell> redCells;
private Grid.Region[] blueRegions;
private Cell[] highlightedCells;
private Collection<Link> links;

private SudokuFrame parent;
Expand Down Expand Up @@ -337,6 +338,9 @@ public void setBlueRegions(Grid.Region... regions) {
this.blueRegions = regions;
}

public void setHighlightedCells(Cell[] cells) {
this.highlightedCells = cells;
}
public void setLinks(Collection<Link> links) {
this.links = links;
}
Expand Down Expand Up @@ -529,6 +533,7 @@ protected void paintComponent(Graphics g) {
paintSelectionAndFocus(g);
paintGrid(g);
paintHighlightedRegions(g);
paintOutlineSingleCells(g);
paintCellsValues(g);
paintLinks(g);
paintCellsPotentials(g);
Expand Down Expand Up @@ -679,15 +684,39 @@ private void paintWindows(Graphics g) {
}

}


//@SudokuMonster: Small Square Cell outline designed to replace yellow cell background highlighting in multi-colour variants (e.g. Disjoint groups)
private void paintOutlineSingleCells(Graphics g) {
if (highlightedCells != null) {
Color[] colors = new Color[] {Color.orange, new Color(255, 128, 0)};
for (int rev = 0; rev < 2; rev++) {
for (int i = 0; i < 1; i++) {
int x, y, w, h; // coordinates, width, height (in cells)
g.setColor(colors[1]);
for (int j = 0; j < highlightedCells.length ; j++) {
if (highlightedCells[j] == null)
continue;
x = highlightedCells[j].getX();
y = highlightedCells[j].getY();
w = 1;
h = 1;
for (int s = -2 + rev; s <= 2; s++) {
g.drawRect(x * CELL_OUTER_SIZE + (CELL_PAD + 4) + s, y * CELL_OUTER_SIZE + (CELL_PAD + 4) + s,
w * (CELL_INNER_SIZE - 8) - s * 2, h * (CELL_INNER_SIZE - 8) - s * 2);
}
}
}
}
}
}

private void paintHighlightedRegions(Graphics g) {
if (blueRegions != null) {
Color[] colors = new Color[] {new Color(0, 128, 0), new Color(255, 0, 0)};
for (int rev = 0; rev < 2; rev++) {
for (int i = 0; i < blueRegions.length; i++) {
int index = (rev == 0 ? i : blueRegions.length - 1 - i);
Grid.Region region = blueRegions[index];
//@SudokuMonster: Temp arrangement to disable Region highlighting for regions in variants
int x, y, w, h; // coordinates, width, height (in cells)
if (region != null)
if (region.getRegionTypeIndex() < 3) {
Expand Down Expand Up @@ -723,6 +752,7 @@ private void paintHighlightedRegions(Graphics g) {
}
}
else {
//@SudokuMonster: individual cells of region outlined in variants
g.setColor(colors[index % 2]);
for (int j = 0; j < 9 ; j++) {
x = region.getRegionCellIndexColumn(j);
Expand Down
35 changes: 34 additions & 1 deletion diuf/sudoku/solver/rules/AlignedExclusionHint.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ else if (i > 0)
}
builder.append(" because ");
if (lockCell == null) {
builder.append("the same value cannot occur twice in the same row, column or block");
builder.append("the same value cannot occur twice in the same " + sharedRegions());
} else {
builder.append("the cell <b>" + lockCell.toString() + "</b> must already contain <g><b>");
//builder.append(ValuesFormatter.formatValues(lockCell.getPotentialValues(), " or "));
Expand All @@ -221,6 +221,39 @@ else if (i > 0)
builder.append("<br>");
}

private String sharedRegions(){
if (Settings.getInstance().isVanilla())
return "row, column or block";
else {
String res[] = new String[10];
int i = 0;
String finalRes = "row";
if (Settings.getInstance().isVLatin())
return "row or column";
else
res[i++]= "column";
if (Settings.getInstance().isBlocks())
res[i++]= "block";
if (Settings.getInstance().isDG())
res[i++]= "disjoint group";
if (Settings.getInstance().isWindows())
res[i++]= "window group";
if (Settings.getInstance().isX())
res[i++]= "diagonal";
if (Settings.getInstance().isGirandola())
res[i++]= "girandola group";
if (Settings.getInstance().isAsterisk())
res[i++]= "asterisk group";
if (Settings.getInstance().isCD())
res[i++]= "center dot group";
i--;
for (int j = 0; j < i; j++)
finalRes += ", " + res[j];
finalRes += " or " + res[i];
return finalRes;
}
}

@Override
public String toHtml(Grid grid) {
String result;
Expand Down
9 changes: 5 additions & 4 deletions diuf/sudoku/solver/rules/Grouped2LinksFishHint.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ <h2>{0}</h2>
<p>
the arrangement of cells with value <b>{1}</b> in <b>{6}</b> and
in <b>{7}</b> (Green outlined regions) form strong links (conjugate pairs shown as green values) or grouped strong
links (yellow cell background). These strong links are weakly linked through <b>{8}</b> (Red outlined region).
links (orange cell outline or yellow cell background). These strong links are weakly linked through <b>{8}</b> (Red outlined region).
</p>
<p>
Any occurrence of the value <b>{1}</b> can therefore be removed from
any cells sharing a row, column or block with all cells with value
any cells sharing a {9} with all cells with value
<b>{1}</b> in <b>{6}</b> and <b>{7}</b> that are not part of <b>{8}</b>.
</p>
<p>
Expand All @@ -27,9 +27,10 @@ <h2>{0}</h2>
<p>
The inference of a strong link from a group of cells with value <b>{1}</b> in
any region can be spotted when a an "Empty mini Area (EmA)" is observed. This EmA
could be an empty mini-Line (EmL) in a row, column or block. In the case of "Empty
could be an empty mini-Line (EmL) in a {9}. In the case of "Empty
rectangle" the EmA is a group of empty cells that can also be referred to as
"Empty mini Rectangle (EmR)".
"Empty mini Rectangle (EmR)". Variants like "Disjoint groups" and "Windows" can
infer a strong link from cell arrangements similar to blocks.
</p>
</body>
</html>
2 changes: 1 addition & 1 deletion diuf/sudoku/solver/rules/GroupedStrongLinksHint.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h2>{0}</h2>
<p>
the arrangement of cells with value <b>{1}</b> in <b>{2}</b> and <b>{3}</b>
form strong links (conjugate pairs, shown as green values) or grouped strong
links (yellow cell background). These strong links are weakly linked to each other via
links (orange cell outline or yellow cell background). These strong links are weakly linked to each other via
<b>{6}</b> and <b>{7}</b> (Red or Green outlined region).
</p>
<p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ <h2>{0}</h2>
The value <b>{1}</b> in <b>{6}</b> forms a strong link (conjugate pair)
while the arrangement of cells with value <b>{1}</b> in <b>{7}</b> forms
a pattern known as Empty rectangle where all cells with value <b>{1}</b>
(yellow) can be mapped on one row and one column. The <i>bridge</i> cell
<b>{3}</b> shares <b>{8}</b> with some cell(s) that have the value <b>{1}</b>
in <b>{7}</b> therefore forming a weak link.
(orange cell outline or yellow cell background) can be mapped on one row and one column.
The <i>bridge</i> cell <b>{3}</b> shares <b>{8}</b> with some cell(s) that have the
value <b>{1}</b> in <b>{7}</b> therefore forming a weak link.
</p>
<p>
Any occurrence of the value <b>{1}</b> can therefore be
removed from any cells sharing a row, column or block
removed from any cells sharing a {9}
with both <i>start</i> cell <b>{2}</b> and <b>{7}</b> cells
with value <b>{1}</b> that are not part of <b>{8}</b>.
</p>
<p>
This technique is similar to a 2x2 Finned Franken X-Wing technique logic.
This technique is similar to a 2x2 Finned Franken X-Wing technique logic. It
is worth noting that some variants like "Disjoint groups" and "Windows" can
display the same pattern of an "Empty rectangle"
</p>
</body>
</html>
6 changes: 2 additions & 4 deletions diuf/sudoku/solver/rules/NakedSetGenHint.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ public int getViewCount() {

@Override
public Cell[] getSelectedCells() {
if (Settings.getInstance().isDG())
return null;
return cells;
return cells;
}

@Override
Expand Down Expand Up @@ -117,7 +115,7 @@ public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getName());
builder.append(": ");
if (cells.length <= 4)
if (cells.length <= 6)
builder.append(Cell.toFullString(this.cells));
else
builder.append("Cells [...]");
Expand Down
2 changes: 1 addition & 1 deletion diuf/sudoku/solver/rules/TurbotFishHint.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h2>{0}</h2>
</p>
<p>
Any occurrence of the value <b>{1}</b> can therefore be
removed from any cells sharing a row, column or block
removed from any cells sharing a {9}
with both <i>start</i> cells <b>{2}</b> and <b>{5}</b>.
</p>
<p>
Expand Down
39 changes: 36 additions & 3 deletions diuf/sudoku/solver/rules/TurbotFishHint.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,44 @@ public String toString() {
value;
}

private String sharedRegions(){
if (Settings.getInstance().isVanilla())
return "row, column or block";
else {
String res[] = new String[10];
int i = 0;
String finalRes = "row";
if (Settings.getInstance().isVLatin())
return "row or column";
else
res[i++]= "column";
if (Settings.getInstance().isBlocks())
res[i++]= "block";
if (Settings.getInstance().isDG())
res[i++]= "disjoint group";
if (Settings.getInstance().isWindows())
res[i++]= "window group";
if (Settings.getInstance().isX())
res[i++]= "diagonal";
if (Settings.getInstance().isGirandola())
res[i++]= "girandola group";
if (Settings.getInstance().isAsterisk())
res[i++]= "asterisk group";
if (Settings.getInstance().isCD())
res[i++]= "center dot group";
i--;
for (int j = 0; j < i; j++)
finalRes += ", " + res[j];
finalRes += " or " + res[i];
return finalRes;
}
}

@Override
public String toHtml(Grid grid) {
String result;
if ((emptyRegion1 && baseSet.getRegionTypeIndex() == 0) || (emptyRegion2 && coverSet.getRegionTypeIndex() == 0))
result = HtmlLoader.loadHtml(this, "ERFishHint.html");
result = HtmlLoader.loadHtml(this, "GroupedTCFishHint.html");
else if (emptyRegion1 || emptyRegion2)
result = HtmlLoader.loadHtml(this, "Grouped2LinksFishHint.html");
else
Expand All @@ -132,7 +165,7 @@ else if (emptyRegion1 || emptyRegion2)
String cell2 = bridgeCell1.toString();
String cell3 = bridgeCell2.toString();
String cell4 = endCell.toString();
result = HtmlLoader.format(result, name, value, cell1, cell2, cell3, cell4, base, cover, shared);
result = HtmlLoader.format(result, name, value, cell1, cell2, cell3, cell4, base, cover, shared, sharedRegions());
return result;
}

Expand Down Expand Up @@ -194,7 +227,7 @@ public String getName() {
@Override
public String getShortName() {
if ((emptyRegion1 && baseSet.getRegionTypeIndex() == 0) || (emptyRegion2 && coverSet.getRegionTypeIndex() == 0))
return "ER" + getSuffix();
return "gTC" + getSuffix();
if ((emptyRegion1 || emptyRegion2) && baseSet.getRegionTypeIndex() == coverSet.getRegionTypeIndex())
return "gSky" + getSuffix();
if (emptyRegion1 || emptyRegion2)
Expand Down
2 changes: 1 addition & 1 deletion diuf/sudoku/solver/rules/VWXYZWingHint.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ <h2>VWXYZ-Wing {12}{10}{11}</h2>
</p>
<p>
Other occurances of the <b>value {5}</b> can therefore be removed
from any cells sharing a row, column or block with all Wing cells
from any cells sharing a {13} with all Wing cells
containing the <b>value {5}</b>.
</p>
<p>
Expand Down
Loading

0 comments on commit be210f7

Please sign in to comment.