# Stockfish is on-chain: play chess against the world's strongest open-source engine, running in one C++ canister

**URL:** <https://forum.dfinity.org/t/stockfish-is-on-chain-play-chess-against-the-worlds-strongest-open-source-engine-running-in-one-c-canister/76222>\
**Category:** Showcase\
**Created:** [October 25, 2026, 4:45am UTC](https://forum.dfinity.org/t/stockfish-is-on-chain-play-chess-against-the-worlds-strongest-open-source-engine-running-in-one-c-canister/76222 "2026-10-25T04:45:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kanodia](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/kanodia/32/23489_2.png) [@kanodia](https://forum.dfinity.org/u/kanodia)\
**Post date:** [October 25, 2026, 4:45am UTC](https://forum.dfinity.org/t/stockfish-is-on-chain-play-chess-against-the-worlds-strongest-open-source-engine-running-in-one-c-canister/76222/1 "2026-10-25T04:45:20Z")

</div>

Hi everyone,

I ported **Stockfish** to an ICP canister, and you can play against it here:

▶ **Play:** [https://ne5l7-xiaaa-aaaaj-qsm3q-cai.icp0.io](https://ne5l7-xiaaa-aaaaj-qsm3q-cai.icp0.io)  
💻 **Code** (GPL-3, like Stockfish): [https://github.com/kanodia/play-the-chain](https://github.com/kanodia/play-the-chain)  
♟ **Example game, replayed from the canister:** [https://ne5l7-xiaaa-aaaaj-qsm3q-cai.icp0.io/game/3](https://ne5l7-xiaaa-aaaaj-qsm3q-cai.icp0.io/game/3)  
🔎 **Canister on the IC dashboard:** [https://dashboard.internetcomputer.org/canister/ne5l7-xiaaa-aaaaj-qsm3q-cai](https://dashboard.internetcomputer.org/canister/ne5l7-xiaaa-aaaaj-qsm3q-cai)  
🐦 **On X:** [https://x.com/abhi\_kanodia803/status/2114213543235235884](https://x.com/abhi_kanodia803/status/2114213543235235884)

### What is Stockfish?

It’s the strongest open-source chess engine in the world, and has been the top computer chess engine for years. Grandmasters use it to analyse their games. It’s over 12,000 lines of heavily optimised C++, the kind of code you’d normally never expect to run inside a smart contract.

### What runs on-chain

There’s no server and no frontend hosting. One canister does everything:

- serves the web page,
- referees the game (checks your move is legal, detects checkmate, stalemate, threefold repetition and the 50-move rule),
- thinks of its reply: a full Stockfish search, computed by all 13 nodes of the subnet and agreed on by consensus,
- writes every move to stable memory, so each game gets a permanent link anyone can replay (`/game/<id>`), plus a raw JSON record (`/api/game/<id>`).

For each engine move the page shows a receipt: how many positions it searched, how many instructions that took, and roughly what it cost in cycles. The canister pays (reverse gas), so players don’t need a wallet.

### How

- Stockfish 11 (the last version before neural nets), compiled to wasm with [icpp-pro](https://github.com/icppWorld/icpp-pro). Wasm is about 2.65 MB.
- The IC has no threads, so a small `SF_NO_THREADS` patch makes the search run synchronously inside a single update call. Apart from that the engine code is unchanged, and node counts match a native build exactly.
- Cost is about 8–9.5k instructions per searched position. A depth-18 move takes around 12B instructions, which fits comfortably inside the 40B per-message limit, so each move is one update call. There’s no need for chunking or timers.
- All HTTP routes go through `http_request_update`, so the responses are certified.
- There’s a daily budget: moves are full strength up to a daily allowance, then lighter searches, then the canister politely says “come back tomorrow”. It’s funded by a small cycles balance, so please be gentle 🙂

### Thanks

Big thanks to the @icpp and onicai. Porting a large real-world C++ codebase was much smoother than I expected, and I think it’s a great showcase of what C++ canisters can do.

Feedback welcome, and so is a game. Can anyone beat it?

---

<div class="post-metadata">

**Author:** ![WebTreeSoftwareSolut](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/webtreesoftwaresolut/32/35012_2.png) [@WebTreeSoftwareSolut](https://forum.dfinity.org/u/WebTreeSoftwareSolut)\
**Post date:** [October 25, 2026, 5:50am UTC](https://forum.dfinity.org/t/stockfish-is-on-chain-play-chess-against-the-worlds-strongest-open-source-engine-running-in-one-c-canister/76222/2 "2026-10-25T05:50:44Z")

</div>

> [@kanodia](#):
>
> Can anyone beat it?

**No**.

Thanks for sharing your work here.

---

<div class="post-metadata">

**Author:** ![Jacc1027](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jacc1027/32/23820_2.png) [@Jacc1027](https://forum.dfinity.org/u/Jacc1027)\
**Post date:** [October 25, 2026, 6:51am UTC](https://forum.dfinity.org/t/stockfish-is-on-chain-play-chess-against-the-worlds-strongest-open-source-engine-running-in-one-c-canister/76222/3 "2026-10-25T06:51:29Z")

</div>

Nicely done 🙂

Ccçcccccccccccccccccccccccccccccccccccccçccccccccccccccccç

---

<div class="post-metadata">

**Author:** ![kanodia](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/kanodia/32/23489_2.png) [@kanodia](https://forum.dfinity.org/u/kanodia)\
**Post date:** [October 25, 2026, 1:29pm UTC](https://forum.dfinity.org/t/stockfish-is-on-chain-play-chess-against-the-worlds-strongest-open-source-engine-running-in-one-c-canister/76222/4 "2026-10-25T13:29:03Z")

</div>

Thank You @WebTreeSoftwareSolut

Really enjoyed working on it too

---

<div class="post-metadata">

**Author:** ![kanodia](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/kanodia/32/23489_2.png) [@kanodia](https://forum.dfinity.org/u/kanodia)\
**Post date:** [October 25, 2026, 1:30pm UTC](https://forum.dfinity.org/t/stockfish-is-on-chain-play-chess-against-the-worlds-strongest-open-source-engine-running-in-one-c-canister/76222/5 "2026-10-25T13:30:28Z")

</div>

Thankssssssssssssssssss

@Jacc1027

Thanks much! …

---

<div class="post-metadata">

**Author:** ![kanodia](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/kanodia/32/23489_2.png) [@kanodia](https://forum.dfinity.org/u/kanodia)\
**Post date:** [October 28, 2026, 3:22pm UTC](https://forum.dfinity.org/t/stockfish-is-on-chain-play-chess-against-the-worlds-strongest-open-source-engine-running-in-one-c-canister/76222/6 "2026-10-28T15:22:17Z")

</div>

**Update: move 2 is physics ⛳**

The same canister now runs [Box2D](https://box2d.org), the C++ physics engine behind Angry Birds and Limbo, in a new game: **Chain Golf**.

▶ **Play:** [https://ne5l7-xiaaa-aaaaj-qsm3q-cai.icp0.io](https://ne5l7-xiaaa-aaaaj-qsm3q-cai.icp0.io)

### ⛳ Chain Golf

Box2D 2.4.2 is vendored **unchanged** : it compiled for the IC with icpp-pro without a single patch.

- One hole a day, generated from the date, so everybody plays the same one.
- The browser sends only an angle and a power. The canister simulates the shot at 60 Hz until the ball stops, sinks or goes out, stores it, and returns the path for the page to animate.
- So the leaderboard can’t be faked: the score is whatever the chain computed. `GET /api/golf/round/<id>/shot/<n>` makes the canister simulate any stored shot again and report whether it lands in exactly the same place. It does, bit for bit, because wasm floats are deterministic.
- A shot is about 12M instructions, roughly a thousandth of one chess move.

### ⛽ A shared fuel tank

Everything is reverse gas, so players need no wallet. To keep it running without one person paying forever, anyone can send ICP to the canister’s principal (from funnAI, the NNS app or any wallet) and press Refuel. The canister then:

1. checks its ICP balance on the ledger,
2. transfers it to the cycles minting canister with the top-up memo, and
3. calls `notify_top_up` to turn it into its own cycles.

Engine moves pause before the freezing threshold, so the canister never freezes and the page can still ask for fuel. The [dashboard](https://ne5l7-xiaaa-aaaaj-qsm3q-cai.icp0.io/games) shows every game and the cycles it used.

### Also new

- A home page that links both games. Chess moved to `/chess`; old `/game/<id>` replay links still work.
- For C++ devs: icpp-pro’s C++20 coroutines made the ledger and CMC calls straightforward. The ledger’s error types are large, so I decode only the `Ok`/`Err` label of their Candid replies with a small parser.

Next on my list: certified assets, so pages load faster. And still open to suggestions: **which C++ library should run on-chain next?**

---

<div class="post-metadata">

**Author:** ![icpp](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icpp/32/9310_2.png) [@icpp](https://forum.dfinity.org/u/icpp)\
**Post date:** [October 28, 2026, 6:46pm UTC](https://forum.dfinity.org/t/stockfish-is-on-chain-play-chess-against-the-worlds-strongest-open-source-engine-running-in-one-c-canister/76222/7 "2026-10-28T18:46:43Z")

</div>

I can’t beat it

> [@kanodia](#):
>
> - icpp-pro’s C++20 coroutines made the ledger and CMC calls straightforward. The ledger’s error types are large, so I decode only the `Ok`/`Err` label of their Candid replies with a small parser.

This is nice to see. Before C++ canisters were able to make their own cross-canister calls, it was always needed to put a Motoko “controller or gateway” canister in front of it, and it introduced additional cross-canister hops from frontend \> gateway \> C++ engine. Now it is direct, which makes is cheaper in cycles and with less latency.

Did you need to use the capability to yield the instruction budget so the C++ engine can go beyond the 40B instructions limit per update call, or did it all fit within a single update call of 40B instructions?

---

<div class="post-metadata">

**Author:** ![icpp](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icpp/32/9310_2.png) [@icpp](https://forum.dfinity.org/u/icpp)\
**Post date:** [October 28, 2026, 6:50pm UTC](https://forum.dfinity.org/t/stockfish-is-on-chain-play-chess-against-the-worlds-strongest-open-source-engine-running-in-one-c-canister/76222/8 "2026-10-28T18:50:31Z")

</div>

> [@kanodia](#):
>
> which C++ library should run on-chain next?

**xgboost** would be very interesting.

That would allow to use decistion tree models for all kinds of stuff. For many years, xgboost models won every single ML competition, and I think it is a good fit for an IC canister.

---

<div class="post-metadata">

**Author:** ![WebTreeSoftwareSolut](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/webtreesoftwaresolut/32/35012_2.png) [@WebTreeSoftwareSolut](https://forum.dfinity.org/u/WebTreeSoftwareSolut)\
**Post date:** [October 28, 2026, 9:02pm UTC](https://forum.dfinity.org/t/stockfish-is-on-chain-play-chess-against-the-worlds-strongest-open-source-engine-running-in-one-c-canister/76222/9 "2026-10-28T21:02:47Z")

</div>

thats very impressive. Call me old fashioned but I actually still prefer c over c++. And box2d is a useful library but you just dont get the unique feeling of a custom physics engine. Rigid body’s just feel a bit _rigid._

In _my_ opinion.

getting a physics engine on chain though, that’s an impressive thing for sure.
