From 67d2e20605bf76b7e9c0c87c742d3c0d7dae9849 Mon Sep 17 00:00:00 2001 From: MZT7 <40639877+MZT7@users.noreply.github.com> Date: Fri, 1 Nov 2024 22:08:35 +0100 Subject: [PATCH 1/6] update --- convex/_generated/api.d.ts | 4 ---- convex/_generated/api.js | 4 ---- convex/_generated/dataModel.d.ts | 4 ---- convex/_generated/server.d.ts | 4 ---- convex/_generated/server.js | 4 ---- 5 files changed, 20 deletions(-) diff --git a/convex/_generated/api.d.ts b/convex/_generated/api.d.ts index 7ed685a..3f64db7 100644 --- a/convex/_generated/api.d.ts +++ b/convex/_generated/api.d.ts @@ -1,5 +1,3 @@ -/* prettier-ignore-start */ - /* eslint-disable */ /** * Generated `api` utility. @@ -66,5 +64,3 @@ export declare const internal: FilterApi< typeof fullApi, FunctionReference >; - -/* prettier-ignore-end */ diff --git a/convex/_generated/api.js b/convex/_generated/api.js index b5f2e08..3f9c482 100644 --- a/convex/_generated/api.js +++ b/convex/_generated/api.js @@ -1,5 +1,3 @@ -/* prettier-ignore-start */ - /* eslint-disable */ /** * Generated `api` utility. @@ -22,5 +20,3 @@ import { anyApi } from "convex/server"; */ export const api = anyApi; export const internal = anyApi; - -/* prettier-ignore-end */ diff --git a/convex/_generated/dataModel.d.ts b/convex/_generated/dataModel.d.ts index 91445df..8541f31 100644 --- a/convex/_generated/dataModel.d.ts +++ b/convex/_generated/dataModel.d.ts @@ -1,5 +1,3 @@ -/* prettier-ignore-start */ - /* eslint-disable */ /** * Generated data model types. @@ -60,5 +58,3 @@ export type Id = * `mutationGeneric` to make them type-safe. */ export type DataModel = DataModelFromSchemaDefinition; - -/* prettier-ignore-end */ diff --git a/convex/_generated/server.d.ts b/convex/_generated/server.d.ts index 8190e1f..7f337a4 100644 --- a/convex/_generated/server.d.ts +++ b/convex/_generated/server.d.ts @@ -1,5 +1,3 @@ -/* prettier-ignore-start */ - /* eslint-disable */ /** * Generated utilities for implementing server-side Convex query and mutation functions. @@ -142,5 +140,3 @@ export type DatabaseReader = GenericDatabaseReader; * for the guarantees Convex provides your functions. */ export type DatabaseWriter = GenericDatabaseWriter; - -/* prettier-ignore-end */ diff --git a/convex/_generated/server.js b/convex/_generated/server.js index 33b487c..566d485 100644 --- a/convex/_generated/server.js +++ b/convex/_generated/server.js @@ -1,5 +1,3 @@ -/* prettier-ignore-start */ - /* eslint-disable */ /** * Generated utilities for implementing server-side Convex query and mutation functions. @@ -89,5 +87,3 @@ export const internalAction = internalActionGeneric; * @returns The wrapped endpoint function. Route a URL path to this function in `convex/http.js`. */ export const httpAction = httpActionGeneric; - -/* prettier-ignore-end */ From 84e03624ef7156edd8536ba71cf5d140ac09ca91 Mon Sep 17 00:00:00 2001 From: MZT7 <40639877+MZT7@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:23:13 +0100 Subject: [PATCH 2/6] Max blocks and Landmines feature Maps - Ability to Change Max Blocks and Landmines --- .gitignore | 2 + app/play/[level]/page.tsx | 8 +++- app/playground/page.tsx | 29 ++++++++++++- components/ui/label.tsx | 26 +++++++++++ convex/README.md | 90 +++++++++++++++++++++++++++++++++++++++ convex/maps.ts | 9 ++++ convex/schema.ts | 2 + package.json | 1 + 8 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 components/ui/label.tsx create mode 100644 convex/README.md diff --git a/.gitignore b/.gitignore index 373edb9..156481d 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,5 @@ next-env.d.ts # ignored for the template, you probably want to remove it: package-lock.json + +.env.local diff --git a/app/play/[level]/page.tsx b/app/play/[level]/page.tsx index 61c6b0d..e321fa6 100644 --- a/app/play/[level]/page.tsx +++ b/app/play/[level]/page.tsx @@ -37,6 +37,8 @@ export default function PlayLevelPage({ const [placementMode, setPlacementMode] = useState("player"); const [blockCount, setBlockCount] = useState(0); const [landmineCount, setLandmineCount] = useState(0); + const [maxBlocks, setMaxBlocks] = useState(0); + const [maxLandmines, setMaxLandmines] = useState(0); const flags = useQuery(api.flags.getFlags); const [mode, setMode] = useState<"play" | "test">("play"); @@ -44,6 +46,8 @@ export default function PlayLevelPage({ useEffect(() => { if (map) { setPlayerMap(map.grid.map((row) => [...row])); + setMaxBlocks(Number(map.maxBlocks) ?? 0); + setMaxLandmines(Number(map.maxLandmines) ?? 0); } }, [map]); @@ -221,14 +225,14 @@ export default function PlayLevelPage({ variant={placementMode === "block" ? "default" : "outline"} className="h-10" > - Place Block ({2 - blockCount} left) + Place Block ({maxBlocks - blockCount} left)
diff --git a/app/playground/page.tsx b/app/playground/page.tsx index 303fad5..3d4f2bd 100644 --- a/app/playground/page.tsx +++ b/app/playground/page.tsx @@ -25,6 +25,8 @@ import { DialogHeader, DialogTitle, } from "@/components/ui/dialog"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; import { useToast } from "@/components/ui/use-toast"; import { api } from "@/convex/_generated/api"; import { Id } from "@/convex/_generated/dataModel"; @@ -62,6 +64,8 @@ export default function PlaygroundPage() { const [userSolution, setUserSolution] = useState([]); const [visualizingUserSolution, setVisualizingUserSolution] = useState(false); const [openSignInModal, setOpenSignInModal] = useState(false); + const [blocks, setBlocks] = useState(2); + const [landmines, setLandmines] = useState(2); const { isSimulating, @@ -90,7 +94,7 @@ export default function PlaygroundPage() { setPublishing(true); try { - await submitMap({ map }); + await submitMap({ map, blocks, landmines }); toast({ description: "Map submitted successfully!", @@ -465,6 +469,29 @@ export default function PlaygroundPage() { ) : ( <> +
+
+ + setBlocks(Number(e.target.value))} + value={blocks} + /> +
+
+ + setLandmines(Number(e.target.value))} + value={landmines} + /> +
+
+ - - + {maxBlocks > 0 && ( + + )} + + {maxLandmines > 0 && ( + + )}

diff --git a/convex/maps.ts b/convex/maps.ts index ec7f69c..830ab6a 100644 --- a/convex/maps.ts +++ b/convex/maps.ts @@ -198,14 +198,14 @@ export const seedMaps = internalMutation({ ctx.db.patch(existingMap._id, { grid: map.grid, maxBlocks: 2, - maxLandmines: 2, + maxLandmines: 0, }); } else { ctx.db.insert("maps", { level: idx + 1, grid: map.grid, maxBlocks: 2, - maxLandmines: 2, + maxLandmines: 0, isReviewed: true, }); } @@ -370,6 +370,7 @@ export const playMapAction = internalAction({ args.modelId, map.grid, activePrompt.prompt, + map.maxBlocks, ); await ctx.runMutation(internal.results.updateResult, { @@ -431,7 +432,12 @@ export const testAIModel = action({ outputTokens, totalTokensUsed, totalRunCost, - } = await runModel(args.modelId, map.grid, activePrompt.prompt); + } = await runModel( + args.modelId, + map.grid, + activePrompt.prompt, + map.maxBlocks, + ); return { map: solution, diff --git a/convex/prompts.ts b/convex/prompts.ts index 40225de..21a3749 100644 --- a/convex/prompts.ts +++ b/convex/prompts.ts @@ -12,6 +12,7 @@ const defaultPrompt = `Your task is to play a game. We will give you a 2d array - You can not place the player in a location already used by a zombie or rock. - You can not place a block over the player or another block. - You must place both blocks and the player before starting the game. +- You can place {MAX_BLOCKS} blocks on the map. # Grid Descriptions The 2d Grid is made up of characters, where each character has a meaning. diff --git a/models/index.ts b/models/index.ts index 927d674..b9848cf 100644 --- a/models/index.ts +++ b/models/index.ts @@ -52,6 +52,7 @@ export async function runModel( modelId: string, map: string[][], prompt: string, + maxBlocks?: number, retry = 1, ): Promise { const userPrompt = @@ -60,7 +61,7 @@ export async function runModel( let result; let reasoning: string | null = null; - + prompt.replace("{MAX_BLOCKS}", maxBlocks?.toString() ?? ""); try { switch (modelId) { case AI_MODELS["gemini-1.5-pro"].slug: { @@ -125,6 +126,6 @@ export async function runModel( }; } - return await runModel(modelId, map, prompt, retry + 1); + return await runModel(modelId, map, prompt, maxBlocks, retry + 1); } } From dfda8d0ecab3a4a25f3b3801c08cacce13ac72eb Mon Sep 17 00:00:00 2001 From: MZT7 <40639877+MZT7@users.noreply.github.com> Date: Mon, 11 Nov 2024 15:35:48 +0100 Subject: [PATCH 5/6] Updates Values --- app/playground/page.tsx | 20 +++++++++++--------- convex/maps.ts | 8 ++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/playground/page.tsx b/app/playground/page.tsx index 95e8989..437b043 100644 --- a/app/playground/page.tsx +++ b/app/playground/page.tsx @@ -63,8 +63,8 @@ export default function PlaygroundPage() { const [userSolution, setUserSolution] = useState([]); const [visualizingUserSolution, setVisualizingUserSolution] = useState(false); const [openSignInModal, setOpenSignInModal] = useState(false); - const [blocks, setBlocks] = useState(2); - const [landmines, setLandmines] = useState(2); + const [maxBlocks, setMaxBlocks] = useState(2); + const [maxLandmines, setMaxLandmines] = useState(0); const { isSimulating, @@ -93,7 +93,7 @@ export default function PlaygroundPage() { setPublishing(true); try { - const submitted = await submitMap({ map, blocks, landmines }); + const submitted = await submitMap({ map, maxBlocks, maxLandmines }); if (submitted == 200) { toast({ @@ -345,9 +345,9 @@ export default function PlaygroundPage() { if (cell === " ") { if (playerCount === 0) { newMap[y][x] = "P"; - } else if (blockCount < 2) { + } else if (blockCount < maxBlocks) { newMap[y][x] = "B"; - } else if (landmineCount === 0) { + } else if (landmineCount === maxLandmines) { newMap[y][x] = "L"; } } else if (cell === "P") { @@ -483,8 +483,8 @@ export default function PlaygroundPage() { placeholder="Max Blocks" type="number" id="block" - onChange={(e) => setBlocks(Number(e.target.value))} - value={blocks} + onChange={(e) => setMaxBlocks(Number(e.target.value))} + value={maxBlocks} />

@@ -493,8 +493,10 @@ export default function PlaygroundPage() { placeholder="Max Landmines" type="number" id="landmine" - onChange={(e) => setLandmines(Number(e.target.value))} - value={landmines} + onChange={(e) => + setMaxLandmines(Number(e.target.value)) + } + value={maxLandmines} />
diff --git a/convex/maps.ts b/convex/maps.ts index 830ab6a..8787e0a 100644 --- a/convex/maps.ts +++ b/convex/maps.ts @@ -159,8 +159,8 @@ export const addMap = mutation({ export const submitMap = authenticatedMutation({ args: { map: v.array(v.array(v.string())), - blocks: v.number(), - landmines: v.number(), + maxBlocks: v.number(), + maxLandmines: v.number(), }, handler: async (ctx, args) => { try { @@ -172,8 +172,8 @@ export const submitMap = authenticatedMutation({ await ctx.db.insert("maps", { grid: args.map, level: undefined, - maxBlocks: args.blocks, - maxLandmines: args.landmines, + maxBlocks: args.maxBlocks, + maxLandmines: args.maxLandmines, submittedBy: ctx.userId, isReviewed: false, }); From 72dc114d710080aee5e44b3a918e379463a09374 Mon Sep 17 00:00:00 2001 From: MZT7 <40639877+MZT7@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:28:41 +0100 Subject: [PATCH 6/6] Update index.ts --- models/index.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/models/index.ts b/models/index.ts index b9848cf..ee24ce4 100644 --- a/models/index.ts +++ b/models/index.ts @@ -61,27 +61,31 @@ export async function runModel( let result; let reasoning: string | null = null; - prompt.replace("{MAX_BLOCKS}", maxBlocks?.toString() ?? ""); + const modifiedPrompt = prompt.replace( + "{MAX_BLOCKS}", + maxBlocks?.toString() ?? "", + ); + try { switch (modelId) { case AI_MODELS["gemini-1.5-pro"].slug: { - result = await gemini15pro(prompt, userPrompt, CONFIG); + result = await gemini15pro(modifiedPrompt, userPrompt, CONFIG); break; } case AI_MODELS["gpt-4o"].slug: { - result = await gpt4o(prompt, userPrompt, CONFIG); + result = await gpt4o(modifiedPrompt, userPrompt, CONFIG); break; } case AI_MODELS["claude-3.5-sonnet"].slug: { - result = await claude35sonnet(prompt, userPrompt, CONFIG); + result = await claude35sonnet(modifiedPrompt, userPrompt, CONFIG); break; } case AI_MODELS["perplexity-llama-3.1"].slug: { - result = await perplexityLlama31(prompt, userPrompt, CONFIG); + result = await perplexityLlama31(modifiedPrompt, userPrompt, CONFIG); break; } case AI_MODELS["mistral-large-2"].slug: { - result = await mistralLarge2(prompt, userPrompt, CONFIG); + result = await mistralLarge2(modifiedPrompt, userPrompt, CONFIG); break; } default: { @@ -126,6 +130,6 @@ export async function runModel( }; } - return await runModel(modelId, map, prompt, maxBlocks, retry + 1); + return await runModel(modelId, map, modifiedPrompt, maxBlocks, retry + 1); } }