LVL 01SK
Project overview
FIRST-PRINCIPLES FIELD GUIDE

AlphaZero on Connect-4

Build the game engine, policy-value network, PUCT MCTS, self-play generation, training, and baseline evaluation.

01 · MOTIVATION

Begin with the problem, not the library

Before AlphaZero on Connect-4 is a collection of classes and functions, it is an answer to a constraint. Build the game engine, policy-value network, PUCT MCTS, self-play generation, training, and baseline evaluation. The useful question is not “which API should I call?” but “what information is available, what decision must be made, and what evidence proves the decision is good?”

A first-principles implementation makes hidden assumptions visible. It forces us to specify the input, the transformation, the objective, and the failure conditions. That discipline is valuable even when a production system later uses a mature library.

02 · FIRST PRINCIPLES

Reduce the system to four questions

01

Representation

How is the raw problem expressed as numbers, states, tokens, tensors, or events?

02

Objective

What quantity tells the system that one answer is better than another?

03

Update

How does evidence change parameters, state, policy, or decisions?

04

Evaluation

Which controlled test separates real improvement from noise or leakage?

AlphaZero on Connect-4 becomes understandable when each implementation step answers exactly one of these questions. The walkthrough keeps those boundaries explicit so a bug can be localized instead of disappearing inside an end-to-end pipeline.

03 · CONCEPT ATLAS

The ideas you must genuinely understand

01

PUCT

PUCT balances exploitation of actions with high mean value and exploration of actions favored by the policy prior but visited less often. Repeated selection, expansion, evaluation, and backup turns neural estimates into a stronger search policy.

In AlphaZero on Connect-4, implement this idea first on a tiny hand-computable example. Write down every shape, legal range, and invariant; compare the code with the manual result; then profile and scale only after the reference agrees.

Verification rule: test the normal case, a boundary case, an invalid case, and an invariant that must remain true after the operation.

02

Value networks

A value network compresses the expected outcome of a state into one scalar from the current player’s perspective. Perspective must flip during tree backup; otherwise an action good for the opponent is accidentally reinforced.

In AlphaZero on Connect-4, implement this idea first on a tiny hand-computable example. Write down every shape, legal range, and invariant; compare the code with the manual result; then profile and scale only after the reference agrees.

Verification rule: test the normal case, a boundary case, an invalid case, and an invariant that must remain true after the operation.

03

Replay buffer

A replay store breaks temporal correlation and lets expensive experience support multiple gradient updates. Its schema, sampling policy, age distribution, and target semantics are part of the algorithm—not mere storage details.

In AlphaZero on Connect-4, implement this idea first on a tiny hand-computable example. Write down every shape, legal range, and invariant; compare the code with the manual result; then profile and scale only after the reference agrees.

Verification rule: test the normal case, a boundary case, an invalid case, and an invariant that must remain true after the operation.

THE COMPLETE TECHNICAL HANDBOOK

From first principles to production evidence

The following chapters deliberately slow the build down. They connect every major milestone to its contract, derivation, implementation choices, tests, failure modes, systems cost, and production responsibilities.

Verified as part of a 10,000+ word project article
07 · DEEP FOUNDATION

Formulate the problem before choosing the machinery

AlphaZero on Connect-4 begins with a decision problem, not a framework. Build the game engine, policy-value network, PUCT MCTS, self-play generation, training, and baseline evaluation. Restate that sentence as an observable input, a desired output, and a criterion for preferring one output over another. Identify who or what supplies supervision, whether feedback is immediate or delayed, and whether examples can be considered independent. These choices determine what can be learned and what remains an assumption. The implementation is honest only when those assumptions are visible near the data contract rather than buried in training code.

The raw material becomes a state transition. Representation decides which distinctions the system can express and which distinctions disappear. List categorical domains, numerical units, missing-value semantics, sequence or spatial axes, masks, player or client perspective, and precision. Then consider invariances: should translation, permutation, rescaling, token position, client identity, or board symmetry change the answer? An architecture that ignores the required invariance wastes data; one that imposes the wrong invariance makes the target impossible to represent.

