Skip to content

Commit

Permalink
add reset
Browse files Browse the repository at this point in the history
  • Loading branch information
webdevcody committed Oct 16, 2024
1 parent 4cff246 commit eaf4971
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
55 changes: 35 additions & 20 deletions app/games/[gameId]/visualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function Visualizer({ map }: { map: string[][] }) {
const interval = useRef<NodeJS.Timeout | null>(null);
const [isRunning, setIsRunning] = useState(false);
const [mapState, setMapState] = useState(map);
const [needsReset, setNeedsReset] = useState(false);

return (
<div>
Expand All @@ -24,27 +25,41 @@ export function Visualizer({ map }: { map: string[][] }) {
))}
</div>
))}
<Button
onClick={() => {
const clonedMap = JSON.parse(JSON.stringify(map));
simulator.current = new ZombieSurvival(clonedMap);
setMapState(simulator.current!.getState());
setIsRunning(true);
interval.current = setInterval(() => {
if (simulator.current!.finished()) {
clearInterval(interval.current!);
interval.current = null;
setIsRunning(false);
return;
}
simulator.current!.step();
<div className="flex gap-2 justify-center py-2">
<Button
onClick={() => {
setNeedsReset(true);
const clonedMap = JSON.parse(JSON.stringify(map));
simulator.current = new ZombieSurvival(clonedMap);
setMapState(simulator.current!.getState());
}, REPLAY_SPEED);
}}
disabled={isRunning}
>
Play
</Button>
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
</Button>
<Button
disabled={isRunning}
onClick={() => {
simulator.current = new ZombieSurvival(map);
setMapState(simulator.current!.getState());
setIsRunning(false);
setNeedsReset(false);
}}
>
Reset
</Button>
</div>
</div>
);
}
4 changes: 3 additions & 1 deletion convex/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
Expand Down

0 comments on commit eaf4971

Please sign in to comment.