![SOCIAL-Building-a-board-game-with-the-TFlite-plugin-for-Flutter.png](https://quantinsightsnetwork.com/wp-content/uploads/2023/10/SOCIAL-Building-a-board-game-with-the-TFlite-plugin-for-Flutter-678x381.png)
https://blog.tensorflow.org/2023/10/building-board-game-with-tflite-plugin-for-flutter.html
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOOPfPbEUuINDsxtTqIQnxPMLg_ThHYU0PSK5n12pt0hHAESQem0lIsnv-LO6LFCv8sq68n0dua5wPoXqiKvP8KF-WFF1s1-vpnTD3DMBrbL0IA019h1UWREjSCDEE2CEkImJ71OFBmchJWt8X5jtZkJiVIV06Ogxqhp12hzvvinVDNh1rMTecH9KIjZ8/s1600/SOCIAL-Building-a-board-game-with-the-TFlite-plugin-for-Flutter.png
Posted by Wei Wei, Developer Advocate
In our previous blog posts Building a board game app with TensorFlow: a new TensorFlow Lite reference app and Building a reinforcement learning agent with JAX, and deploying it on Android with TensorFlow Lite, we demonstrated how to train a reinforcement learning (RL) agent with TensorFlow, TensorFlow Agents and JAX respectively, and then deploy the converted TFLite model in an Android app using TensorFlow Lite, to play a simple board game ‘Plane Strike’.
![Flow Chart illustrating training a Reinforncement Learning (RL) Agent with TensorFlow, TensorFlow Agents and JAX, deploying the converted model in an Android app and Flutter using the TensorFlow Lite plugin](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQDl4Xa2yqwJdBabBma9TpiDP6oOt9DApNSnBd0u3dammHHQV5QuMS8WYj0h2xEMPWyG4bZKSDK0pFzjavXn7XscaIItUytQ-6GAtV2PBGyUZg0T7z_DXSHAhDDu8YgDeZxomS0ingTQI2llhqShlFPMVqgAK3UtgbaxKa-AE05RPabKfVFK_ezxyh5pc/s1600/CHART-Building-a-board-game-with-the-TFlite-plugin-for-Flutter.png)
Since we already have the model trained with TensorFlow and converted to TFLite, we can just load the model with TFLite interpreter:
Then we pass in the user board state and help the game agent identify the most promising position to strike next (please refer to our previous blog posts if you need a refresher on the game rules) by running TFLite inference:
That’s it! With some additional Flutter frontend code to render the game boards and track game progress, we can immediately run the game on both Android and iOS (currently the plugin only supports these two mobile platforms). You can find the complete code on GitHub.
![]() |
If you want to dig digger, there are a couple of things you can try:
- Convert the TFAgents-trained model to TFLite and run it with the plugin
- Leverage the RL technique we have used and build a new agent for the tic tac toe game in the Flutter Casual Games Toolkit. You will need to create a new RL environment and train the model from scratch before deployment, but the core concept and technique are pretty much the same.
This concludes this mini-series of blogs on leveraging TensorFlow/JAX to build games for Android and Flutter. And we very much look forward to all the exciting things you build with our tooling, so be sure to share them with @googledevs, @TensorFlow, and your developer communities!
Be the first to comment