Finally define the baseline and the abstention point. A baseline can be a constant predictor, random policy, linear rule, naive kernel, synchronous algorithm, or human heuristic. It anchors complexity in evidence. The abstention point describes inputs for which the system lacks support and should decline, defer, or fall back. Together they prevent AlphaZero on Connect-4 from being judged only by an impressive end-to-end demonstration while basic correctness, calibration, robustness, or operational usefulness remains unknown.

08 · OBJECTIVE

Connect the objective to the behavior you actually want

An objective compresses preferences into a scalar, but no scalar captures every product or scientific goal. For AlphaZero on Connect-4, distinguish the training objective from the evaluation metric and the deployment utility. The training objective must provide a usable signal to parameters or state; evaluation must estimate generalization under a controlled protocol; deployment utility includes latency, cost, safety, and the consequence of errors. When these three disagree, optimization can succeed while the system becomes less useful.

Study each term dimensionally and statistically. Ask what happens if one term is multiplied by ten, one class becomes rare, a sequence becomes longer, a client contributes more samples, or rewards are shifted. Determine whether averages are per token, example, client, action, spatial position, or batch. Regularization is not decorative: it encodes a preference over solutions and changes units unless normalized consistently. A correct derivation names the population quantity of interest, its finite-sample estimator, and the approximation introduced by minibatches, replay, sampling, or surrogate losses.

Identifiability is the deeper constraint. Data may not contain enough information to separate competing explanations. PUCT, Value networks, Replay buffer can improve computation or inductive bias, but they cannot manufacture missing evidence. State causal assumptions, observability limits, support conditions, and equivalence classes of solutions. Use sensitivity analysis and targeted interventions where possible. When identification is impossible, report uncertainty or a set of plausible answers rather than converting an arbitrary modeling choice into unwarranted confidence.

09 · COMPUTATION

Make mathematical equivalence survive finite precision

Paper algebra assumes exact real numbers; the implementation uses finite precision, bounded memory, and discrete execution order. In AlphaZero on Connect-4, audit exponentials, logarithms, divisions, reductions, norms, probabilities, recursive values, and accumulated updates. Rewrite unstable expressions with max subtraction, log-sum-exp, compensated accumulation, safe denominators, or higher-precision reductions. Track where a mathematically harmless reordering changes rounding and where mixed precision needs scaling or master copies.

Shapes are part of the proof. Annotate each intermediate with semantic axes rather than only dimensions: batch, token, head, channel, client, action, expert, feature, row, column, or sample. Broadcasting should be intentional and verified with asymmetric dimensions so an accidental match cannot hide. Record contiguous layout and stride assumptions when performance code depends on them. For every reshape or transpose, write both the precondition and the inverse operation needed during backward, decoding, aggregation, or reconstruction.

Build a numerical ladder: scalar example, tiny vector or matrix example, batched reference, optimized path, then realistic workload. At each rung compare values and invariants before increasing scale. This catches defects while they are still interpretable. The acceptance test should specify absolute and relative error, exceptional values, deterministic modes, and the hardware or library versions used. Numerical stability is not a final cleanup task; it is part of the algorithm’s definition.

10 · EVALUATION

Design evidence that can falsify the implementation

Evaluation is an experiment. For AlphaZero on Connect-4, specify the unit of analysis, split strategy, temporal boundary, randomization, baseline, metric, and uncertainty before viewing final results. Prevent duplicates, transformed copies, future information, opponent leakage, and shared-client information from crossing the boundary. A single aggregate score can hide subgroup collapse, unstable seeds, poor calibration, tail latency, or rare catastrophic behavior, so pair it with distributions and stratified slices.

Ablations connect outcomes to mechanisms. Remove or replace PUCT, Value networks, Replay buffer one at a time while controlling data, compute, and evaluation. Compare equal wall-clock or equal resource budgets when efficiency is part of the claim. Repeat stochastic runs and report variation rather than selecting the best seed. Inspect learning curves and intermediate metrics because two systems with the same final score may differ radically in sample efficiency, stability, or cost.

