mirror of
https://github.com/sigmasternchen/x86-64-wordle
synced 2025-03-15 08:09:01 +00:00
feat: Add distinction between empty and unknown
This commit is contained in:
parent
cb21280e85
commit
121866e86a
5 changed files with 38 additions and 29 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
.idea
|
||||||
|
node_modules
|
|
@ -32,8 +32,13 @@ body {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cell.Empty {
|
||||||
|
background-color: black;
|
||||||
|
}
|
||||||
|
|
||||||
.cell.Unknown {
|
.cell.Unknown {
|
||||||
background-color: black;
|
background-color: black;
|
||||||
|
border: 1px solid #888;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cell.Wrong {
|
.cell.Wrong {
|
||||||
|
|
|
@ -13,6 +13,33 @@ export const App = () => {
|
||||||
|
|
||||||
const [currentGuess, setCurrentGuess] = React.useState("");
|
const [currentGuess, setCurrentGuess] = React.useState("");
|
||||||
|
|
||||||
|
const fieldDataForPastGuesses = pastGuesses
|
||||||
|
.map(guess => guess.toUpperCase())
|
||||||
|
.map(guess => [
|
||||||
|
guess.split(""),
|
||||||
|
calculateDifference(correct.toUpperCase(), guess)
|
||||||
|
])
|
||||||
|
.map(([guess, difference]) => zip(guess, difference))
|
||||||
|
.map(guessWithDifference => guessWithDifference
|
||||||
|
.map(([content, state]) => ({
|
||||||
|
state: state,
|
||||||
|
content: content,
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
const usedWithState = objectMap(
|
||||||
|
Object.groupBy(
|
||||||
|
fieldDataForPastGuesses
|
||||||
|
.flatMap(id)
|
||||||
|
.flatMap(id),
|
||||||
|
cell => cell.content
|
||||||
|
),
|
||||||
|
states => states
|
||||||
|
.map(state => state.state)
|
||||||
|
.toSorted(sortCellStates)
|
||||||
|
.at(-1)
|
||||||
|
);
|
||||||
|
|
||||||
const inputHandler = key => {
|
const inputHandler = key => {
|
||||||
if (currentGuess.length > 0 && key === "BACK") {
|
if (currentGuess.length > 0 && key === "BACK") {
|
||||||
setCurrentGuess(currentGuess.substring(0, currentGuess.length - 1));
|
setCurrentGuess(currentGuess.substring(0, currentGuess.length - 1));
|
||||||
|
@ -28,33 +55,6 @@ export const App = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fieldDataForPastGuesses = pastGuesses
|
|
||||||
.map(guess => guess.toUpperCase())
|
|
||||||
.map(guess => [
|
|
||||||
guess.split(""),
|
|
||||||
calculateDifference(correct.toUpperCase(), guess)
|
|
||||||
])
|
|
||||||
.map(([guess, difference]) => zip(guess, difference))
|
|
||||||
.map(guessWithDifference => guessWithDifference
|
|
||||||
.map(([content, state]) => ({
|
|
||||||
state: state,
|
|
||||||
content: content,
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
|
|
||||||
const used = objectMap(
|
|
||||||
Object.groupBy(
|
|
||||||
fieldDataForPastGuesses
|
|
||||||
.flatMap(id)
|
|
||||||
.flatMap(id),
|
|
||||||
cell => cell.content
|
|
||||||
),
|
|
||||||
states => states
|
|
||||||
.map(state => state.state)
|
|
||||||
.toSorted(sortCellStates)
|
|
||||||
.at(-1)
|
|
||||||
);
|
|
||||||
|
|
||||||
const fieldData = fieldDataForPastGuesses
|
const fieldData = fieldDataForPastGuesses
|
||||||
.concat([currentGuess
|
.concat([currentGuess
|
||||||
.split("")
|
.split("")
|
||||||
|
@ -70,6 +70,6 @@ export const App = () => {
|
||||||
size={[5, 6]}
|
size={[5, 6]}
|
||||||
fieldData={fieldData}
|
fieldData={fieldData}
|
||||||
/>
|
/>
|
||||||
<Keyboard used={used} onKey={inputHandler}/>
|
<Keyboard used={usedWithState} onKey={inputHandler}/>
|
||||||
</div>
|
</div>
|
||||||
};
|
};
|
|
@ -10,7 +10,7 @@ export const Field = ({size, fieldData}) => {
|
||||||
range(size[1]).map(y =>
|
range(size[1]).map(y =>
|
||||||
range(size[0]).map(x => (
|
range(size[0]).map(x => (
|
||||||
<Cell
|
<Cell
|
||||||
state={fieldData?.[y]?.[x]?.state ?? CellState.Unknown}
|
state={fieldData?.[y]?.[x]?.state ?? CellState.Empty}
|
||||||
content={fieldData?.[y]?.[x]?.content ?? " "}
|
content={fieldData?.[y]?.[x]?.content ?? " "}
|
||||||
/>
|
/>
|
||||||
)).concat([<br />])
|
)).concat([<br />])
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {makeEnum} from "../utils";
|
import {makeEnum} from "../utils";
|
||||||
|
|
||||||
export const CellState = makeEnum([
|
export const CellState = makeEnum([
|
||||||
|
"Empty",
|
||||||
"Unknown",
|
"Unknown",
|
||||||
"Wrong",
|
"Wrong",
|
||||||
"HalfRight",
|
"HalfRight",
|
||||||
|
@ -9,6 +10,7 @@ export const CellState = makeEnum([
|
||||||
|
|
||||||
const cellStateOrder = (cellState) => {
|
const cellStateOrder = (cellState) => {
|
||||||
switch (cellState) {
|
switch (cellState) {
|
||||||
|
case CellState.Empty: return 0;
|
||||||
case CellState.Unknown: return 0;
|
case CellState.Unknown: return 0;
|
||||||
case CellState.Wrong: return 1;
|
case CellState.Wrong: return 1;
|
||||||
case CellState.HalfRight: return 2;
|
case CellState.HalfRight: return 2;
|
||||||
|
|
Loading…
Reference in a new issue