diff --git a/convex/maps.ts b/convex/maps.ts index 6d2d285..d4c5088 100644 --- a/convex/maps.ts +++ b/convex/maps.ts @@ -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, diff --git a/simulators/zombie-survival/ZombieSurvival.ts b/simulators/zombie-survival/ZombieSurvival.ts index ee3c973..88f374b 100644 --- a/simulators/zombie-survival/ZombieSurvival.ts +++ b/simulators/zombie-survival/ZombieSurvival.ts @@ -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) => {