Challenge an advanced ML-powered bot in a game of Tic Tac Toe within PixeLAW, a blockchain-based pixel landscape, using on-chain ML inference to power real-time strategy.
Our project brings the nostalgic game of Tic Tac Toe into the futuristic PixeLAW world, enhanced with on-chain machine learning intelligence. It pits players against an ML bot within a pixel-based autonomous world. The integration of machine learning aims to provide a challenging opponent capable of strategic gameplay, all running within a decentralized environment. As players interact with the pixel grid, the game contract records their moves, while the ML bot calculates and places its counters in real-time. Our game offers a seamless blend of classic fun and cutting-edge technology, giving a glimpse into the future of on-chain gaming and AI.
The tech stack used:
We set out to build our idea within PixeLAW, a Smart Contract Playground built on Dojo Engine, on Starknet. This allowed us to focus on implementing the logic, as the UI/UX is taken care of by PixeLAW.
We built this immersive game starting with the smart contract 'app.cairo,' which lays down the rules and mechanics for the game within PixeLAW's ecosystem. The players interact with the game using simple grid selections that translate their moves into state changes in the contract. Our ML bot was initially trained on a conventional ML setup and was meticulously transpiled into Cairo with Giza. This innovative process allows it to run inference entirely on-chain for responsive gameplay.
The development of the ML model followed these steps:
The TicTacToe game is rooted in the PixeLAW world by registering the game with personalized game dynamics and iconography. Using Dojo, we set up the world contract to keep track of the ongoing game states between players and the ML bot. Actions such as initiating a game, player's moves, and the bot's responses leverage Dojo's world dispatcher to maintain consistency and enforce game rules within the contracts.
The React frontend delivers an engaging experience for the users by letting them interact with the game's user interface in their web browsers. Our contract ensures that moves are legal and executed in turns, maintaining the integrity of the game's progression and outcomes. Handling an ML bot on-chain required overcoming the computational and gas limitations of smart contracts. We achieved a balance between complexity and performance, ensuring the game remains fast and cost-effective for the players. Overall, our game showcases the practicality of integrating machine learning into smart contracts and offers a fun, interactive way for the community to engage with blockchain technology.