mirror of
https://github.com/sigmasternchen/x86-64-wordle
synced 2025-03-14 23:59:00 +00:00
feat: Select random word from list
This commit is contained in:
parent
4c3c44f95e
commit
25a76e90fe
2 changed files with 36 additions and 1 deletions
|
@ -5,6 +5,10 @@ import {id, objectMap, zip} from "../utils";
|
|||
import {Keyboard} from "./Keyboard";
|
||||
import {CellState, sortCellStates} from "../model/CellState";
|
||||
import {Toast} from "./Toast";
|
||||
import dictionary from "../data/dictionary.json"
|
||||
import {newSFC32} from "../random/sfc32";
|
||||
|
||||
const validWordsRegex = /[A-Z]+/;
|
||||
|
||||
export const App = () => {
|
||||
const [pastGuesses, setPastGuesses] = useState([]);
|
||||
|
@ -13,9 +17,16 @@ export const App = () => {
|
|||
const [message, setMessage] = useState("");
|
||||
|
||||
const length = 5;
|
||||
const correct = "guess";
|
||||
const availableWords = dictionary
|
||||
.filter(word => validWordsRegex.test(word))
|
||||
.filter(word => word.length === length);
|
||||
|
||||
const today = Date.now() / 1000 / 60 / 60 / 24;
|
||||
const random = newSFC32(today);
|
||||
|
||||
const correct = availableWords[Math.floor(random() * availableWords.length)];
|
||||
|
||||
console.log(correct)
|
||||
|
||||
const fieldDataForPastGuesses = pastGuesses
|
||||
.map(guess => guess.toUpperCase())
|
||||
|
|
24
src/random/sfc32.js
Normal file
24
src/random/sfc32.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
export const newSFC32 = seed => {
|
||||
// see https://github.com/bryc/code/blob/master/jshash/PRNGs.md#sfc32
|
||||
|
||||
let a = 0 | 0;
|
||||
let b = seed >> 0;
|
||||
let c = seed >> 16; // crutch because JS doesn't have 64 bit ints
|
||||
let d = 1 | 0;
|
||||
|
||||
const next = () => {
|
||||
let t = (a + b | 0) + d | 0;
|
||||
d = d + 1 | 0;
|
||||
a = b ^ b >>> 9;
|
||||
b = c + (c << 3) | 0;
|
||||
c = c << 21 | c >>> 11;
|
||||
c = c + t | 0;
|
||||
return (t >>> 0) / 4294967296;
|
||||
}
|
||||
|
||||
for (let i = 0; i < 12; i++) {
|
||||
next();
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
Loading…
Reference in a new issue