Skip to content

Commit

Permalink
fix some merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutoshbind15 committed Oct 17, 2024
2 parents 2ee4027 + 9ea8a17 commit 306e94d
Show file tree
Hide file tree
Showing 23 changed files with 749 additions and 306 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Add optional environment variable/s for simulating real AI models without mockup

- `npx convex env set GEMINI_API_KEY YOUR_API_KEY`
- `npx convex env set OPENAI_API_KEY YOUR_API_KEY`
- `npx convex env set ANTHROPIC_API_KEY YOUR_API_KEY`
- `npx convex env set PERPLEXITY_API_KEY YOUR_API_KEY`

also, you may need to run, but I think the initial setup does that.

Expand Down
2 changes: 1 addition & 1 deletion app/games/[gameId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function GamePage({ params }: { params: { gameId: string } }) {
});

return (
<div className="container mx-auto min-h-screen flex flex-col items-center py-12 pb-24 gap-8">
<div className="container mx-auto max-w-5xl min-h-screen flex flex-col items-center py-12 pb-24 gap-8">
<h1>Game {params.gameId}</h1>
<h2>Model: {game?.modelId}</h2>

Expand Down
14 changes: 9 additions & 5 deletions app/games/[gameId]/result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ export const Result = ({ result }: { result: Doc<"results"> }) => {
return <div>Game in progress...</div>;
}

if (result.status === "failed") {
return <div className="text-red-500">{result.error}</div>;
}

return (
<div className="flex items-center gap-8">
<Link
Expand All @@ -32,7 +28,15 @@ export const Result = ({ result }: { result: Doc<"results"> }) => {
>
Level {map.level}
</Link>
<Visualizer map={result.map} autoStart={true} />

{result.status === "failed" ? (
<div className="text-red-500 w-[200px] flex-shrink-0">
{result.error}
</div>
) : (
<Visualizer map={result.map} autoStart={true} />
)}

<div className="flex flex-col">
<ResultStatus result={result} />
{result.reasoning !== "" && <p>{result.reasoning}</p>}
Expand Down
7 changes: 6 additions & 1 deletion app/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export default function Header() {
<Link href="/leaderboard">
<Button variant="ghost">Leaderboard</Button>
</Link>
{isAuthenticated && (
<Link href="/maps">
<Button variant="ghost">Submit Map</Button>
</Link>
)}
{flags?.showTestPage && (
<Link href="/test">
<Button variant="ghost">Test</Button>
Expand All @@ -61,7 +66,7 @@ export default function Header() {
<Image src="/convex.svg" alt="Convex" width={24} height={24} />
</Link>

<div className="flex hover:bg-slate-500 rounded-md px-1">
<div className="">
<ThemeToggle />
</div>
{!isAuthenticated ? (
Expand Down
175 changes: 175 additions & 0 deletions app/maps/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
"use client";

import { Input } from "@/components/ui/input";
import React, { useEffect, useState } from "react";
import { Button } from "@/components/ui/button";
import { useMutation } from "convex/react";
import { api } from "@/convex/_generated/api";

export default function AddMapPage() {
const [height, setHeight] = useState(1);
const [width, setWidth] = useState(1);
const [map, setMap] = useState<string[][]>([]);
const [isSubmitted, setIsSubmitted] = useState(false);
const [isZombie, setIsZombie] = useState(false);
const createMap = useMutation(api.maps.addMap);
useEffect(() => {
generateMap();
}, [height, width]);

const generateMap = () => {
const newMap = Array.from({ length: height }, () =>
Array.from({ length: width }, () => " "),
);
newMap.forEach((row, y) => {
row.forEach((cell, x) => {
newMap[y][x] = " ";
});
});
setMap(newMap);
};
const checkValidMap = () => {
var flag = false;
map.forEach((row, y) => {
row.forEach((cell, x) => {
if (map[y][x] == " ") {
console.log("All well!");
flag = true;
}
});
});
console.log(map);
if (!flag) {
console.log("All set");
console.log(map);
alert("No place left to place the player!");
} else {
createMap({ grid: map });
alert("Map saved");
}
};
const setCell = (y: number, x: number, z: boolean) => {
var cell = " ";
if (z == true) {
if (map[y][x] == "Z") {
cell = " ";
} else {
cell = "Z";
}
} else {
if (map[y][x] == "B") {
cell = " ";
} else {
cell = "R";
}
}
const newMap = map.map((row) => [...row]);
newMap[y][x] = cell;
setMap(newMap);
};
return (
<div className="container mx-auto min-h-screen py-12 pb-24 gap-8">
<h1 className="text-center text-3xl font-semibold mb-6">Submit Map</h1>

{isSubmitted ? (
<div>
<div className="flex justify-center m-5">
<Button
className="mx-2"
variant={isZombie ? "default" : "outline"}
onClick={() => setIsZombie(true)}
>
Place Zombie
</Button>
<Button
className="mx-2"
variant={isZombie ? "outline" : "default"}
onClick={() => setIsZombie(false)}
>
Place Rock
</Button>
</div>
<div className="justify-center m-5">
{map.map((row, y) => (
<div key={y} className="flex justify-center">
{row.map((cell, x) => (
<div
key={x}
className={`size-8 border flex items-center justify-center text-2xl p-5`}
>
<Button
className="m-5"
variant="outline"
onClick={() => {
setCell(y, x, isZombie);
}}
>
{map[y][x]}
</Button>
</div>
))}
</div>
))}
</div>
</div>
) : (
<div>
<h1>Enter the height of the map: </h1>
<Input
type="number"
value={height}
onChange={(e) => {
setHeight(+e.target.value);
}}
/>
<h1>Enter the width of the map: </h1>
<Input
type="number"
value={width}
onChange={(e) => {
setWidth(+e.target.value);
}}
/>
<div className="justify-center m-5">
{map.map((row, y) => (
<div key={y} className="flex justify-center">
{row.map((cell, x) => (
<div
key={x}
className={`size-8 border flex items-center justify-center text-2xl`}
>
{cell}
</div>
))}
</div>
))}
</div>
</div>
)}
<div className="flex justify-center m-5">
{isSubmitted ? (
<div>
<Button className="mx-2" type="submit" onClick={checkValidMap}>
Save map
</Button>
<Button
className="mx-2"
variant="destructive"
onClick={() => {
setIsSubmitted(false);
map.fill([]);
generateMap();
}}
>
Reset
</Button>
</div>
) : (
<Button type="submit" onClick={() => setIsSubmitted(true)}>
Confirm grid
</Button>
)}
</div>
</div>
);
}
Loading

0 comments on commit 306e94d

Please sign in to comment.