introduce bitloops
This commit is contained in:
@@ -12,10 +12,6 @@ import puzzle.SwedishGenerator.DictEntry;
|
||||
import puzzle.SwedishGenerator.FillResult;
|
||||
import puzzle.SwedishGenerator.Grid;
|
||||
import puzzle.SwedishGenerator.Slotinfo;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -197,7 +193,7 @@ public record Export() {
|
||||
}
|
||||
}
|
||||
|
||||
record Placed(long lemma, int slotKey, int[] cells) {
|
||||
record Placed(long lemma, int shardIdx, int slotKey, int[] cells) {
|
||||
|
||||
static final char[] DIRECTION = { Placed.VERTICAL, Placed.HORIZONTAL, Placed.VERTICAL, Placed.HORIZONTAL };
|
||||
public static final char HORIZONTAL = 'h';
|
||||
@@ -214,9 +210,10 @@ public record Export() {
|
||||
|
||||
public record WordOut(String word, int[] cell, int startRow, int startCol, char direction, int arrowRow, int arrowCol, boolean isReversed, int complex, String[] clue) {
|
||||
|
||||
public WordOut(long l, int startRow, int startCol, char d, int arrowRow, int arrowCol, boolean isReversed) {
|
||||
public WordOut(long l, int shardIdx, int startRow, int startCol, char d, int arrowRow, int arrowCol, boolean isReversed) {
|
||||
val meta = Meta.readRecord(Meta.shardKey(l), shardIdx);
|
||||
this(Lemma.asWord(l), new int[]{ arrowRow, arrowCol, startRow, startCol }, startRow, startCol, d, arrowRow, arrowCol, isReversed,
|
||||
CsvIndexService.simpel(Lemma.unpackIndex(l)), CsvIndexService.clues(Lemma.unpackIndex(l)));
|
||||
meta.simpel(), meta.clues());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +227,7 @@ public record Export() {
|
||||
for (var n = 1; n < slots.length; n++) {
|
||||
if (slots[n].assign().w != X) {
|
||||
k++;
|
||||
simpel += CsvIndexService.simpel(Lemma.unpackIndex(slots[n].assign().w));
|
||||
simpel += Meta.readRecord(Meta.shardKey(slots[n].assign().w), slots[n].assign().shardIdx).simpel();//.simpel(Lemma.unpackIndex(slots[n].assign().w));
|
||||
}
|
||||
}
|
||||
simpel = k == 0 ? 0 : simpel / k;
|
||||
@@ -239,7 +236,7 @@ public record Export() {
|
||||
public ExportedPuzzle exportFormatFromFilled(int difficulty, Rewards rewards) {
|
||||
var placed = new ArrayList<Placed>();
|
||||
for (var slot : slots) {
|
||||
placed.add(new Placed(slot.assign().w, slot.key(), Gridded.walk((byte) slot.key(), slot.lo(), slot.hi()).toArray()));
|
||||
placed.add(new Placed(slot.assign().w, slot.assign().shardIdx, slot.key(), Gridded.walk((byte) slot.key(), slot.lo(), slot.hi()).toArray()));
|
||||
}
|
||||
|
||||
// If nothing placed: return full grid mapped to letters/# only
|
||||
@@ -285,6 +282,7 @@ public record Export() {
|
||||
int MIN_R = minR, MIN_C = minC;
|
||||
var wordsOut = placed.stream().map(p -> new WordOut(
|
||||
p.lemma,
|
||||
p.shardIdx,
|
||||
p.startRow() - MIN_R,
|
||||
p.startCol() - MIN_C,
|
||||
p.direction(),
|
||||
@@ -298,19 +296,9 @@ public record Export() {
|
||||
|
||||
interface Dicts {
|
||||
|
||||
static Dict loadDict(String wordsPath) {
|
||||
try {
|
||||
var map = new LongArrayList(100_000);
|
||||
Files.lines(Path.of(wordsPath), StandardCharsets.UTF_8).forEach(line -> CsvIndexService.lineToLemma(line, map::add));
|
||||
return makeDict(map.toArray());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Failed to load dictionary from " + wordsPath, e);
|
||||
}
|
||||
}
|
||||
static Dict makeDict(long[] wordz) {
|
||||
var index = new DictEntryDTO[SwedishGenerator.MAX_WORD_LENGTH_PLUS_ONE];
|
||||
Arrays.setAll(index, i -> new DictEntryDTO(i));
|
||||
Arrays.setAll(index, DictEntryDTO::new);
|
||||
for (var lemma : wordz) {
|
||||
var L = Lemma.length(lemma);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user