-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b9c3c9c
commit 1e843eb
Showing
15 changed files
with
343 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const AI_MODELS = [ | ||
{ | ||
model: "gpt-4o", | ||
name: "OpenAI - 4o Mini", | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,117 @@ | ||
import MapTester from "@/components/MapTester"; | ||
import { Map } from "./map"; | ||
"use client"; | ||
|
||
import { CELL_SIZE, Map } from "./map"; | ||
import { api } from "@/convex/_generated/api"; | ||
import { useAction } from "convex/react"; | ||
import React, { useState } from "react"; | ||
import { Button } from "@/components/ui/button"; | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectItem, | ||
SelectTrigger, | ||
SelectValue, | ||
} from "@/components/ui/select"; | ||
import { AI_MODELS } from "@/app/constants"; | ||
import { Loader2 } from "lucide-react"; | ||
|
||
const hardCodedMapTemp = [ | ||
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "], | ||
[" ", " ", " ", "P", "B", " ", " ", " ", " ", " "], | ||
[" ", " ", " ", " ", "B", " ", " ", " ", " ", " "], | ||
["R", "R", "R", "R", " ", " ", " ", " ", " ", " "], | ||
[" ", " ", " ", " ", " ", " ", " ", " ", "Z", " "], | ||
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "], | ||
[" ", " ", " ", " ", " ", " ", " ", "R", " ", " "], | ||
["R", "R", "R", "R", " ", " ", " ", "R", " ", " "], | ||
[" ", " ", " ", " ", " ", " ", " ", "R", "Z", " "], | ||
[" ", " ", " ", " ", " ", " ", " ", "R", " ", " "], | ||
[" ", "Z", " ", " ", " ", " ", " ", " ", " ", " "], | ||
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "], | ||
[" ", " ", " ", " ", " ", " ", " ", " ", " ", " "], | ||
]; | ||
|
||
export default function MainPage() { | ||
const getPlayerMap = useAction(api.openai.playMapAction); | ||
const [resMap, setResMap] = useState<null | string[][]>(null); | ||
const [loading, setLoading] = useState(false); | ||
const [model, setModel] = useState(AI_MODELS[0].model); | ||
|
||
const handleClick = async () => { | ||
setLoading(true); | ||
try { | ||
const res = await getPlayerMap({ | ||
level: 1, | ||
mapId: "zombiemap", | ||
map: hardCodedMapTemp, | ||
}); | ||
|
||
console.log(res); | ||
setResMap(res?.map || []); | ||
} catch (error) { | ||
console.error(error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
const mapWidth = hardCodedMapTemp[0].length * CELL_SIZE; | ||
const mapHeight = hardCodedMapTemp.length * CELL_SIZE; | ||
console.log(mapWidth, mapHeight); | ||
|
||
return ( | ||
<div className="min-h-screen flex flex-col items-center justify-center"> | ||
<Map map={hardCodedMapTemp} /> | ||
<MapTester map={hardCodedMapTemp} /> | ||
<div className="container mx-auto min-h-screen flex flex-col items-center pt-12 gap-8"> | ||
<h1 className="text-4xl font-bold mb-8">Zombie Map Simulator</h1> | ||
|
||
<div className="flex gap-8 items-start w-full"> | ||
<div className="flex flex-col items-center flex-grow"> | ||
<h2 className="text-2xl font-semibold mb-4">Initial Map</h2> | ||
<Map map={hardCodedMapTemp} /> | ||
</div> | ||
|
||
<div className="flex flex-col items-center justify-between h-full pt-12"> | ||
<div className="flex flex-col items-center gap-4"> | ||
<Select value={model} onValueChange={(value) => setModel(value)}> | ||
<SelectTrigger className="w-[180px]"> | ||
<SelectValue placeholder="Select model" /> | ||
</SelectTrigger> | ||
<SelectContent> | ||
{AI_MODELS.map((model) => ( | ||
<SelectItem key={model.model} value={model.model}> | ||
{model.name} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
<Button onClick={handleClick} disabled={loading}> | ||
Run Simulation | ||
</Button> | ||
</div> | ||
</div> | ||
|
||
<div className="flex flex-col items-center justify-center flex-grow"> | ||
<h2 className="text-2xl font-semibold mb-4">AI Result</h2> | ||
{loading ? ( | ||
<div | ||
style={{ | ||
width: `${mapWidth}px`, | ||
height: `${mapHeight}px`, | ||
}} | ||
className={`flex items-center justify-center`} | ||
> | ||
<Loader2 className="h-8 w-8 animate-spin" /> | ||
</div> | ||
) : resMap ? ( | ||
<Map map={resMap} /> | ||
) : ( | ||
<div | ||
style={{ | ||
width: `${mapWidth}px`, | ||
height: `${mapHeight}px`, | ||
}} | ||
className={`border-2 border-dashed border-gray-300 flex items-center justify-center text-gray-400`} | ||
> | ||
Run simulation to see results | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.