Building Decentralized Chess On The Radix Ledger

Josh Primero

We previously wrote about how gaming could be the first area to drive global adoption of cryptoassets, with the likes of non-fungible tokens offering the chance to revolutionize how collectibles and gaming intersects. For our hackathon project, we decided to port a game well over a millennium old to Radix: chess.

Why?

Typically, playing chess online requires a third party, centralised service which verifies your moves and synchronises them with another player. By integrating chess into Radix, it becomes a real-time, decentralised, auditable and ledger-verified game playable from anywhere in the world. Besides illustrating that even a game like chess can take advantage of a real-time DLT, the complex rules of chess also present an interesting challenge when ported to a decentralised platform.

How?

We decided to go all-in with implementing our chosen game and wanted to implement all its rules in Radix, so that every node can act as a chess service. This includes

Different actions depending on the piece being moved

Ensuring the player controlling white pieces goes first

Not being able to move twice before the other player moves

Once moved, a move cannot be reverted

These rules demand a certain level of versatility. Fortunately, Radix is the ideal fit for complex application logic through its unique application stack made available in the form of the Constraint Machine.

To implement the chess game, we utilised a key feature of the Radix platform: creating new logic in the form of Particles. The application stack was built from the ground up with buildability and extensibility in mind, and as such, it is trivial to add new Particles to the system.

Specifically, we added two Particles: one for the chess board, and one for a chess move.

When a player makes a move, they consume the last chess board particle and submit a new board state alongside their chess move (signed by the player). The validity and authenticity of the move is then checked by the ledger, verifying that

the move itself is legal given the referenced board state,

the referenced board state has not been consumed yet, and that

the claimed next board state is the product of applying the move to the previous board.

All this is done in real-time across the entire ledger, meaning that a player from anywhere can play on all their devices and rely on the ledger to keep them up to date.

Using the simple Radix libraries we then combined these new particles with an open source chess GUI to provide the front-end interface. Everything else runs through Radix.

If you want to understand the Constraint Machine ELI5 style, head over to this explainer blog post by Josh. Chess Guardians of the Galaxy Vol. 1

So what?

By implementing this on Radix, the chess service gains very nice features for free that would otherwise be very hard to obtain on any other platform:

Free real-time sync between all participants (i.e. can play from anywhere on multiple devices simultaneously)

Free offline play (i.e. if the node you’re using temporarily loses connectivity you can keep playing and rejoin the network gracefully once reconnected, without losing anything)

Free global consistency (i.e. no “double spends” of board states, no illegal moves, no cheating, no moving other pieces without permission, all enforced by ledger)

Free auditability (i.e. spectators can watch the game)

Implementing all these important and amazing features in Radix required a day’s work. Of course, the solution could be polished further, but the fully-functional prototype sporting all these features was completed within a day.

While chess is a toy example, it illustrates the speed of development and versatility of the Radix application stack for even complex applications. In later installments, we will look at more examples and look deeper into how Radix works for you.

Note: As the chess application is built to interact with the internal betanet, we will open-source it only after the public betanet is live.



Have questions? Message me, Alex or Greg on the Radix discord group (Discord), or you can ask them in our telegram channel (https://t.me/radix_dlt) as well.

Subscribe to our mailing list to get notified when we hit major milestones – https://radixdlt.typeform.com/to/nyKvMV?source=chessapp