POCKET CITY / STUDY / LEVEL 4 OF 5
Checking
the reply.
The prompt asks nicely; the validator insists. A reply from the AI is text from another computer, and it is wrong more often than you would think: a block at x = 3, a cube floating in the air, two cubes in one cell, three buildings instead of four. validateCityResponse reads every block, keeps the ones that obey the vocabulary, drops the rest and counts them, and gives up on a building that has too little left. This page runs it on any reply you type.
An AI reply
edit it, or pick a casevalidateCityResponse
What the coach would draw: the kept blocks on the four blue lots. Dropped blocks are simply absent.
The real code
pocketCityRules.jsTwo kinds of problem, two reactions, as in the coach's AI code: a broken structure throws, and the scene keeps the example; a bad block is dropped, and the rest of the building survives. The sort by y matters: support is checked against cubes already accepted, so lower layers must be processed first whatever order the AI wrote them in.
What you should be able to explain
- Reject or repair. Wrong count or no block array: nothing can be made of it, so the reply is rejected and the old city, if any, stays. A single bad cube: drop it and keep going.
- Support is checked in order. Blocks are sorted by layer before the loop, and
occupiedremembers accepted cells, so "is there a cube below?" always has an answer. A floating cube is dropped, and so is anything that would have stood on it. - Discarded is a measurement. The scene reports how many cubes were dropped. Across many runs that number says how well the AI understood the rules, which is the kind of observation the assignment asks for.
- Only known fields survive. Accepted blocks are rebuilt as
{x, y, z, kind}; names and titles are reduced to plain capitals for the line font.
Exercises: ① Pick "a floating cube": which cubes vanish, and why more than one? ② Make a building with 30 valid cubes: how many are kept, and which ones? ③ Change one building's blocks to an empty array: why does the whole reply fail rather than that one lot?