# Square Patchwork: pytoolz/WSRF retraining

A real **`pytoolz.wsrf.WSRFRegressor`** chooses legal placements. The browser evaluates its complete exported trees and does not retrain while playing. This update responds to quilts getting stuck at **32/36 covered squares**: four scattered spaces cannot hold a remaining 2 × 2 tile. That is a lost packing attempt, not the intended finish and not a count of moves.

## Rules and learned inputs

The unchanged puzzle covers a 6 × 6 board with two 3 × 3, three 2 × 2 and six 1 × 1 patches. Seeded rotation, reflection and one to three pre-placed patches create solvable starts. Placements cannot overlap. Covering all 36 squares wins; exhausting legal placements early ends the attempt.

An exact offline packing teacher gives a move +30 if the remaining inventory can still cover the quilt, or −40 otherwise, plus the original small size/edge priority bonuses. The 14 original features describe inventory, free placements, holes and connected regions. Eight additional visible geometry inputs measure cells that require single patches, spare singles, separate-size packing capacities, capacity margins and medium-tile room after placing one large tile. These are bounds computed from visible cells. They do **not** solve the mixed-size quilt or expose exact finishability as an input.

Inputs, in order: `tile side, tile area, ones left, twos left, threes left, two-square spaces, three-square spaces, isolated holes, empty regions, small-region area, edge contact, filled area, large priority, edge priority, squares needing singles, spare singles, medium packing capacity, large packing capacity, medium capacity margin, large capacity margin, medium capacity after one large, large fits leaving medium room`.

Autoplay, the ordinary hint and the brain panel all use the learned forest. When a player explicitly requests **Back to a quilt that fits** after a loss, a separate exact rule helper finds the most recent finishable state, undoes the necessary moves, and outlines a checked placement. The page identifies this as a rules check. It leaves the game paused in coach mode; the player chooses whether to place it. Recovery is excluded from model evaluations.

## Training and selection

`pt.indexrng.Index("patchwork-comfort-v1", backend="blake2b")` generates separate train, recovery, validation, solo-test and guided-test streams. Existing checked qrand arithmetic creates world details. Train and recovery priorities vary; solo tests use balanced priority, and guided tests change priority and condition every five turns. The two zones, `calm` and `challenge`, correspond to the cosmetic tile-size/area display.

The first fit uses **256 reference episodes**, collecting every legal action at each visited state. The shared sampler's exploration rule chooses a random move every eleventh turn; these quilts finish within ten moves, so this rule adds no exploration in the initial reference collection. A further **128 guided early-model episodes** supply recovery-state action labels. Training has **53,326 selected action rows**.

The early candidate has 16 trees per zone, depth 14. The final candidate has 32 per zone, depth 20. Both use minimum leaf size 2, all features, seed 2026, one worker, no adaptive complexity, no zone prior and no calibration. Both finish 64/64 validation quilts. Selection compares completions, score, then fewer turns; the final candidate wins the tie under the recorded deterministic selection rule. Selected: **final**, **64 trees**. Fresh test results are measured after selection and are not used for fitting or selection.

## Recorded results

| Policy | Completed | Mean moves |
| --- | --- | --- |
| Previous model, same fresh quilts | 215/256 | 8.879 |
| Early candidate | 256/256 | 9.043 |
| Selected model | 256/256 | 9.043 |
| Previous model, changing nudges | 60/64 | 9.000 |
| Selected model, changing nudges | 64/64 | 9.062 |
| Exact reference | 256/256 | 9.043 |
| Random legal moves | 2/256 | 7.441 |

Solo comparisons use the same 256 fresh seeds; guided comparisons use the same separate 64 seeds. The original model's old evaluation was 49/64, retained in [the previous report](../../tools/patchwork/previous-report.json). Its unchanged trees are retained in [the previous forest](../../tools/patchwork/previous-forest.json). For comparison only, the sampler extends its feature-name metadata: the original 14 feature indices and all tree nodes stay identical.

The 15 failures from the old solo evaluation, including the reproduced 32/36 board, now finish with the new model. Those are diagnostic regressions, not additional fresh test evidence. This is a finite family of seeded quilts; different seeds can create identical starting boards. The results do not guarantee every human-created position or arbitrary packing problem.

Held-out action-value MAE: **2.415994**; R²: **0.931259**. These describe the teacher's score, not a probability of winning. **144,339 Python/browser predictions** match within `1e-9`, with maximum observed error **0**. The compressed fixtures include held-out features and float32 neighbors around every selected tree threshold.

The optional brain view shows all 22 real inputs, candidate values, a tree path, tree standard deviation, early/current comparisons and the effect of changing priorities. Previewing a move does not play it.

## Reproduce

Run from the arcade root with the recorded local pytoolz/WSRF environment:

```sh
/home/wiliamrocha/.spenv/bin/python -B tools/patchwork/train.py
/home/wiliamrocha/.spenv/bin/python -B tools/patchwork/document.py
/home/wiliamrocha/.spenv/bin/python -B tools/curiosity/document.py
node tools/test-patchwork.cjs
node tools/test-curiosity.cjs
npm run build
```

The actual library version, estimator source/hash, parameters, all evaluation seeds, source hashes, model checksum and comparisons are in [report.json](training/report.json). See [training code](../../tools/patchwork/train.py), [world rules](model.js), [prediction fixtures](training/validation.json.gz), [fixture checksum](training/fixture-package.json), and [pytoolz mathematics provenance](../../tools/curiosity/math-report.json). The upstream libraries were used without editing their source. Temporary training rows are excluded from the Netlify folder.
