diff --git a/app/__tests__/builderReducer.test.ts b/app/__tests__/builderReducer.test.ts index 0a2b53ab..9ef5cab6 100644 --- a/app/__tests__/builderReducer.test.ts +++ b/app/__tests__/builderReducer.test.ts @@ -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'], { diff --git a/app/reducers/builderReducer.ts b/app/reducers/builderReducer.ts index 4f23565e..059002b0 100644 --- a/app/reducers/builderReducer.ts +++ b/app/reducers/builderReducer.ts @@ -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 diff --git a/app/reducers/builderUtils.ts b/app/reducers/builderUtils.ts index 8401139d..1f3d6e6d 100644 --- a/app/reducers/builderUtils.ts +++ b/app/reducers/builderUtils.ts @@ -81,13 +81,25 @@ export function getWarningStats(state: BuilderState) { const { clues, grid } = state; const { entries, sortedEntries } = grid; - const shortWords = new Set(); + const shortWords = new Set(); - 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(); + +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(); const missingEnums = new Set(); @@ -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 {