AI has several applications but Gaming might be the most fascinating one! So how about we talk a little about AI Gaming & all the amazing things it brings to the table when industry-leading cloud computing service Azure and my favorite programming language Python comes together.
What is AI Gaming?
In classic gaming, we bring together two players and they play the game accordingly to score maximum points and the one with maximum points, well as you've guessed, wins the game.
AI Gaming is the same thing, but here you bring two programmers and they code their bots (or scripts). Both bots are programmed to play the same game and the bot which is faster, more accurate & can score more points will win the game.
Sounds fun right!
AI Gaming Platform
What if I tell you, there's an entire platform dedicated to AI Gaming where you can learn, code & compete with your bots? Well, I am not kidding, you can see yourself here aigaming.com.
Throughout this article, we are going to explore the platform and see how it works plus how you can create bots and power them with Azure's cutting-edge Cognitive Services.
Setting up your AI Gaming Account
Alright so before we do anything, let's quickly create your AI Gaming Account.
Go ahead and click on the Register on the top right corner and fill in your email, a strong password, a fancy username, and click on register. I'll leave the rest on you.
Now once you've successfully registered and logged in to your account, we can proceed to further steps.
Getting familiar with the Interface
Let's quickly gaze over the essential components the AI Gaming so we can quickly get started coding out bots.
In the top header, we have a few options:
- Games: Under this menu, you can browse through all the games you can play on the AI Gaming platform. Every game is different, hence the strategies & code for each will be different as well. You can also register for tournaments & compete with other players.
- Editor: The editor is where you will be writing all your code. This is where you'll probably spend most of your time.
- My Account: Here you can find all the account and bot management options. Nothing much to worry about here.
- Help: Help section is full of useful & beginner-friendly tutorials to help you get started with AI Gaming.
For now, you can ignore the About us & News Section.
Let's Get Coding!
Alright, so the fun part begins here! Let's do it!
Creating a Bot
So the first thing is to create a bot before we start coding it. Here's how to do it -
-
Head to the Bot Management Section in the My Account Dropdown.
-
Now create a new bot from the top right corner
-
Give your Bot a name and click on OK
Getting your Azure Computer Vision API Key
Although there are many games available for you to play on the AI Gaming Platform, for the sake of this tutorial we are going to play the good old Match Game. Now in Match Game, you have match titles with similar content. The catch is, to match the content, you have to turn the tiles to see what content it has and remember it, then you have to locate a tile with similar content to lock them and score the point. The bot with higher points and minimum turns will win the game.
To increase our odds of winning, we can make use of Azure's Computer Vision API Key to give our bot the power of AI.
To create an Azure Computer Vision API Key, follow these steps:
- Create an account on Azure. If you are a student, then you can get the free student credits to get started.
- Once done, head on to the Azure Portal.
-
Now click on Create a Resource
-
Now from the left-hand category list, select AI + Machine Learning category
-
Now from the right-hand list, click on Computer Vision
-
Now here are a few things you need to fill in to create the API
- Subscription: Select the subscription you would like to continue with. Most probably it will be your student subscription.
- Resource Group: Resource Groups are nothing but just a way to group certain resources to help you become organized. You can choose any of your previous resource groups or if you don't have any yet, you can create a new one easily.
- Region: Region is where your resource in the world will be located. You should make sure that your resource region is close to your current location so that latency can be minimized. If you're in India, then you are highly recommended to go for the West Europe region.
- Name: You have to give some name to your resource.
- Pricing tier: Here you have to select what tier you prefer. If you have the subscription then go for, Standard S1 tier since you can make more calls per minute with this tier, hence making it an ideal option for the AI Gaming tournaments.
Once done, click on **Review + Create**
-
Once your resource is successfully deployed, you will see this message. Simply click on Go to Resource
-
Now under the Resource Management in the left-hand sidebar, go to Keys and Endpoint
-
Now you will see the two API Keys that have been generated for you, copy any one of these & finally let's get to coding.
Writing some code
Now since your API keys are ready, head back to AI Gaming Platform & jump to the editor.
-
Click on the New & select Microsoft API Template.py
-
Give the file a name & click on YES
-
Now you will see a lot of readymade code over here. This will be helpful since we don't have to type everything manually.
-
Online 7, make sure the
botName
variable is set to the Bot you created. In my case it wasbotName='mindninjaX-defbot'
. -
One last thing, on line 16, we have to add our API key, which we generated in the last step.
headers_vision = {'Ocp-Apim-Subscription-Key': 'YOUR-WESTEUROPE-MICROSOFT-COMPUTER-VISION-API-KEY', 'Content-Type': 'application/octet-stream'}
Here we simply have to replace
YOUR-WESTEUROPE-MICROSOFT-COMPUTER-VISION-API-KEY
with our API Key.For example if your API Key is
2f6c3c7d02db4490a6ac00a10a7af82e
, then the line 16 will look like this:
headers_vision = {'Ocp-Apim-Subscription-Key': '2f6c3c7d02db4490a6ac00a10a7af82e', 'Content-Type': 'application/octet-stream'}
-
Save your code.
-
Now make sure that you have selected the Match Game in the Game Type dropdown since we are going to play Match Game. And also make sure that you have selected the housebot-practise bot in the Opponents dropdown.
-
Now finally, let's run our code!
Now you will see the game has started.
And since we are using Azure Computer Vision API Key, our Bot easily won the game with a large margin in the score.
-
That's it!
That was a lot! But honestly speaking we only scratched the surface of what's possible with Azure & AI Gaming. I highly encourage you to go ahead and play an AI Gaming Game & invite your friends to see who can score more points. With the power of Azure, the sky is the limit.
Thank you!
Thank you so much for reading! I hope you found this beginner tutorial useful.
Also if you have any questions or doubts feel free to contact me on Twitter, LinkedIn & GitHub. Or you can also post a comment/discussion & I will try my best to help you :D
Top comments (1)
Detailed and neat article.
Thanks for this 🔥 🔥