Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/__tests__/builderReducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,18 @@ test('short word warning', () => {
]
`);
});
test('isolated cell warning', () => {
const state = getState(
['a', 'b', 'c', 'd', 'e', '.', 'f', '.', 'g'],
{}
);

expect(builderReducer(state, publish).publishWarnings).toMatchInlineSnapshot(`
[
"Some cells are not part of any word",
]
`);
});

test('basic enum warnings', () => {
const state = getState(['a', 'b', 'c', 'g', '', '', 'd', 'e', 'f'], {
Expand Down
3 changes: 3 additions & 0 deletions app/reducers/builderReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,9 @@ function _builderReducer(
Array.from(stats.shortWords).sort().join(', ') +
')'
);
if (stats.isolatedCells.size > 0) {
warnings.push('Some cells are not part of any word');
}
}
if (stats.hasUnches) {
warnings.push('UNCHES'); // A bit of a hack but PublishWarningsList handles rendering this one
Expand Down
37 changes: 25 additions & 12 deletions app/reducers/builderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,25 @@ export function getWarningStats(state: BuilderState) {
const { clues, grid } = state;
const { entries, sortedEntries } = grid;

const shortWords = new Set<string>();
const shortWords = new Set<string>();

for (const [i, entry] of entries.entries()) {
if (entry.completedWord && entry.completedWord.length <= 2) {
shortWords.add(entryWord(grid, i));
}
for (const [i, entry] of entries.entries()) {
if (entry.completedWord && entry.completedWord.length <= 2) {
shortWords.add(entryWord(grid, i));
}
}

const isolatedCells = new Set<number>();

for (const [i, cellEntries] of grid.entriesByCell.entries()) {
if (
grid.cells[i] !== '.' &&
cellEntries[0].entryIndex === null &&
cellEntries[1].entryIndex === null
) {
isolatedCells.add(i);
}
}

const unmatchedRefs = new Set<string>();
const missingEnums = new Set<string>();
Expand Down Expand Up @@ -128,13 +140,14 @@ export function getWarningStats(state: BuilderState) {
});
const enumsExpected = missingEnums.size < numValidClues / 2;

return {
shortWords,
hasUnches: hasUnches(grid) && !state.userTags.includes('cryptic'),
unmatchedRefs,
missingEnums: enumsExpected ? missingEnums : null,
wrongEnums: enumsExpected ? wrongEnums : null,
};
return {
shortWords,
isolatedCells,
hasUnches: hasUnches(grid) && !state.userTags.includes('cryptic'),
unmatchedRefs,
missingEnums: enumsExpected ? missingEnums : null,
wrongEnums: enumsExpected ? wrongEnums : null,
};
}

export function hasSelection(state: GridInterfaceState): boolean {
Expand Down