Skip to content

Commit

Permalink
Fix #111 1st in bug report #114
Browse files Browse the repository at this point in the history
Needs testing of grouped strong links in box with more than  5 candidates in box
  • Loading branch information
SudokuMonster committed Sep 22, 2021
1 parent 1fb47ce commit 362854e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
8 changes: 8 additions & 0 deletions diuf/sudoku/Grid.java
Original file line number Diff line number Diff line change
Expand Up @@ -2712,6 +2712,14 @@ public BitSet crossBlade2(int index) {
return blockGroupedCellSet;
}

//1 Cell set corresponds to intersection cell in block cells that share exactly 1 column and 1 row
public BitSet crossHeart(int index) {
BitSet blockGroupedCellSet = new BitSet(10);
blockGroupedCellSet.set(index);
return blockGroupedCellSet;
}


//cellIndex of blockCell at centre of Cross Cell set
public int Heart(int index) {
int[] blocksHeartCells = new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8};
Expand Down
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 = 18;
public final static String SUBREV = ".0";
public final static String releaseDate = "2021-09-21";
public final static String SUBREV = ".1";
public final static String releaseDate = "2021-09-22";
public final static String releaseYear = "2021";
public final static String releaseLicence = "Lesser General Public License";
public final static String releaseLicenceMini = "LGPL";
Expand Down
20 changes: 18 additions & 2 deletions diuf/sudoku/solver/rules/StrongLinks.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ private void buildLinks(Grid grid, int digit, int[] linkSet, int linksNumber, in
continue;
BitSet baseLinkBlade1 = (BitSet)baseLinkRegionPotentials.clone();
BitSet baseLinkBlade2 = (BitSet)baseLinkRegionPotentials.clone();
//@SudokuMonster #111 bug fixattempt
BitSet beatingHeart = (BitSet)baseLinkRegionPotentials.clone();

if (baseLinkRegionPotentialsC > 2) {
//Grouped Strong links in box have 15 configurations but only 9 are ER
for (e[linksDepth] = 0; e[linksDepth] < (linkSet[linksDepth] < 1 ? 15 : 3); e[linksDepth]++) {
Expand All @@ -304,6 +307,8 @@ private void buildLinks(Grid grid, int digit, int[] linkSet, int linksNumber, in
BitSet baseLinkEmptyArea = (BitSet)baseLinkRegionPotentials.clone();
baseLinkBlade1 = (BitSet)baseLinkRegionPotentials.clone();
baseLinkBlade2 = (BitSet)baseLinkRegionPotentials.clone();
//@SudokuMonster #111 bug fixattempt
beatingHeart = (BitSet)baseLinkRegionPotentials.clone();
if (linkSet[linksDepth] == 0 || linkSet[linksDepth] == 3 || linkSet[linksDepth] == 4) {
//confirm if we have an empty rectangle
//block has 9 cells: 4 "Cross" cells, 4 "Rectangle" cells and 1 "Heart" cell
Expand All @@ -320,6 +325,8 @@ private void buildLinks(Grid grid, int digit, int[] linkSet, int linksNumber, in
//9 configurations for each block depending on "Heart" cell
baseLinkBlade1.and(baseLinkRegion[linksDepth].crossBlade1(e[linksDepth]));
baseLinkBlade2.and(baseLinkRegion[linksDepth].crossBlade2(e[linksDepth]));
//@SudokuMonster #111 bug fixattempt
beatingHeart.and(baseLinkRegion[linksDepth].crossHeart(e[linksDepth]));
}
else {
baseLinkBlade1.and(baseLinkRegion[linksDepth].lineBlade1(e[linksDepth]));
Expand Down Expand Up @@ -443,8 +450,17 @@ private void buildLinks(Grid grid, int digit, int[] linkSet, int linksNumber, in
cells[linksDepth * 2 + 1] = baseLinkRegion[linksDepth].getCell(baseLinkBlade1.nextSetBit(p1 + 1));
cells[linksNumber * 2 + linksDepth * 2 + 0] = baseLinkRegion[linksDepth].getCell(baseLinkBlade2.nextSetBit(0));
}
if (!EmL)
baseLinkGroupedLinkOrdinal = 1; }
if (!EmL) {
baseLinkGroupedLinkOrdinal = 1;
//@SudokuMonster #111 bug fixattempt
if (e[linksDepth] < 9){
if (baseLinkBlade1.cardinality() == 2 && beatingHeart.cardinality() == 1)
cells[linksDepth * 2 + linksNumber * 4 + 0] = baseLinkRegion[linksDepth].getCell(baseLinkRegion[linksDepth].Heart(e[linksDepth]));
if (baseLinkBlade2.cardinality() == 2 && beatingHeart.cardinality() == 1)
cells[linksDepth * 2 + linksNumber * 4 + 1] = baseLinkRegion[linksDepth].getCell(baseLinkRegion[linksDepth].Heart(e[linksDepth]));
}
}
}
}
else {
baseLinkGroupedLinkOrdinal = 1;
Expand Down

0 comments on commit 362854e

Please sign in to comment.