introduce bitloops
This commit is contained in:
@@ -110,32 +110,37 @@ public record Export() {
|
|||||||
}
|
}
|
||||||
//public boolean isLetterSet(int idx) { return isLetter(g[idx]); }
|
//public boolean isLetterSet(int idx) { return isLetter(g[idx]); }
|
||||||
char NOT_CLUE_NOT_LETTER_TO(byte b, char fallback) { return isLetter(b) ? (char) b : fallback; }
|
char NOT_CLUE_NOT_LETTER_TO(byte b, char fallback) { return isLetter(b) ? (char) b : fallback; }
|
||||||
String gridToString() {
|
String gridToString(Clues clues) {
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
for (var r = 0; r < R; r++) {
|
for (var r = 0; r < R; r++) {
|
||||||
if (r > 0) sb.append('\n');
|
if (r > 0) sb.append('\n');
|
||||||
for (var c = 0; c < C; c++) sb.append((char) grid.letter32At(Grid.offset(r, c)));
|
for (var c = 0; c < C; c++) {
|
||||||
|
var offset = Grid.offset(r, c);
|
||||||
|
if (clues.isClue(offset))
|
||||||
|
sb.append((char) (48 | clues.digitAt(offset)));
|
||||||
|
else
|
||||||
|
sb.append((char) grid.letter32At(offset));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
public String renderHuman() {
|
public String renderHuman(Clues clues) {
|
||||||
return String.join("\n", exportGrid(_ -> ' ', '#'));
|
return String.join("\n", exportGrid(clues, _ -> ' ', '#'));
|
||||||
}
|
}
|
||||||
public boolean notClue(int c) { return grid.notClue(c); }
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
interface Replacar {
|
interface Replacar {
|
||||||
|
|
||||||
record Cell(Grid grid, int index, byte data) { }
|
record Cell(Grid grid, Clues clues, int index, byte data) { }
|
||||||
char replace(Cell c);
|
char replace(Cell c);
|
||||||
}
|
}
|
||||||
public String[] exportGrid(Replacar clueChar, char emptyFallback) {
|
public String[] exportGrid(Clues clues, Replacar clueChar, char emptyFallback) {
|
||||||
var out = new String[R];
|
var out = new String[R];
|
||||||
for (var r = 0; r < R; r++) {
|
for (var r = 0; r < R; r++) {
|
||||||
var sb = new StringBuilder(C);
|
var sb = new StringBuilder(C);
|
||||||
for (var c = 0; c < C; c++) {
|
for (var c = 0; c < C; c++) {
|
||||||
var offset = Grid.offset(r, c);
|
var offset = Grid.offset(r, c);
|
||||||
if (grid.isClue(offset)) {
|
if (clues.isClue(offset)) {
|
||||||
sb.append(clueChar.replace(new Cell(grid, offset, grid.letter32At(offset))));
|
sb.append(clueChar.replace(new Cell(grid, clues, offset, clues.digitAt(offset))));
|
||||||
} else {
|
} else {
|
||||||
sb.append(NOT_CLUE_NOT_LETTER_TO(grid.letter32At(offset), emptyFallback));
|
sb.append(NOT_CLUE_NOT_LETTER_TO(grid.letter32At(offset), emptyFallback));
|
||||||
}
|
}
|
||||||
@@ -199,7 +204,7 @@ public record Export() {
|
|||||||
|
|
||||||
// If nothing placed: return full grid mapped to letters/# only
|
// If nothing placed: return full grid mapped to letters/# only
|
||||||
if (placed.isEmpty()) {
|
if (placed.isEmpty()) {
|
||||||
return new ExportedPuzzle(g.exportGrid(_ -> '#', '#'), new WordOut[0], difficulty, rewards);
|
return new ExportedPuzzle(g.exportGrid(mask.mask, _ -> '#', '#'), new WordOut[0], difficulty, rewards);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2) bounding box around all word cells + arrow cells, with 1-cell margin
|
// 2) bounding box around all word cells + arrow cells, with 1-cell margin
|
||||||
@@ -224,7 +229,7 @@ public record Export() {
|
|||||||
var letterAt = new HashMap<Integer, Character>();
|
var letterAt = new HashMap<Integer, Character>();
|
||||||
for (var p : placed) {
|
for (var p : placed) {
|
||||||
for (var c : p.cells) {
|
for (var c : p.cells) {
|
||||||
if (inBounds(c) && g.notClue(c)) {
|
if (inBounds(c) && mask.notClue(c)) {
|
||||||
letterAt.put(c, (char) g.letter32At(c));
|
letterAt.put(c, (char) g.letter32At(c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,10 +94,10 @@ public class Main {
|
|||||||
System.out.print(indentLines(res.mask().gridToString(), " "));
|
System.out.print(indentLines(res.mask().gridToString(), " "));
|
||||||
|
|
||||||
section("Grid (raw)");
|
section("Grid (raw)");
|
||||||
System.out.print(indentLines(res.filled().grid().gridToString(), " "));
|
System.out.print(indentLines(res.filled().grid().gridToString(res.mask().mask()), " "));
|
||||||
|
|
||||||
section("Grid (human)");
|
section("Grid (human)");
|
||||||
System.out.print(indentLines(res.filled().grid().renderHuman(), " "));
|
System.out.print(indentLines(res.filled().grid().renderHuman(res.mask().mask()), " "));
|
||||||
|
|
||||||
var exported = res.exportFormatFromFilled(1, new Rewards(50, 2, 1));
|
var exported = res.exportFormatFromFilled(1, new Rewards(50, 2, 1));
|
||||||
|
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ public class MainTest {
|
|||||||
System.out.println("[DEBUG_LOG] Simplicity: " + res.filled().stats().simplicity);
|
System.out.println("[DEBUG_LOG] Simplicity: " + res.filled().stats().simplicity);
|
||||||
System.out.println("[DEBUG_LOG] ClueMap Size: " + res.filled().wordCount());
|
System.out.println("[DEBUG_LOG] ClueMap Size: " + res.filled().wordCount());
|
||||||
System.out.println("[DEBUG_LOG] Grid:");
|
System.out.println("[DEBUG_LOG] Grid:");
|
||||||
System.out.println(res.filled().grid().renderHuman());
|
System.out.println(res.filled().grid().renderHuman(res.mask().mask()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user