introduce bitloops
This commit is contained in:
@@ -68,6 +68,7 @@ public final class CsvIndexService
|
||||
return lineToSimpel(SC.get().getLine(index));
|
||||
return -1;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Failed to get clues for index " + index, e);
|
||||
}
|
||||
}
|
||||
@@ -77,6 +78,7 @@ public final class CsvIndexService
|
||||
return lineToClue(SC.get().getLine(index));
|
||||
return new String[0];
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Failed to get clues for index " + index, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,8 +159,9 @@ public record Export() {
|
||||
public void clear() { Arrays.fill(bits, 0L); }
|
||||
}
|
||||
|
||||
record Placed(long lemma, char direction, int slotKey, int[] cells) {
|
||||
record Placed(long lemma, int slotKey, int[] cells) {
|
||||
|
||||
static final char[] DIRECTION = { '\0', Placed.VERTICAL, Placed.HORIZONTAL, Placed.VERTICAL, Placed.HORIZONTAL, Placed.VERTICAL };
|
||||
public static final char HORIZONTAL = 'h';
|
||||
static final char VERTICAL = 'v';
|
||||
public int arrowCol() { return Grid.c(Slot.clueIndex(slotKey)); }
|
||||
@@ -168,6 +169,7 @@ public record Export() {
|
||||
public int startRow() { return Grid.r(cells[0]); }
|
||||
public int startCol() { return Grid.c(cells[0]); }
|
||||
public boolean isReversed() { return !Slot.increasing(slotKey); }
|
||||
public char direction() { return DIRECTION[Slot.dir(slotKey)]; }
|
||||
}
|
||||
|
||||
public record Rewards(int coins, int stars, int hints) { }
|
||||
@@ -185,15 +187,11 @@ public record Export() {
|
||||
|
||||
boolean inBounds(int idx) { return idx >= 0 && idx < SwedishGenerator.SIZE; }
|
||||
Placed extractPlacedFromSlot(Slot s, long lemma) {
|
||||
var d = s.dir();
|
||||
|
||||
var cells = s.walk().toArray();
|
||||
|
||||
char[] DIRECTION = { '\0', Placed.VERTICAL, Placed.HORIZONTAL, Placed.VERTICAL, Placed.HORIZONTAL, Placed.VERTICAL };
|
||||
|
||||
return new Placed(
|
||||
lemma,
|
||||
DIRECTION[d],
|
||||
s.key(),
|
||||
cells
|
||||
);
|
||||
@@ -258,7 +256,7 @@ public record Export() {
|
||||
p.lemma,
|
||||
p.startRow() - MIN_R,
|
||||
p.startCol() - MIN_C,
|
||||
p.direction,
|
||||
p.direction(),
|
||||
p.arrowRow() - MIN_R,
|
||||
p.arrowCol() - MIN_C,
|
||||
p.isReversed()
|
||||
|
||||
@@ -82,6 +82,7 @@ public final class HintScores {
|
||||
try {
|
||||
score = scoreFn.applyAsInt(word);
|
||||
} catch (RuntimeException ex) {
|
||||
ex.printStackTrace();
|
||||
// If scoring fails, decide your policy: skip or set 0.
|
||||
// Here: skip row.
|
||||
continue;
|
||||
|
||||
@@ -125,6 +125,7 @@ public class Main {
|
||||
else rebuildIndex();
|
||||
info("indexUpdated : " + INDEX_FILE);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
err("Failed to write: " + FILE_NAME);
|
||||
err("Reason : " + e.getMessage());
|
||||
System.exit(2);
|
||||
@@ -344,6 +345,15 @@ public class Main {
|
||||
}
|
||||
|
||||
static PuzzleResult attempt(Rng rng, Dict dict, Opts opts) {
|
||||
try {
|
||||
return _attempt(rng, dict, opts);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("Failed to operate" + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
static PuzzleResult _attempt(Rng rng, Dict dict, Opts opts) {
|
||||
TOTAL_ATTEMPTS.incrementAndGet();
|
||||
var swe = new SwedishGenerator(rng);
|
||||
var mask = swe.generateMask(opts.pop, opts.gens, Math.max(opts.pop, (int) Math.floor(opts.pop * 1.5)));
|
||||
@@ -422,6 +432,7 @@ public class Main {
|
||||
Files.writeString(indexPath, content, StandardCharsets.UTF_8);
|
||||
info("indexUpdated : " + indexPath);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
err("Failed to update index.json: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -462,10 +473,12 @@ public class Main {
|
||||
var pathInIndex = "/puzzles/" + filename;
|
||||
records.add(toIndexRecordJson(id, pathInIndex, date, theme, difficulty, createdAt));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
err("Failed to read " + path + ": " + e.getMessage());
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
err("Failed to list puzzles: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
@@ -476,6 +489,7 @@ public class Main {
|
||||
Files.writeString(indexPath, content, StandardCharsets.UTF_8);
|
||||
info("Successfully rebuilt index.json with " + records.size() + " records.");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
err("Failed to write index.json: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,7 +318,7 @@ public record SwedishGenerator(Rng rng) {
|
||||
public int clueIndex() { return clueIndex(key); }
|
||||
public static int clueIndex(int key) { return key >>> BIT_FOR_DIR; }
|
||||
public int clueC() { return Grid.c((key >>> BIT_FOR_DIR)); }
|
||||
public int dir() { return key & 7; }
|
||||
public static int dir(int key) { return key & 7; }
|
||||
public boolean horiz() { return horiz(key); }
|
||||
public boolean reversed() { return (key & 2) == 0; }
|
||||
public boolean increasing() { return (key & 2) != 0; }
|
||||
|
||||
@@ -147,10 +147,10 @@ public class SwedishGeneratorTest {
|
||||
lo |= 1L << Grid.offset(4, 5);
|
||||
|
||||
var s = Slot.from(key, lo, 0L);
|
||||
System.out.println("[DEBUG_LOG] s.dir() = " + s.dir());
|
||||
System.out.println("[DEBUG_LOG] s.dir() = " + Slot.dir(s.key()));
|
||||
assertEquals(2, s.clueR());
|
||||
assertEquals(3, s.clueC());
|
||||
assertEquals(3, s.dir());
|
||||
assertEquals(3, Slot.dir(s.key()));
|
||||
assertFalse(s.horiz());
|
||||
var cells = s.walk().toArray();
|
||||
assertEquals(2, Grid.r(cells[0]));
|
||||
@@ -259,7 +259,7 @@ public class SwedishGeneratorTest {
|
||||
assertTrue(s.len() >= 2);
|
||||
assertEquals(0, s.clueR());
|
||||
assertEquals(0, s.clueC());
|
||||
assertEquals(2, s.dir());
|
||||
assertEquals(2, Slot.dir(s.key()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user