Gather data

This commit is contained in:
mike
2026-01-06 02:22:26 +01:00
parent 42a69235d2
commit f031e97a58
5 changed files with 143 additions and 164 deletions

View File

@@ -1,6 +1,7 @@
package puzzle;
import java.sql.*;
import java.util.Map;
import java.util.function.ToIntFunction;
public final class HintScores {
@@ -8,9 +9,37 @@ public final class HintScores {
public static void main(String[] args) throws Exception {
Class.forName("org.sqlite.JDBC");
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:/home/mike/dev/puzzle-generator/tools/hint/hint.sqlite")) {
updateCrossScores(conn, HintScores::exampleScore, 1000);
updateCrossScores(conn, HintScores::crossabilityScore, 1000);
}
}
static final Map<Character, Integer> LETTER_WEIGHT = Map.ofEntries(
Map.entry('E', 10), Map.entry('N', 9), Map.entry('A', 9), Map.entry('R', 8),
Map.entry('I', 8), Map.entry('O', 7), Map.entry('S', 7), Map.entry('T', 7),
Map.entry('D', 6), Map.entry('L', 6), Map.entry('K', 5), Map.entry('M', 5),
Map.entry('U', 5), Map.entry('P', 4), Map.entry('G', 4), Map.entry('H', 4),
Map.entry('V', 4), Map.entry('B', 3), Map.entry('W', 3),
Map.entry('C', 2), Map.entry('F', 2), Map.entry('Z', 2),
Map.entry('J', 1), Map.entry('Y', 1), Map.entry('Q', 0), Map.entry('X', 0)
);
static boolean isVowel(char ch) {
return ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U';
}
static int crossabilityScore(String w) {
var score = 0;
var vowels = 0;
for (var i = 0; i < w.length(); i++) {
var ch = w.charAt(i);
score += LETTER_WEIGHT.getOrDefault(ch, 2);
if (isVowel(ch)) vowels++;
}
var ratio = vowels / (double) w.length();
if (ratio >= 0.35 && ratio <= 0.65) score += 8;
if (w.indexOf('Q') >= 0 || w.indexOf('X') >= 0) score -= 6;
if (w.indexOf('Y') >= 0 || w.indexOf('J') >= 0) score -= 2;
return score;
}
/**
* Updates hints.cross_score by computing a score from hints.word.
*
@@ -83,10 +112,4 @@ public final class HintScores {
conn.setAutoCommit(prevAutoCommit);
}
}
// Example scoring callback
public static int exampleScore(String word) {
return ThemePoolBuilderLength.crossabilityScore(word);
}
}