The test suite and the benchmark answer different questions. Unit and property tests prove local contracts; integration tests prove components agree; benchmarks estimate behavior at scale; task evaluation estimates usefulness. Preserve all four. A benchmark that bypasses validation or uses a different code path from production is weak evidence. The strongest release gate reruns the exact packaged implementation with recorded configuration and produces an artifact that another person can inspect.

11 · PRODUCTION

Turn the learning artifact into an operable system

Production structure separates pure computation from orchestration, configuration, persistence, and interfaces. Package the core of AlphaZero on Connect-4 behind typed contracts. Keep data loading, model or state construction, training, evaluation, serialization, and serving independently invocable. Configuration should be validated, versioned, and printable. Random seeds, data identifiers, source commit, dependency lock, hardware, and metric definitions belong in the run record so an apparent regression can be reproduced instead of guessed at.

Capacity planning follows the critical path. Measure environment interactions, exploration budget, replay reuse, and evaluation games across representative input sizes and concurrency. Report warm-up separately, distinguish throughput from latency, and include tail percentiles. Define memory ownership and lifetime so caches, activations, buffers, replay, or optimizer state cannot grow without a bound. Backpressure and admission control are preferable to unpredictable collapse. Where hardware-specific acceleration exists, preserve a portable reference path for correctness and degraded operation.

Observability must explain decisions and failures without exposing sensitive content. Log stable identifiers, shapes, versions, summary statistics, timings, and error categories. Monitor input drift, output distribution, task quality, saturation, retries, and fallback rate. Establish rollback and shadow-evaluation procedures before the first risky change. A production-grade implementation is not merely more abstract than a notebook; it makes dependencies, state, failure, and evidence explicit enough for another engineer to operate safely.

12 · RESEARCH PRACTICE

Read claims as reproducible hypotheses

The research surrounding AlphaZero on Connect-4 improves representations, objectives, algorithms, systems, or evaluation protocols. Classify each paper by which lever it changes. Then identify the comparison budget: data, parameters, tokens, environment steps, hardware, communication, wall-clock time, and tuning effort. A claimed improvement may disappear when budgets are normalized or when the baseline receives equal tuning. Read methods and appendices for details that determine reproducibility, not only the abstract and headline table.

Reproduction begins with the smallest claim. Recreate one table row or ablation before attempting the entire system. Preserve the authors’ preprocessing and metric definitions, then deliberately vary one assumption. Document deviations, failed attempts, and environment details. When a result does not reproduce, distinguish an implementation defect from missing procedural knowledge, stochastic uncertainty, and genuine sensitivity. Negative evidence is useful when it narrows the conditions under which the method works.

Extension should start from a mechanism and a falsifiable prediction. The skills developed here—MCTS, Self-play, Policy learning—suggest multiple directions, but change one major factor at a time. Predict which metric and intermediate signal should move if the explanation is correct. Use confidence intervals and preregistered stopping rules for expensive experiments where possible. Publish code, configuration, data provenance, and failure cases so the work contributes more than another isolated score.

13 · PROOF LEDGER

Maintain a chain of evidence from equation to outcome

A proof ledger for AlphaZero on Connect-4 links each important claim to the smallest evidence that could disprove it. For a mathematical claim, keep a hand-worked example and a high-precision reference. For a software contract, keep unit and property tests. For an optimization claim, keep profiler traces and equal-budget baselines. For a learning claim, keep per-seed results, confidence intervals, and ablations. For a production claim, keep load tests, failure injection, monitoring queries, and rollback evidence. This structure prevents one successful end-to-end run from being treated as proof of every layer beneath it.

Record evidence beside the versioned artifact it evaluates. A metric without its dataset revision, configuration, dependency lock, hardware, and commit cannot reliably settle a regression. Likewise, a screenshot or generated sample is qualitative evidence, not a distribution. Name the claim, evidence type, acceptance threshold, owner, and date. When the implementation changes, rerun the smallest affected evidence first and then the downstream integration gates. The ledger becomes a map of confidence: it shows what is known, what is assumed, what has become stale, and where another experiment is required.

Use the ledger during review. Ask whether each test would fail for a realistic defect, whether each benchmark measures the packaged code path, whether every aggregate retains inspectable raw values, and whether uncertainty is reported at the correct independent unit. Include counterexamples and failed experiments because they define the boundary of the method. Over time this habit turns MCTS, Self-play, Policy learning from isolated implementation skills into a reproducible engineering practice that survives new data, new hardware, new collaborators, and changing product constraints.

