
Weekend Creative Challenge: Congklak Bali
This started with a guide's memory of a childhood game and ended up as something I built between destinations. If you're travelling, it's worth asking about the games people grew up with. An ordinary memory to them can be completely new to you, and you might end up building something out of it.
Vision & what the app does
I'm travelling in Bali. A guide mentioned a game he played constantly as a kid: a board of small hollows, stones moved around them one at a time. Congklak, a mancala. I wanted to try it, and I had no board and no stones with me.
So I built one between destinations. That's this app.
Congklak uses sixteen holes: seven small pits per player, plus a store at each end, and ninety-eight stones. It has one feature that Kalah, the version most people have met, doesn't have. If your last stone lands in a pit that already has stones in it, you scoop up that pit and keep sowing. A single move can travel around the board several times before it stops.
The opponent's moves come from Amazon Bedrock, using Nova Lite. The model returns a move and a one-line reason, and the reason is shown in the UI, so you can see what the AI thinks it's doing while you play.

How you built it
I deployed the boring part first. Before writing a single rule of Congklak, I put up a walking skeleton: CloudFront serving a hello page, a working Cognito login, and a Lambda that returned a hardcoded move. A perfect game engine is worth nothing if sign-in won't deploy, and I'd rather find that out on day one.
The API sits on the same CloudFront distribution as the site, under
/api/* . Same origin, so CORS never enters the picture. There's a trap here that cost me some time: CloudFront strips the Authorization header by default. Without the ALL_VIEWER_EXCEPT_HOST_HEADER origin request policy, a completely valid token gets you a 401 and nothing in any log explains why.I also had to remove a setting I'd added out of habit. The usual SPA rule that rewrites 403 and 404 to
index.html with a 200 is configured on the distribution, not on a behavior, so it applied to /api/* as well. API errors were arriving at the browser as successful HTML, which the frontend then failed to parse. This app is one page with no client-side router, so the rule was pure downside.The capture rule turned out to be the trickiest thing to get right. You capture when your last stone lands in an empty pit on your own side. But with relay sowing a move can lap the board, and an earlier stone from the same move can drop into the exact pit where the last one lands. If you compare the board before and after, that pit looks occupied and you miss the capture. You have to track how many stones were sitting there at the moment the final stone was placed.
Writing tests found a bug in my rules document rather than my code. Coverage flagged one unreachable branch in the turn logic. I'd written both "the game ends the instant either side is empty" and "a player whose side is empty passes", and the first fires before the second ever can. The two aren't interchangeable either. Congklak sows into your opponent's pits, so an emptied side gets refilled on their next move. Ending at the first empty side cuts games short and hands a big win to whoever emptied first, which is easy to do by accident. Without tests I'd have shipped a game that ends wrong.
AWS services used / architecture overview

S3, CloudFront, Cognito, API Gateway, Lambda, Bedrock, Budgets, IAM and CloudWatch Logs, all in
us-east-1 . Pinning the region up front meant I never had to think about Nova availability or cross-region inference profiles.The frontend has no npm dependencies at all. A sixteen-hole board is CSS grid and some DOM, so there's no bundler and no build step to break. CDK writes a
config.json into the bucket at deploy time using Source.jsonData , which is how the pool IDs and endpoints reach the browser without any copy-paste or a second deploy pass.For cost control I picked a few things and skipped the rest. A WAF Web ACL starts at about $5 a month, while Nova Micro runs about $0.035 per million input tokens, so the guard would have cost more than what it guards. What's actually in there: Cognito sign-in, API Gateway throttling, an explicit
maxTokens cap, and a Budgets alert.What you learned
I expected to spend this section on prompt wording. Instead the interesting result was that the approach worked for one thing and not for another.
Rather than asking the model to reason about the board, the Lambda enumerates every legal move, simulates each one, and sends a menu with the outcomes already worked out:
[{"hole":0,"stonesCaptured":3,"endsInOwnStore":false}, {"hole":2,"stonesCaptured":0,"endsInOwnStore":true}]The reply is forced through the Converse API's
toolConfig with toolChoice , so it comes back as {hole, reason} and there's no text to parse.Legality was solved completely. Across five calls on the opening board, a full 29-ply game with Nova playing both sides, and a scored run over two fixtures, 46 out of 46 moves were legal. Not rarely illegal. Illegal moves stopped being possible, because they were never on the menu.
Then I changed the question. Instead of asking whether the move was legal, I scored whether it was the best option on the menu it had just been handed. On one mid-game board with six legal moves, one earning an extra turn, one capturing three stones, and one doing neither, Nova picked the do-nothing move four times out of six. Its explanation was that the move "will maximize my store stones and give me an extra turn". The prompt had told it, for that exact hole,
"stonesCaptured":0,"endsInOwnStore":false . It wasn't misjudging a subtle position, it was contradicting a number in its own input.I should flag a mistake in my own measurement. My first scoring pass weighted "extra turn" far above captured stones, which made the opening board look like a disaster. Banking nine stones is very plausibly the better move there, so I threw that result out. The mid-game case survives because the move it kept choosing is worse on both counts at once.
What I take from this is narrower than "write a better prompt". Taking the search away from the model is reliable and cheap. Taking the evaluation away from it is the next thing you have to do, and I hadn't done it. Rank the moves in code, and let the model do the part it's actually good at, which is explaining the choice to the player.
That also lines up with something I saw earlier. In a comparison between Nova Micro and Nova Lite, Micro picked a perfectly defensible move and then invented a justification for it that was flatly untrue. The quality of the move and the quality of the explanation are separate problems, and validating against the legal move list only protects the first one. So every move gets re-checked before it touches the board, and a small heuristic AI stays on standby for when Bedrock is throttled, misconfigured, or simply wrong.
Link to app or repo
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article