Summary: Speed Star is a web based game where players race, train, and breed horses. In order to do well in races, it’s important for players to obtain the best horses on the market. Horses have numerous attributes that determine how well they’ll do in a race, including their speed, stamina, etc. However, the data to make educated decisions on which horses to buy and breed is only available through the UI on the game website, where it is difficult to navigate efficiently.
Objectives:
- Create a tool that allows players to easily check the attributes of a horse.
- Create a database that allows players to easily sort, filter, and compare horses.
Objective 1: Create a tool that allows players to easily check the attributes of a horse
Accessing data for the project
First, I needed a way to obtain data about each horse. I went to the Speed Star game website where it displayed horses. By opening a network inspect window and filtering by “api”, I was able to identify a URL which listed all of the data I needed in JSON format.
I verified that I was able to access data for any horse by simply changing the last digits in the URL.
However, the data wasn’t very readable. So, I used a JSON formatter to clean up the data. I then took note of all of the data points I was interested in, as I would need these later.
Great! Now that I knew where my data was, I wanted to view it using Python. On my local machine, I used the following script to map out the data and verify that I was seeing the values I expected by printing it to the console:
Creating a discord bot
Now that I was able to pull data for any horse, the next step was to make the data easily readable and accessible. People that play Speed Star generally use Discord (a messaging/chat room app) to discuss the game. I decided to create a bot that would connect to the discord server and pull data on request.
I began by importing the required libraries, including discord, requests, and json. I also needed commands from discord.ext so that the bot could listen for specific commands. To make it simple, I configured the bot to respond to anyone that typed “!horse ####” into the chat (the #### would be the ID of the horse that the player wanted to view).
Now that the bot can respond to commands, I used the script from early to request horse data from the Speed Star website and put each point of data into a variable.
Unfortunately, the data I was requesting only displayed the value of a given attribute, and not the maximum value. For example, it’s useful to the player to not only know that a horse has 50 speed, but that it could potentially grow to 100 speed. To get around this, I defined three variables for each attribute; one for the current value, one for the maximum value, and another to display both values in a string.
To make things more complicated, a horse can have one of five rarities. Each rarity has a different maximum value for its stats, so I needed to put these values into a variable and display them based on the horse’s rarity. Here’s what the code looks like to request data from a given horse:
At this point, if a user were to type “!horse 3333” into the chat, they’d see the following:
That works well enough, but I wanted to make it look more presentable and provide more value. So, I improved the formatting, added an image of the horse instead of a placeholder, and performed some data analysis to display at the top of the response. Using this bot, a player would be able to tell how a given horse stacks up against the others with ease:
I didn’t want to continue hosting the bot on my local machine, so I decided to host it in the cloud. This would allow people to use the bot anytime as it would always be running. I wanted to get exposure to AWS, so I signed up for an account and performed the following steps (note: the documentation for this section is limited as I no longer have access to this account):
- Create a virtual machine
- Install python
- Upload python script for bot
- Create a cron script to start the discord bot automatically if the server ever restarts
Finally, you can see the completed project below. A user is able to type “!horse ####” into the discord chat and the bot responds with the requested data. My first objective for this project is complete, I’ll explain the second in Part 2.