IMPLEMENTATION ATLAS · 01

Make Empty Board — from contract to production evidence

Make Empty Board is the construction at milestone 1 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between connect-4 game engine and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Make Empty Board as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Make Empty Board depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Make Empty Board needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Make Empty Board can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Make Empty Board changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Connect-4 Game Engine. Build the board representation, move mechanics, terminal detection, and environment step function for Connect-4.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 02

Column Full — from contract to production evidence

Column Full is the pipeline boundary at milestone 4 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between connect-4 game engine and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Column Full as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Column Full depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Column Full needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Column Full can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Column Full changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Connect-4 Game Engine. Build the board representation, move mechanics, terminal detection, and environment step function for Connect-4.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 03

Four In A Row Vertical — from contract to production evidence

Four In A Row Vertical is the pipeline boundary at milestone 7 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between connect-4 game engine and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Four In A Row Vertical as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Four In A Row Vertical depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Four In A Row Vertical needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Four In A Row Vertical can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Four In A Row Vertical changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Connect-4 Game Engine. Build the board representation, move mechanics, terminal detection, and environment step function for Connect-4.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 04

Check Winner — from contract to production evidence

Check Winner is the verification at milestone 10 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between connect-4 game engine and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Check Winner as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Check Winner depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Check Winner needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Check Winner can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Check Winner changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Connect-4 Game Engine. Build the board representation, move mechanics, terminal detection, and environment step function for Connect-4.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 05

Other Player — from contract to production evidence

Other Player is the pipeline boundary at milestone 13 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between connect-4 game engine and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Other Player as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Other Player depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Other Player needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Other Player can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Other Player changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Connect-4 Game Engine. Build the board representation, move mechanics, terminal detection, and environment step function for Connect-4.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 06

Board To Torch Tensor — from contract to production evidence

Board To Torch Tensor is the pipeline boundary at milestone 16 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between board encoding and policy-value network and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Board To Torch Tensor as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Board To Torch Tensor depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Board To Torch Tensor needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Board To Torch Tensor can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Board To Torch Tensor changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Board Encoding and Policy-Value Network. Encode boards as tensors and assemble a convolutional backbone with policy and value heads.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 07

Build Policy Value Net — from contract to production evidence

Build Policy Value Net is the measurement at milestone 20 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between board encoding and policy-value network and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Build Policy Value Net as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Build Policy Value Net depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Build Policy Value Net needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Build Policy Value Net can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Build Policy Value Net changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Board Encoding and Policy-Value Network. Encode boards as tensors and assemble a convolutional backbone with policy and value heads.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 08

Masked Policy Logits — from contract to production evidence

Masked Policy Logits is the transformation at milestone 23 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between action masking and policy sampling and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Masked Policy Logits as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Masked Policy Logits depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Masked Policy Logits needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Masked Policy Logits can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Masked Policy Logits changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Action Masking and Policy Sampling. Mask illegal moves and turn network logits into sampled or greedy column actions.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 09

Greedy Action From Policy — from contract to production evidence

Greedy Action From Policy is the decision at milestone 26 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between action masking and policy sampling and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Greedy Action From Policy as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Greedy Action From Policy depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Greedy Action From Policy needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Greedy Action From Policy can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Greedy Action From Policy changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Action Masking and Policy Sampling. Mask illegal moves and turn network logits into sampled or greedy column actions.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 10

Ucb Score — from contract to production evidence

Ucb Score is the measurement at milestone 29 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between puct monte carlo tree search and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Ucb Score as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Ucb Score depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Ucb Score needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Ucb Score can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Ucb Score changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: PUCT Monte Carlo Tree Search. Implement nodes, PUCT selection, network-guided expansion, backup, and full MCTS rollouts.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 11

Evaluate With Network — from contract to production evidence

