redo
This commit is contained in:
@@ -1,17 +1,21 @@
|
|||||||
package precomp;
|
package precomp;
|
||||||
|
|
||||||
|
import puzzle.Masker.Slot;
|
||||||
public sealed interface Mask
|
public sealed interface Mask
|
||||||
permits Const9x8.Cell, Const3x4.Cell, Mask.Masker {
|
permits Const9x8.Cell, Const3x4.Cell, Mask.Masker {
|
||||||
|
|
||||||
record Masker(long lo, long hi, int index, int r, int c, byte d)
|
record Masker(long lo, long hi, int index, int r, int c, int place, byte d)
|
||||||
implements precomp.Mask { }
|
implements precomp.Mask { }
|
||||||
default Mask or(Mask o) { return new Masker(o.lo() | lo(), o.hi() | hi(), 0, 0, 0, (byte) 0); }
|
default Mask or(Mask o) { return new Masker(o.lo() | lo(), o.hi() | hi(), 0, 0, 0, 0, (byte) 0); }
|
||||||
default Mask and(Mask o) { return new Masker(o.lo() & lo(), o.hi() & hi(), 0, 0, 0, (byte) 0); }
|
default Mask and(Mask o) { return new Masker(o.lo() & lo(), o.hi() & hi(), 0, 0, 0, 0, (byte) 0); }
|
||||||
|
|
||||||
long hi();
|
long hi();
|
||||||
long lo();
|
long lo();
|
||||||
int index();
|
int index();
|
||||||
int r();
|
int r();
|
||||||
int c();
|
int c();
|
||||||
|
int place();
|
||||||
byte d();
|
byte d();
|
||||||
|
default byte letter() { return (byte) (d() | 64); }
|
||||||
|
default byte clueChar() { return (byte) (d() | 48); }
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,6 @@ import puzzle.SwedishGenerator.Grid;
|
|||||||
import puzzle.SwedishGenerator.Slotinfo;
|
import puzzle.SwedishGenerator.Slotinfo;
|
||||||
import static puzzle.Masker.Slot;
|
import static puzzle.Masker.Slot;
|
||||||
import static puzzle.SwedishGenerator.X;
|
import static puzzle.SwedishGenerator.X;
|
||||||
import puzzle.SwedishGenerator.Lemma;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@@ -89,22 +88,23 @@ public record Export() {
|
|||||||
|
|
||||||
public record PuzzleResult(Signa clues, Puzzle puzzle, Slotinfo[] slots, FillResult filled) {
|
public record PuzzleResult(Signa clues, Puzzle puzzle, Slotinfo[] slots, FillResult filled) {
|
||||||
|
|
||||||
public String exportGrid(ClueSign clueChar, byte[] template) {
|
public String exportGrid(ClueSign clueChar, byte[] sb) {
|
||||||
var sb = template.clone();
|
Arrays.stream(slots).map(s -> puzzle.cells[Slot.clueIndex(s.key())]).forEach(c -> sb[c.place()] = clueChar.replace(c.clueChar()));
|
||||||
for (var slot : slots) sb[INDEX(Slot.clueIndex(slot.key()), (C + 1))] = clueChar.replace(CLUE_CHAR(Slot.dir(slot.key())));
|
puzzle.forEach((l) -> sb[l.place()] = l.letter());
|
||||||
puzzle.forEach((l) -> sb[INDEX(l.index(), C + 1)] = LETTER(l.d()));
|
|
||||||
return new String(sb);
|
return new String(sb);
|
||||||
}
|
}
|
||||||
public String cluesGridToString() { return gridToString(clues.c()); }
|
public String cluesGridToString() { return gridToString(clues.c()); }
|
||||||
public String gridRenderHuman() { return exportGrid(_ -> SPACE, INIT_GRID_OUTPUT_DASH_ARR); }
|
public String gridRenderHuman() { return exportGrid(_ -> SPACE, INIT_GRID_OUTPUT_DASH_ARR.clone()); }
|
||||||
public String gridGridToString() { return exportGrid(d1 -> d1, INIT_GRID_OUTPUT_ARR); }
|
public String gridGridToString() { return exportGrid(d1 -> d1, INIT_GRID_OUTPUT_ARR.clone()); }
|
||||||
public ExportedPuzzle exportFormatFromFilled(Rewards rewards) {
|
public ExportedPuzzle exportFormatFromFilled(Rewards rewards) {
|
||||||
if (slots.length == 0) {
|
if (slots.length == 0) {
|
||||||
return new ExportedPuzzle(new String(INIT_GRID_OUTPUT_DASH_ARR).split("\n"), new WordOut[0], 1, rewards);
|
return new ExportedPuzzle(new String(INIT_GRID_OUTPUT_DASH_ARR).split("\n"), new WordOut[0], 1, rewards);
|
||||||
}
|
}
|
||||||
|
|
||||||
var placed = Arrays.stream(slots)
|
var placed = Arrays.stream(slots)
|
||||||
.map(slot -> new Placed(slot.assign().w, slot.key(), Riddle.cellWalk(slot.key(), slot.lo(), slot.hi()).mapToObj(idx-> puzzle.cells[idx]).toArray(Mask[]::new)))
|
.map(slot -> new Placed(slot.assign().w, slot.key(), Riddle.cellWalk(slot.key(), slot.lo(), slot.hi())
|
||||||
|
.mapToObj(idx -> puzzle.cells[idx])
|
||||||
|
.toArray(Mask[]::new)))
|
||||||
.toArray(Placed[]::new);
|
.toArray(Placed[]::new);
|
||||||
|
|
||||||
// 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
|
||||||
@@ -132,7 +132,7 @@ public record Export() {
|
|||||||
int rr = l.r() - MINR;
|
int rr = l.r() - MINR;
|
||||||
int cc = l.c() - MINC;
|
int cc = l.c() - MINC;
|
||||||
if (rr >= 0 && rr < height && cc >= 0 && cc < width) {
|
if (rr >= 0 && rr < height && cc >= 0 && cc < width) {
|
||||||
template[rr * (width + 1) + cc] = LETTER(l.d());
|
template[rr * (width + 1) + cc] = l.letter();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var grid = new String(template).split("\n");
|
var grid = new String(template).split("\n");
|
||||||
|
|||||||
18
src/main/java/puzzle/Person.java
Normal file
18
src/main/java/puzzle/Person.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package puzzle;
|
||||||
|
|
||||||
|
import anno.GenAccessors;
|
||||||
|
|
||||||
|
@GenAccessors
|
||||||
|
public class Person {
|
||||||
|
@GenAccessors.Getter final String name;
|
||||||
|
@GenAccessors.Getter final int age;
|
||||||
|
|
||||||
|
public Person(String name, int age) { this.name = name; this.age = age; }
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
var p = new Person("Mike", 42);
|
||||||
|
|
||||||
|
System.out.println(Person__Accessors.getName(p));
|
||||||
|
System.out.println(Person__Accessors.getAge(p));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user