From eaf49713c3cfa24703d6fe67bbb45c4d9982e122 Mon Sep 17 00:00:00 2001 From: Cody Seibert Date: Tue, 15 Oct 2024 23:31:40 -0400 Subject: [PATCH] add reset --- app/games/[gameId]/visualizer.tsx | 55 ++++++++++++++++++++----------- convex/openai.ts | 4 ++- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/app/games/[gameId]/visualizer.tsx b/app/games/[gameId]/visualizer.tsx index 5bde609..2f41a5e 100644 --- a/app/games/[gameId]/visualizer.tsx +++ b/app/games/[gameId]/visualizer.tsx @@ -9,6 +9,7 @@ export function Visualizer({ map }: { map: string[][] }) { const interval = useRef(null); const [isRunning, setIsRunning] = useState(false); const [mapState, setMapState] = useState(map); + const [needsReset, setNeedsReset] = useState(false); return (
@@ -24,27 +25,41 @@ export function Visualizer({ map }: { map: string[][] }) { ))}
))} - + setIsRunning(true); + interval.current = setInterval(() => { + if (simulator.current!.finished()) { + clearInterval(interval.current!); + interval.current = null; + setIsRunning(false); + return; + } + simulator.current!.step(); + setMapState(simulator.current!.getState()); + }, REPLAY_SPEED); + }} + disabled={isRunning} + > + Play + + + ); } diff --git a/convex/openai.ts b/convex/openai.ts index 1dd48c0..066a8d8 100644 --- a/convex/openai.ts +++ b/convex/openai.ts @@ -68,7 +68,9 @@ export const playMapAction = internalAction({ "R" represents rocks, which players can shoot over but zombies cannot pass through or break. "P" represents the player, who cannot move. The player's goal is to shoot and kill zombies before they reach them. "B" represents blocks that can be placed before the round begins to hinder the zombies. You can place up to two blocks on the map. - Your goal is to place the player ("P") and two blocks ("B") in locations that maximize the player's survival by delaying the zombies' approach while allowing the player clear lines of sight to shoot them before they get too close. + + Your goal is to place the player ("P") and two blocks ("B") in locations that maximize the player's survival by delaying the zombies' approach. + You can shoot any zombie regardless of where it is on the grid. Returning a 2d grid with the player and blocks placed in the optimal locations, with the coordinates player ("P") and the blocks ("B"), also provide reasoning for the choices. You can't replace rocks R or zombies Z with blocks. If there is no room to place a block, do not place any.`,