Evaluate With Network is the measurement at milestone 32 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between puct monte carlo tree search and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Evaluate With Network as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Evaluate With Network depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Evaluate With Network needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Evaluate With Network can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Evaluate With Network changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: PUCT Monte Carlo Tree Search. Implement nodes, PUCT selection, network-guided expansion, backup, and full MCTS rollouts.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 12

Run One Simulation — from contract to production evidence

Run One Simulation is the pipeline boundary at milestone 35 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between puct monte carlo tree search and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Run One Simulation as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Run One Simulation depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Run One Simulation needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Run One Simulation can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Run One Simulation changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: PUCT Monte Carlo Tree Search. Implement nodes, PUCT selection, network-guided expansion, backup, and full MCTS rollouts.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 13

Record Self Play Step — from contract to production evidence

Record Self Play Step is the pipeline boundary at milestone 39 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between self-play data generation and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Record Self Play Step as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Record Self Play Step depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Record Self Play Step needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Record Self Play Step can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Record Self Play Step changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Self-Play Data Generation. Use MCTS to play games against itself, recording (state, policy, outcome) training tuples.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 14

Generate Self Play Batch — from contract to production evidence

Generate Self Play Batch is the decision at milestone 42 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between self-play data generation and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Generate Self Play Batch as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Generate Self Play Batch depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Generate Self Play Batch needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Generate Self Play Batch can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Generate Self Play Batch changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Self-Play Data Generation. Use MCTS to play games against itself, recording (state, policy, outcome) training tuples.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 15

L2 Regularization Loss — from contract to production evidence

L2 Regularization Loss is the measurement at milestone 45 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between losses and training loop and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat L2 Regularization Loss as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If L2 Regularization Loss depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for L2 Regularization Loss needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how L2 Regularization Loss can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing L2 Regularization Loss changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Losses and Training Loop. Define the policy, value, and L2 losses and run minibatched training over the self-play buffer.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 16

Iterate Minibatches — from contract to production evidence

Iterate Minibatches is the pipeline boundary at milestone 48 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between losses and training loop and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Iterate Minibatches as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Iterate Minibatches depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Iterate Minibatches needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Iterate Minibatches can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Iterate Minibatches changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Losses and Training Loop. Define the policy, value, and L2 losses and run minibatched training over the self-play buffer.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 17

Self Play Iteration — from contract to production evidence

Self Play Iteration is the pipeline boundary at milestone 51 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between iterated training loop and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Self Play Iteration as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Self Play Iteration depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Self Play Iteration needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Self Play Iteration can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Self Play Iteration changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Iterated Training Loop. Alternate self-play generation and network training across many iterations.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
IMPLEMENTATION ATLAS · 18

Greedy Agent Action — from contract to production evidence

Greedy Agent Action is the decision at milestone 54 of AlphaZero on Connect-4. Its purpose is not merely to make the next function run. It establishes a contract between agents and evaluation and every downstream stage. Begin by naming the accepted inputs, their axes, units, legal ranges, ownership rules, and whether mutation is permitted. Then name the output with the same precision. In this project the surrounding ideas—PUCT, Value networks, Replay buffer—only compose correctly when this boundary preserves those invariants. A useful implementation note records one representative shape, one smallest valid example, one boundary example, and one invalid example before any optimization is attempted.

From first principles, treat Greedy Agent Action as a mapping from available information to a new state transition. Ask which information is genuinely known at this point and which information would leak from the future, evaluation set, opposing player, held-out client, or later pipeline stage. Write the transformation symbolically before translating it into array operations. Every reduction must state its axis; every probability must state its normalization set; every random choice must state its distribution and seed; every learned quantity must state the objective that changes it. This discipline turns an appealing formula into an executable specification that can be challenged with small counterexamples.

The reference implementation should favor clarity over cleverness. Separate validation, the mathematical core, and state updates so each can be tested independently. Use explicit intermediate names that correspond to the derivation rather than compressing the work into one expression. Confirm dtype promotion, broadcasting, device placement, and empty-input behavior. If Greedy Agent Action depends on randomness, pass a generator instead of reading hidden global state. If it owns mutable state, return or document the updated state explicitly. The optimized implementation may later fuse operations or reuse buffers, but it must remain numerically comparable with this small version on deterministic fixtures.

