Skip to content

Commit

Permalink
Fix running models with mocked data
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy committed Nov 2, 2024
1 parent f0329d1 commit 9886c47
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
19 changes: 16 additions & 3 deletions convex/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,23 @@ export const playMapAction = internalAction({

if (process.env.FLAG_MOCK_MODELS === "true") {
const existingMap = ZombieSurvival.cloneMap(map.grid);
const playerPosition = ZombieSurvival.nextValidPosition(existingMap);

existingMap[0][0] = "P";
existingMap[0][1] = "B";
existingMap[0][2] = "B";
if (playerPosition !== null) {
existingMap[playerPosition.y][playerPosition.x] = "P";
}

const firstBoxPosition = ZombieSurvival.nextValidPosition(existingMap);

if (firstBoxPosition !== null) {
existingMap[firstBoxPosition.y][firstBoxPosition.x] = "B";
}

const secondBoxPosition = ZombieSurvival.nextValidPosition(existingMap);

if (secondBoxPosition !== null) {
existingMap[secondBoxPosition.y][secondBoxPosition.x] = "B";
}

await ctx.runMutation(internal.results.updateResult, {
resultId,
Expand Down
12 changes: 12 additions & 0 deletions simulators/zombie-survival/ZombieSurvival.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ export class ZombieSurvival {
return map.length === 0 || map[0].length === 0;
}

public static nextValidPosition(map: string[][]): Position | null {
for (let y = 0; y < map.length; y++) {
for (let x = 0; x < map[y].length; x++) {
if (map[y][x] === " ") {
return { x, y };
}
}
}

return null;
}

public static validLocations(map: string[][]): number[][] {
return map.flatMap((row, y) =>
row.reduce((acc, cell, x) => {
Expand Down

0 comments on commit 9886c47

Please sign in to comment.