Skip to content

Commit

Permalink
Make safe-storage work (fix #179)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcreedcmu committed Mar 5, 2024
1 parent bb6da89 commit 11ffa75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/core/grid.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DEBUG } from "../util/debug";
import { Point, Rect } from "../util/types";
import { boundRect } from "../util/util";
import { boundRect, mapval } from "../util/util";
import { vtrans } from "../util/vutil";
import { AbstractLetter, stringOfLetter } from "./letters";
import { MainTile, TileNoId } from './state-types';
Expand Down Expand Up @@ -231,3 +231,7 @@ export function gridKeys<T>(x: UbGrid<T>): Point[] {
export function unionGrids<T>(x: UbGrid<T>, y: UbGrid<T>): UbGrid<T> {
return { elems: { ...x.elems, ...y.elems } };
}

export function mapGrid<T, U>(x: UbGrid<T>, f: (x: T) => U): UbGrid<U> {
return { elems: mapval(x.elems, f) };
}
6 changes: 4 additions & 2 deletions src/core/state-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { PauseData, WORD_BONUS_INTERVAL_MS, now_in_game } from "./clock";
import { DrawForce, getLetterSample } from "./distribution";
import { updateFogOfWar } from "./fog-of-war";
import { freshPanic } from "./fresh-panic";
import { checkConnected, checkGridWords, gridKeys, mkGridOfMainTiles } from "./grid";
import { checkConnected, checkGridWords, gridKeys, mapGrid, mkGridOfMainTiles, unionGrids } from "./grid";
import { mkOverlayFrom, overlayAny, overlayPoints, setOverlay } from "./layer";
import { AbstractLetter } from "./letters";
import { addRandomMob } from "./mob-helpers";
Expand Down Expand Up @@ -156,7 +156,9 @@ export function checkValid(state: CoreState): CoreState {
const oldConnectedSet = state.connectedSet;

const { validWords, invalidWords } = checkGridWords(grid, word => getAssets().dictionary[word] || DEBUG.allWords);
const { allConnected, connectedSet } = checkConnected(grid);
const { allConnected, connectedSet: realConnectedSet } = checkConnected(grid);
const connectedSet = unionGrids(realConnectedSet, mapGrid(mkGridOfMainTiles(safeTiles), _ => true));

let allValid = false;
if (invalidWords.length == 0 && allConnected && get_hand_tiles(state).length == 0) {
state = resolveValid(state, new Set(validWords.map(x => x.word)));
Expand Down

0 comments on commit 11ffa75

Please sign in to comment.