Verification for Greedy Agent Action needs more than a happy-path assertion. Prove a hand-computable normal case, a boundary case, an invalid case, and at least one invariant. Compare against seeded rollouts, learning curves, confidence intervals, and baseline matches. Add metamorphic tests when an exact answer is awkward: permutation, scaling, symmetry, conservation, monotonicity, or equivalence under a harmless representation change. Run the test repeatedly under fixed seeds to distinguish deterministic defects from statistical variation. When floating-point arithmetic is involved, justify tolerances from expected rounding error instead of choosing a loose threshold simply because the test passes.

Failure analysis asks how Greedy Agent Action can look plausible while being wrong. Inspect reward leakage, unstable bootstrapping, invalid actions, and optimistic evaluation. Trace one example through every intermediate value and preserve enough logging to reproduce it. Distinguish a contract violation from an optimization failure and from an evaluation-design failure; each requires a different repair. A numerical answer within range is not automatically meaningful, and a rising training metric is not proof that the intended signal is being learned. The strongest debugging move is usually to shrink the input until the complete computation fits on paper, then compare the paper trace with the program line by line.

Productionizing Greedy Agent Action changes the question from “does it work once?” to “does it remain trustworthy under load and change?” Measure environment interactions, exploration budget, replay reuse, and evaluation games. Define observability for inputs, outputs, latency, failures, drift, and resource saturation. Decide what happens on malformed data, cancellation, partial worker failure, unavailable accelerators, or a distribution outside the training envelope. Version configuration and schemas with the code, preserve reproducible seeds where appropriate, and expose a safe fallback. Optimization is accepted only when the reference tests, numerical comparisons, and task-level metrics remain within an explicitly documented budget.

  • Part: Agents and Evaluation. Build baseline agents, run head-to-head matches, and measure win rate against a random policy.
  • Normal case: choose the smallest input that exercises the intended transformation.
  • Boundary case: use an empty, singleton, saturated, masked, terminal, or maximum-size input as appropriate.
  • Invariant: verify shape, range, conservation, normalization, symmetry, immutability, or monotonicity.
  • Production evidence: record correctness, latency, memory or cost, and the exact configuration.
04 · REAL-WORLD USE

Where this pattern becomes useful

MCTS

Use this capability when the product must make repeatable decisions under the same structural constraints studied in the project. Begin with an offline baseline, define a business-facing metric, and add monitoring before automation.

Use case 1

Self-play

Use this capability when the product must make repeatable decisions under the same structural constraints studied in the project. Begin with an offline baseline, define a business-facing metric, and add monitoring before automation.

Use case 2

Policy learning

Use this capability when the product must make repeatable decisions under the same structural constraints studied in the project. Begin with an offline baseline, define a business-facing metric, and add monitoring before automation.

Use case 3
05 · RESEARCH EVOLUTION

How the field keeps improving

UCT turned Monte Carlo search into principled exploration, AlphaGo combined policy/value networks with MCTS and expert data, and AlphaGo Zero/AlphaZero removed human examples in favor of self-play with a shared policy-value network and PUCT. Connect-4 makes the loop tractable, but credible evaluation still needs search-budget controls, held-out opponents, symmetry augmentation, and Elo confidence intervals.

Improvements usually change one of four levers: representation, learning signal, computation path, or evaluation protocol. Read each source with its assumptions and comparison budget in view.

Treat paper claims as hypotheses: reproduce the baseline, inspect ablations, normalize compute budgets, and verify whether the evaluation matches your intended use.

06 · AFTER THE BUILD

Your next-study roadmap

  1. Re-derive

    Explain each core equation without looking at the code.

  2. Rebuild

    Implement the smallest version again from an empty file.

  3. Stress test

    Create adversarial, boundary, numerical, and distribution-shift tests.

  4. Read critically

    Choose one foundational paper and two recent follow-ups; reproduce one reported comparison.

  5. Extend

    Change one assumption, record the hypothesis, and run a controlled experiment.

  6. Publish

    Document architecture, tradeoffs, failures, metrics, cost, and reproducible commands.