Add AlphaZero MCTS notebook to algorithms gallery#65
Merged
Conversation
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>
There was a problem hiding this comment.
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.pyimplementing the interactive MCTS tutorial + playable UI. - Add the corresponding marimo session snapshot
notebooks/algorithms/__marimo__/session/alphazero-mcts.py.json. - Update
README.mdAlgorithms 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> ', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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