redo
This commit is contained in:
@@ -44,11 +44,12 @@ public record Export() {
|
||||
|
||||
static int HI(int in) { return in | 64; }
|
||||
static byte LETTER(int in) { return (byte) (in | 64); }
|
||||
static char CLUE_CHAR(int s) { return (char) (s | 48); }
|
||||
static byte CLUE_CHAR(int s) { return (byte) (s | 48); }
|
||||
static int INDEX_ROW(int idx) { return idx % R; }
|
||||
static int INDEX_COL(int idx) { return idx / R; }
|
||||
static int INDEX(int r, int cols, int c) { return r * cols + c; }
|
||||
static int INDEX(int idx, int cols) { return INDEX_ROW(idx) * cols + INDEX_COL(idx); }
|
||||
|
||||
record Lettrix(int index, byte letter) {
|
||||
|
||||
public int row() { return INDEX_ROW(index); }
|
||||
@@ -57,7 +58,11 @@ public record Export() {
|
||||
static Lettrix from(int index, byte[] bytes) { return new Lettrix(index, bytes[index]); }
|
||||
public int index(int cols) { return (row() * cols) + col(); }
|
||||
}
|
||||
|
||||
public static String gridToString(Clues clues) {
|
||||
val chars = INIT_GRID_OUTPUT_ARR.clone();
|
||||
new Signa(clues).forEach(v -> chars[INDEX(v.index(), C + 1)] = CLUE_CHAR(v.clue()));
|
||||
return new String(chars);
|
||||
}
|
||||
public record Signa(@Delegate Clues c) {
|
||||
|
||||
public static Signa of(Mask... cells) { return new Signa(createEmpty()).setClue(cells); }
|
||||
@@ -70,12 +75,7 @@ public record Export() {
|
||||
}
|
||||
|
||||
public Signa deepCopyGrid() { return new Signa(new Clues(c.lo, c.hi, c.vlo, c.vhi, c.rlo, c.rhi, c.xlo, c.xhi)); }
|
||||
String gridToString() {
|
||||
var sb = new StringBuilder(INIT_GRID_OUTPUT);
|
||||
stream().forEach(v -> sb.setCharAt(INDEX(INDEX_ROW(v.index()), C + 1, INDEX_COL(v.index())), CLUE_CHAR(v.clue())));
|
||||
return sb.toString();
|
||||
}
|
||||
public Stream<Vestigium> stream() {
|
||||
@Delegate public Stream<Vestigium> stream() {
|
||||
val stream = Stream.<Vestigium>builder();
|
||||
for (var l = c.lo & ~c.xlo & ~c.rlo & c.vlo; l != X; l &= l - 1) stream.accept(new Vestigium(Long.numberOfTrailingZeros(l), CLUE_RIGHT1));
|
||||
for (var l = c.lo & ~c.xlo & ~c.rlo & ~c.vlo; l != X; l &= l - 1) stream.accept(new Vestigium(Long.numberOfTrailingZeros(l), CLUE_DOWN0));
|
||||
@@ -112,11 +112,11 @@ public record Export() {
|
||||
|
||||
public String exportGrid(ClueSign clueChar, byte[] template) {
|
||||
var sb = template.clone();
|
||||
for (var slot : slots) sb[INDEX(Slot.clueIndex(slot.key()), (C + 1))] = clueChar.replace((byte) (Slot.dir(slot.key()) | 48));
|
||||
for (var slot : slots) sb[INDEX(Slot.clueIndex(slot.key()), (C + 1))] = clueChar.replace(CLUE_CHAR(Slot.dir(slot.key())));
|
||||
puzzle.stream().forEach((l) -> sb[l.index(C + 1)] = l.human());
|
||||
return new String(sb);
|
||||
}
|
||||
public String cluesGridToString() { return clues.gridToString(); }
|
||||
public String cluesGridToString() { return gridToString(clues.c); }
|
||||
public String gridRenderHuman() { return String.join("\n", exportGrid(_ -> (byte) ' ', INIT_GRID_OUTPUT_DASH_ARR).split("\n")); }
|
||||
public String gridGridToString() { return exportGrid(d1 -> d1, INIT_GRID_OUTPUT_ARR); }
|
||||
public ExportedPuzzle exportFormatFromFilled(Rewards rewards, rci[] rcis) {
|
||||
|
||||
@@ -59,7 +59,7 @@ public class MarkerTest {
|
||||
for (var i = 0; i < 200; i++) {
|
||||
for (var j = 19; j < 24; j++) {
|
||||
var clues = masker.randomMask(j);
|
||||
assertTrue(masker.isValid(clues), "Mask should be valid for length \n" + new Signa(clues).gridToString());
|
||||
assertTrue(masker.isValid(clues), "Mask should be valid for length \n" + Export.gridToString(clues));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ public class MarkerTest {
|
||||
simCount++;
|
||||
masker.mutate(clues);
|
||||
sim += Masker.similarity(orig, clues);
|
||||
assertTrue(masker.isValid(clues), "Mask should be valid for length \n" + new Signa(clues).gridToString());
|
||||
assertTrue(masker.isValid(clues), "Mask should be valid for length \n" + Export.gridToString(clues));
|
||||
}
|
||||
}
|
||||
System.out.println("Average similarity: " + sim / simCount);
|
||||
@@ -92,7 +92,7 @@ public class MarkerTest {
|
||||
simCount++;
|
||||
var cross = masker.crossover(clues, clues2);
|
||||
sim += Math.max(Masker.similarity(cross, clues), Masker.similarity(cross, clues2));
|
||||
assertTrue(masker.isValid(cross), "Mask should be valid for length \n" + new Signa(cross).gridToString());
|
||||
assertTrue(masker.isValid(cross), "Mask should be valid for length \n" + Export.gridToString(cross));
|
||||
}
|
||||
}
|
||||
System.out.println("Average similarity: " + sim / simCount);
|
||||
|
||||
Reference in New Issue
Block a user