-
Notifications
You must be signed in to change notification settings - Fork 16
Description
I started this experiment to see if the Wolfram ChatBot would be capable of writing a working Minesweeper game.
It cannot.
Here's the query:
Create a minesweeper clone in mathematica. It should be a completely functioning game with GUI, and same interactions as the standard Microsoft Minesweeper game.
Here's the resulting code:
Module[{size = 10, mines = 20, grid, revealed, flags, minePositions,
gameState},
(* Initialize game state *)
grid = ConstantArray[0, {size, size}];
revealed = ConstantArray[False, {size, size}];
flags = ConstantArray[False, {size, size}];
gameState = "playing";
(* Place mines *)
minePositions = RandomSample[Range[size^2], mines];
grid = ReplacePart[grid, Thread[minePositions -> -1]];
(* Calculate adjacent mines *)
Do[
If[grid[[i, j]] != -1,
grid[[i, j]] = Total[Boole@Thread[grid[[##]] == -1] & @@@
Tuples[{Range[Max[1, i - 1], Min[size, i + 1]],
Range[Max[1, j - 1], Min[size, j + 1]]}]]
],
{i, size}, {j, size}
];
(* Define cell action *)
cellAction[i_, j_] := (
If[gameState === "playing",
If[! revealed[[i, j]],
If[grid[[i, j]] == -1,
gameState = "lost",
revealed[[i, j]] = True;
If[grid[[i, j]] == 0,
Do[If[! revealed[[x, y]], cellAction[x, y]], {x, Max[1, i - 1],
Min[size, i + 1]}, {y, Max[1, j - 1], Min[size, j + 1]}]
]
]
]
];
If[Total[Boole[revealed]] == size^2 - mines, gameState = "won"];
);
(* Create interactive grid )
Grid[
Table[
Button[
Dynamic[
If[revealed[[i, j]],
If[grid[[i, j]] == -1, Style["", Red], grid[[i, j]]],
If[flags[[i, j]], Style["F", Blue], ""]]
],
If[flags[[i, j]], flags[[i, j]] = False, cellAction[i, j]],
Appearance -> "Frameless"
],
{i, size}, {j, size}
],
Spacings -> {0, 0}
]
]
This code has two issues. The first issue is with this line:
grid = ReplacePart[grid, Thread[minePositions -> -1]];
That line doesn't work the way the chatbot think it does. After some additional conversations with the chatbot, we got to this line, which does work (after I fixed a couple of bugs in the chat bots output)
grid = Fold[
ReplacePart[#1, {QuotientRemainder[#2, size] + 1} -> -1] &,
grid,
minePositions
];
(It just had # instead of #1 and #2 )
The second bug is tougher, the dynamic module/grid it is generating just doesn't work. Table/Dynamic/Button don't work together the way it thinks, and I've been working around trying to figure out how to make that work. to focus on just this issue, I started down another path with a Chatbot query like this:
I'd like to build a GUI, which consists of a grid of 5x5 buttons, such that when you click on a button, the button updates with the number of times it's been clicked.
And it generated this identical code, which doesn't work:
DynamicModule[{clickCounts},
clickCounts = ConstantArray[0, {5, 5}];
Grid[
Table[
Button[
Dynamic[clickCounts[[i, j]]],
(*
Increment the click count for the button at position {i, j} *)
clickCounts[[i, j]]++,
Appearance -> "Palette"
],
{i, 5}, {j, 5}
],
Spacings -> {0, 0}
]
]
After a few conversations, I put this query into the chat, and it crashed:
No, that is not the issue, the issue is that the [[i,j]] from the table definition aren't understood by Dynamic. How to fix that? Alternatively, please come up with alternative solutions to this problem.
Chatbook/Source/Chatbook/PromptGenerators/VectorDatabases.wl
Lines 998 to 1007 in 586d3af
| close = ConfirmMatch[ | |
| inVectorDBDirectory @ VectorDatabaseSearch[ | |
| vectorDB, | |
| embeddingVector, | |
| { "Index", "Distance" }, | |
| MaxItems -> $maxNeighbors | |
| ] // LogChatTiming[ "VectorDatabaseSearch" ], | |
| { ___Association }, | |
| "PositionsAndDistances" | |
| ]; |
Debug Data
| Property | Value |
|---|---|
| Name | "Wolfram/Chatbook" |
| Version | "2.5.0" |
| ReleaseID | "586d3af0ec254ed07f6531a96e32f19791e349b6" |
| EvaluationEnvironment | "Session" |
| FrontEndVersion | "Desktop: 14.3 for Microsoft Windows (64-bit) (July 8, 2025)" |
| KernelVersion | "14.3.0 for Microsoft Windows (64-bit) (July 8, 2025)" |
| SystemID | "Windows-x86-64" |
| Notebooks | True |
| DynamicEvaluation | False |
| SynchronousEvaluation | False |
| TaskEvaluation | False |
Settings
| Property | Value |
|---|---|
| InheritanceTest | True |
| StyleSheetVersion | "2.3.48.3959923654" |
Failure Data
<|
"Evaluation" :> Wolfram`Chatbook`PromptGenerators`Common`vectorDBSearch["FunctionRepositoryURIs", "```wl\nIn[355]:=\nDynamicModule[{clickCounts = ConstantArray[0, {5, 5}]}, \n\t Grid[\n\t Table[\n\t Button[\n\t Dynamic[clickCounts[[i, j]]], \n\t (* Increment the click count for the button at position {i, j} *)\n\t clickCounts[[i, j]]++, \n\t Appearance -> \"Palette\"\n\t ], \n\t {i, 5}, {j, 5}\n\t ], \n\t Spacings -> {0, 0}\n\t ]\n\t]\n\nOut[355]= DynamicMod...,
"Information" -> "PositionsAndDistances@@Source/Chatbook/PromptGenerators/VectorDatabases.wl:998,17-1007,10",
"ConfirmationType" -> "ConfirmMatch",
"Expression" :> VectorDatabaseSearch[VectorDatabaseObject[<|"DistanceFunction" -> EuclideanDistance, "FeatureExtractor" -> Identity, "GeneratedAssetLocation" -> "FunctionRepositoryURIs", "ID" -> "FunctionRepositoryURIs", "Location" -> File["FunctionRepositoryURIs/FunctionRepositoryURIs.wxf"], "ResolvedFeatureExtractor" -> Identity, "USearchParameters" -> <|"Connectivity" -> 16, "ExpansionAdd" -> 32, "ExpansionSearch" -> 1024|>, "VectorDatabaseInfo" -> <|"DistanceFunction" -> "l2sq", "WorkingPrecision" -> "i8", ...,
"Pattern" -> {___Association},
"Stack" :> Wolfram`Chatbook`Common`Private`$stack$381924,
"Failure" -> Failure["ConfirmationFailed", <|"MessageTemplate" -> "PositionsAndDistances@@Source/Chatbook/PromptGenerators/VectorDatabases.wl:998,17-1007,10", "MessageParameters" -> {}, "ConfirmationType" -> "ConfirmMatch", "Expression" :> VectorDatabaseSearch[VectorDatabaseObject[<|"DistanceFunction" -> EuclideanDistance, "FeatureExtractor" -> Identity, "GeneratedAssetLocation" -> "FunctionRepositoryURIs", "ID" -> "FunctionRepositoryURIs", "Location" -> File["FunctionRepositoryURIs/FunctionRepositoryURIs.wx...,
"Arguments" -> {}
|>
Stack Data
trimURL
throwFailure
applyBias
catchTop
withChatState
catchTop
formatGeneratedPrompt
catchTopAs
withChatState