Skip to content

Add AlphaZero MCTS notebook to algorithms gallery#65

Merged
koaning merged 1 commit into
mainfrom
koaning/singapore-v1
Jun 16, 2026
Merged

Add AlphaZero MCTS notebook to algorithms gallery#65
koaning merged 1 commit into
mainfrom
koaning/singapore-v1

Conversation

@koaning

@koaning koaning commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Adds an interactive marimo notebook teaching the AlphaZero algorithm via Monte Carlo Tree Search, using Connect 4 and other k-in-a-line games (built on JAX). The notebook includes PEP 723 inline dependencies and a pre-computed session snapshot for instant gallery loading. A new entry is added to the README under the Algorithms section.

🤖 Generated with Claude Code

Interactive notebook teaching Monte Carlo Tree Search via Connect 4 and
other k-in-a-line games, built on JAX. Adds PEP 723 metadata, the
generated session snapshot, and a README entry.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 16, 2026 11:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new interactive marimo notebook to the Algorithms gallery that teaches Monte Carlo Tree Search (AlphaZero-style) using Connect 4 / k-in-a-line games, and wires it into the main README index with a precomputed session snapshot for fast loading.

Changes:

  • Add notebooks/algorithms/alphazero-mcts.py implementing the interactive MCTS tutorial + playable UI.
  • Add the corresponding marimo session snapshot notebooks/algorithms/__marimo__/session/alphazero-mcts.py.json.
  • Update README.md Algorithms table to include the new AlphaZero MCTS entry.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 6 comments.

File Description
README.md Adds the new “AlphaZero MCTS” entry to the Algorithms gallery table.
notebooks/algorithms/alphazero-mcts.py New marimo notebook implementing the MCTS tutorial, tree visualization, and gameplay UI.
notebooks/algorithms/marimo/session/alphazero-mcts.py.json Precomputed session snapshot for instant gallery loading / CI validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +195 to +198
}}
</style>
</style>
"""
max_value=2,
step=1,
debounce=True,
value=[[0] * N_COLS] * N_ROWS,
Comment on lines +829 to +835
## Add the root node to the tree
if root_board is not None:
self.board[Tree.ROOT_NODE_IX] = root_board
self.player_turn[Tree.ROOT_NODE_IX] = root_player_turn
self.is_terminal[Tree.ROOT_NODE_IX] = bool(
Game.is_terminal(self.board[Tree.ROOT_NODE_IX])
)

visits = self.tree.N_sims[node_ix]
w_total = self.tree.total_sim_reward[node_ix]
raw_win_rate = w_total / visits # if visits > 0 else 0.0
Comment on lines +537 to +541
player_points = 1.0 * Game.has_k_in_a_line(state == player_turn)
opponets_points = 1.0 * Game.has_k_in_a_line(
state == (3 - player_turn)
)
return player_points - opponets_points
debounce=True,
)
random_start_turn_slider = mo.ui.slider(
label='<div data-tooltip="Start all games from a random starting position with a number of random moves played. This makes for a more dynamic opennings and/or can out the balance Player 1 advangage"> Random Start Moves </div> ',
@koaning koaning merged commit 078ef27 into main Jun 16, 2026
3 checks passed
@koaning koaning deleted the koaning/singapore-v1 branch June 16, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants