Recently, I had a conversation with @aliaksandrh.near about the need for more accessible on-chain games on @NEAR. With the development of decentralized frontends through #NEARistheBOS, we aim to encourage more people to interact with the chain. The simplest and most effective way to achieve this goal is through games, as they appeal to a broad audience. Imagine a dedicated games hub on @self.social.near where users can choose to play against either an AI or another player. Such a games hub would provide an immersive experience that could help draw more users to the NEAR ecosystem. With the ability to play games on-chain, users could enjoy the added benefits of decentralization, such as greater security, transparency, and control. Additionally, on-chain games could pave the way for new economic models and opportunities for game developers. With NEAR's low fees and fast transactions, developers could experiment with innovative gaming concepts and monetization strategies. I think turn based games are very well suited to be implemented fully on chain, so I decided to develop an on chain chess game and it's now in a state where you should definitely try it out. Of course it's developed [open source](https://github.com/Tarnadas/chess-on-chain). I forked an already existing [chess engine](https://github.com/Tarnadas/chess-engine) and added all the things necessary to store the game state on chain, but before we dive into the technical details I will explain how to play it. You need to visit [this website](https://raen.shroomkingdom.net/#/near/app.chess-game.near) which gives you an interface to interact with all the view and change methods of the contract. You need to login with your wallet on the top left.  The first thing you need to do to be allowed to interact with the contract is to pay the storage deposit, so go to the `storage_deposit` function and insert the yoctoNear amount that is shown in the description, which is equivalent to 0.05N.  Now you're ready to create an AI game, so open the `create_ai_game` method, select your preferred difficulty and send the transaction. The output will show you a number that you need to copy.  Let's first render the board before we do our first move, so go to `render_board`. The first argument is the copied number, the 2nd argument is your wallet ID and the 3rd argument is "Option 2". It should now render the default board.  If you lost the copied number you can always go to `get_game_ids` and insert your wallet ID to check all your open games.  Now go to `play_move`. Insert the same game_id as before. The "mv" value is the move that you will play, e.g. "d2d4". You need to add one "0" to the attached gas, because the UI fills it by default with 30TGas. We might need more gas depending on the difficulty setting.  Once you send the transaction you will get a confirmation including the AIs move and the newly rendered board. Go on by sending additional `play_move` transactions until the game is finished.  Now let's dive into the technical details. The website you visited is a fork of [Raen](https://github.com/raendev) Admin. They do awesome work to support an Application Binary Interface (ABI) for Near smart contracts. I forked it so that I can make the chess game look better. Their approach uses WebAssembly Interface Types (WIT), which is an already existing standard to interact with WASM compiled libraries, so it is very well suited to also be used by Near smart contracts. [Nearblocks](https://nearblocks.io/) also supports Raen compiled smart contracts and can render their ABI. The approach of Raen is different than the official ABI efforts of @PagodaPlatform.near. Hopefully they will find common ground. I prefer using Raen, because it uses already existing standards and makes them available for the Near ecosystem, which is great! The chess engine I chose comes with an AI, but the problem I faced was too high gas usage on higher difficulties, so I had to tweak the algorithm to not exceed the hard limit of 300TGas. I also added some randomness so that every game is unique and the AI behaves differently. This can be achieved by using Near SDK's `env::random_seed()` function, which derives a random seed. More information about [random numbers on Near](https://docs.near.org/develop/contracts/security/random). I have not yet developed a BOS component, but I already wanted to show you my progress and that it's already possible to play against an AI. You can expect me to develop a BOS component, so that you can play chess on http://alpha.near.org or @self.social.near Here's also a [Twitter thread](https://twitter.com/marior_dev/status/1638167624939978753) for sharing.