Add some mitigations against blank letter bug

This commit is contained in:
Joel Therrien 2023-10-13 21:16:30 -07:00
parent 7d6e7d0113
commit 22d7ce969e
5 changed files with 822 additions and 651 deletions

1445
ui/package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -47,6 +47,7 @@ export function Game(props: {
const [isGameOver, setGameOver] = useState<boolean>(false); const [isGameOver, setGameOver] = useState<boolean>(false);
const [confirmedScorePoints, setConfirmedScorePoints] = useState<number>(-1); const [confirmedScorePoints, setConfirmedScorePoints] = useState<number>(-1);
const [isResetTrayButtonEnabled, setIsResetTrayButtonEnabled] = useState<boolean>(false);
const [boardLetters, setBoardLetters] = useState<HighlightableLetterData[]>(() => { const [boardLetters, setBoardLetters] = useState<HighlightableLetterData[]>(() => {
const newLetterData = [] as HighlightableLetterData[]; const newLetterData = [] as HighlightableLetterData[];
@ -150,6 +151,10 @@ export function Game(props: {
let tray: Tray = props.wasm.get_tray("Player"); let tray: Tray = props.wasm.get_tray("Player");
if(update.override) {
playerLetters = [];
}
return mergeTrays(playerLetters, tray.letters); return mergeTrays(playerLetters, tray.letters);
} else if (update.action === TileDispatchActionType.MOVE) { } else if (update.action === TileDispatchActionType.MOVE) {
@ -171,8 +176,17 @@ export function Game(props: {
setConfirmedScorePoints(-1); setConfirmedScorePoints(-1);
return playerLetters.slice(); return playerLetters.slice();
} if (update.action === TileDispatchActionType.SET_BLANK) { } else if (update.action === TileDispatchActionType.SET_BLANK) {
const blankLetter = playerLetters[update.blankIndex]; const blankLetter = playerLetters[update.blankIndex];
// FIXME DEBUG code
if(blankLetter == null || !blankLetter.is_blank){
window.alert("Bug was triggered!! Doing nothing.");
console.warn({playerLetters});
setIsResetTrayButtonEnabled(true);
return playerLetters.slice();
}
if(blankLetter.text !== update.newBlankValue) { if(blankLetter.text !== update.newBlankValue) {
blankLetter.text = update.newBlankValue; blankLetter.text = update.newBlankValue;
if (blankLetter.location == LocationType.GRID) { if (blankLetter.location == LocationType.GRID) {
@ -517,6 +531,13 @@ export function Game(props: {
} }
} }
}}>Pass</button> }}>Pass</button>
{isResetTrayButtonEnabled && <button onClick={() => {
trayDispatch({action: TileDispatchActionType.RETRIEVE, override: true});
setConfirmedScorePoints(-1);
}}>
Reset Tray
</button>}
</div> </div>
</div> </div>

View file

@ -65,6 +65,7 @@ export function Menu(props: {settings: Settings, dictionary_text: string}) {
<div className="selection-buttons"> <div className="selection-buttons">
<button onClick={() => { <button onClick={() => {
const seed = new Date().getTime(); const seed = new Date().getTime();
//const seed = 136; // seed for starting with a blank
const difficulty: Difficulty = { const difficulty: Difficulty = {
proportion: processedProportionDictionary, proportion: processedProportionDictionary,
randomness: processedAIRandomness, randomness: processedAIRandomness,

View file

@ -141,7 +141,7 @@ export function TileTray(props: { letters: Array<PlayableLetterData>, trayLength
props.trayDispatch({action: TileDispatchActionType.SET_BLANK, blankIndex: i, newBlankValue: value}) props.trayDispatch({action: TileDispatchActionType.SET_BLANK, blankIndex: i, newBlankValue: value})
}} }}
/>} />}
key={"letter" + letter.index} key={"letter_tray" + letter.index}
location={{location: LocationType.TRAY, index: letter.index}} location={{location: LocationType.TRAY, index: letter.index}}
tileDispatch={props.trayDispatch} /> tileDispatch={props.trayDispatch} />

View file

@ -37,7 +37,7 @@ export enum TileDispatchActionType {
RETURN, RETURN,
MOVE_TO_ARROW, MOVE_TO_ARROW,
} }
export type TileDispatchAction = {action: TileDispatchActionType, start?: CoordinateData, end?: CoordinateData, newBlankValue?: string, blankIndex?: number}; export type TileDispatchAction = {action: TileDispatchActionType, start?: CoordinateData, end?: CoordinateData, newBlankValue?: string, blankIndex?: number, override?: boolean};
export type TileDispatch = React.Dispatch<TileDispatchAction>; export type TileDispatch = React.Dispatch<TileDispatchAction>;
export enum Direction { export enum Direction {