
Implementing AI-Powered Matchmaking with Amazon GameLift FlexMatch

In the first part of this two-part blog series, we showed you how to use Amazon SageMaker AI, a suite of ML tools, to create and deploy an automated ML pipeline… In this blog, we’ll show you how to use this skill value in conjunction with Amazon GameLift Servers FlexMatch (FlexMatch)… We’…
In competitive multiplayer games, skill-based matchmaking is crucial for creating fun and engaging games. Determining player skill today is difficult due to the vast array of metrics games record such as hits, misses, assists, time played, level, and more. This can make it challenging to manually determine which factors are most indicative of skill.
Instead of manually creating algorithms to determine player skill, machine learning (ML) techniques—particularly supervised learning—can automatically identify patterns across game metrics to produce more accurate skill ratings. These ML-derived ratings enable more balanced matchmaking, ultimately enhancing player satisfaction and engagement.
In the first part of this two-part blog series, we showed you how to use Amazon SageMaker AI, a suite of ML tools, to create and deploy an automated ML pipeline. This ML model produced a skill value that is a more reflective and precise rating of each player’s actual skill.
In this blog, we’ll show you how to use this skill value in conjunction with Amazon GameLift Servers FlexMatch (FlexMatch). FlexMatch handles the logic of matchmaking players while giving you, the developer, a way to adjust which matches are created through a rules-based syntax called FlexMatch rule sets.
We’ll demonstrate how to create matchmaking rules for creating teams of players with similar skills. We’ll also highlight how to test these rule sets by simulating matchmaking using the Amazon GameLift Testing Toolkit. This toolkit helps game developers to optimize their multiplayer games by providing ways to visualize Amazon GameLift infrastructure, launch virtual players, iterate on matchmaking rules, and simulate matchmaking events. By using the Amazon GameLift Testing Toolkit, you can quickly test the performance of your model and matchmaking solution before deploying your matchmaking solution to production servers.
Walkthrough
Prerequisites
For this walkthrough, you should have the following prerequisites:
- Completed the steps included in part 1 of this series.
- To download the code we will need for this tutorial, choose FlexMatchSimulator.cs. This will take you to the page where you can choose the “Download raw file” option (as seen in Figure 1).
- Deployed the Amazon GameLift Testing Toolkit. You will not need to deploy the sample game for this tutorial.
Understanding the Amazon GameLift Testing Toolkit solution
The illustration in Figure 2 shows you the architecture Amazon GameLift Testing Toolkit deploys.
Typically, designing and testing matchmaking systems comes very late in the game development cycle because it requires a working game client and running game servers. Additionally, to thoroughly test your game infrastructure at a scale realistic to what you expect during launch, you either need to gather a large volume of players or create virtual players. This can increase your overall cost and infrastructure management overhead.
The Amazon GameLift Testing Toolkit provides game developers with a test harness and visualization tool for Amazon GameLift and FlexMatch. This tool allows game developers to begin testing their game’s matchmaking logic early in the development process, since it does not require running game servers, virtual players, or a completed game client. It instead creates virtual players and runs simulated matchmaking sessions. To learn more about the architecture that the Amazon GameLift Testing Toolkit deploys, see the Amazon GameLift Testing Toolkit Guidance. For a more in-depth guide into what you can do with the Amazon GameLift Testing Toolkit, see the Amazon GameLift Testing Toolkit documentation.
Deploy the Amazon GameLift Testing Toolkit solution
First, download and follow the instructions in the Amazon GameLift Testing Toolkit repository. After you follow the instructions, navigate to the resulting Amazon CloudFront URL and sign in, you will see a page that looks like Figure 3.
Configuring player profiles in the testing toolkit
In order to perform matchmaking, we will be using Amazon GameLift Servers FlexMatch. To test FlexMatch on the Amazon GameLift Testing Toolkit we will need:
- A pool of player profiles to simulate matchmaking between
- The rule set(s) we want to test
For a more in-depth guide on how FlexMatch works, including more capabilities and in-depth instructions on how to test FlexMatch with the Amazon GameLift Testing Toolkit, read: Fine-tune online game matchmaking with Amazon GameLift FlexMatch rule sets and the Amazon GameLift Testing Toolkit.
For this specific blog, create the components we need by following these instructions:
- From the Amazon GameLift Testing Toolkit dashboard, choose the gear icon on the top left corner.
- Choose FlexMatch Simulator.
- Choose Player Profiles. You will see something similar to Figure 4, which shows you all your player profiles.
- Choose Create Player Profile. You should see a form to give the player profile name and add any number of attributes to it, as shown in Figure 5.
- For the name, enter Good Player.
- Choose Add Attributes.
- Enter the following values with the Number attribute type. Choose Add Attribute to add each new one:
- kills: 1755500
- hits: 3672500
- timePlayed: 1250
- gamesPlayed: 7830
- assists: 2125
- misses: 16017200
- shots: 19689500
- deaths: 100420
- winRate: 60
- Choose Create Profile.
- Choose Create Player Profile.
- For the name, enter Bad Player.
- Choose Add Attributes.
- Enter the following values with the Number attribute type. Choose Add Attribute to add each new one:
- kills: 10
- hits: 60
- timePlayed: 5
- gamesPlayed: 12
- assists: 2
- misses: 160
- shots: 196
- deaths: 100
- winRate: 30
- Choose Create Profile.
Configuring your matchmaking rules for your FlexMatch matchmaker
- Open the Amazon GameLift Servers console dashboard.
- Choose Matchmaking rule sets under the FlexMatch section of the menu on the left side.
- Choose Create matchmaking rule set.
- Select From scratch and choose Next.
- Give your rule set the name: FairTeams.
- Copy and paste the following JSON into your rule set:
- Choose Create.
Integrating the Amazon GameLift Testing Toolkit with Amazon SageMaker AI
In this portion of the tutorial, you will be modifying the FlexMatch Simulator backend code to send player attributes to your newly created Amazon SageMaker AI endpoint to inference the player’s “skill” before matchmaking occurs.
Figure 11 is the architecture you will be implementing in the lab. The diagram shows the flow of how a player’s matchmaking request is handled. The matchmaking request triggers Amazon API Gateway, invoking an Amazon Web Services (AWS) Lambda function, which receives the relevant player data from Amazon DynamoDB. The data is then passed to the Amazon SageMaker AI endpoint, which generates a comprehensive skill value that is then passed to FlexMatch for matchmaking.
Figure 12 shows how you would implement this solution in an actual game by connecting FlexMatch to an Amazon GameLift queue. The queue triggers Amazon GameLift to either place players in servers or spin up additional game servers for the newly created matches.
- Navigate to your development environment with the agttworkshop.
- We need to modify the matchmaking simulation in order to inference each player’s “skill” attribute before matchmaking. To do this we will modify /amazon-gamelift-testing-toolkit/ManagementConsole/Backend/ManagementService/FlexMatchSimulator.cs to feed the player stats to the SageMaker AI endpoint and simulate matchmaking with the new skill attribute. Replace the contents of the current cs file with the version you downloaded in the Prerequisites section of this blog.
- Navigate to the directory /amazon-gamelift-testing-toolkit/ManagementConsole/Backend/ManagementService and install the dependencies by executing the following commands in your command line:
cd ManagementConsole/Backend
dotnet add package AWSSDK.DynamoDBv2 --version 3.7.101.31
dotnet add package AWSSDK.SagemakerRuntime --version 3.7.101.33
dotnet add package AWSSDK.SagemakerModel --version 3.7.101.33
- Now that we have made our changes, we need to rebuild and re-deploy the solution. In your command line, execute the following:
yarn build-toolkit
yarn deploy-toolkit
- Once the changes are deployed, open the AWS Lambda console and choose the Function that starts with AGTT-ManagementConsoleSta-FlexMatchSimulatorLambda.
- In the section under Function overview, select the Configuration tab, then select Permissions from the left side menu. Select the role associated with the Execution role.
- Choose Add permissions, then choose Create inline policy.
- For service, choose SageMaker. For actions select InvokeEndpoint for All Resources for the purpose of this demonstration. Choose Next.
- For the name of the inline policy enter InvokeSageMaker. Choose Create policy.
- Return to the Amazon GameLift Testing Toolkit dashboard and choose the gear icon in the top left corner of the page.
- Choose FlexMatch Simulator.
- Choose Simulate Matchmaking.
- For the rule set choose FairTeams.
- For the Player Profiles, under Profile, choose Good Player. For number of players, enter 8. Choose Add Player Profile.
- For the second profile, under Profile, choose Bad Player. For number of players, enter 8. Choose Add Player Profile.
- Choose Run Simulation. A successful result will display: Status: Simulation Complete (see Figure 17).
- To view the details of the match you can choose SHOW SIMULATION RESULTS. On the table, shown in Figure 18, you’ll see the number of each player profile placed on each team.
- Choosing Match Info on each of the items in the table will show you more details about who was placed together in a match.
Reviewing the results, you can see the good players were matched up in the same session as the other good players, and the bad players were matched up in the same session as the other bad players.
Next, we’ll show you how to clean up what you’ve deployed during this blog series demonstrations.
Cleaning up
Deleting the Guidance for AI-Driven Player Insights
Delete the S3 bucket
- Open the Amazon S3 console and select the radio button for the bucket that was created by the PlayerSkills-Stack, then choose Empty.
- Once the bucket is empty, select the radio button again and choose Delete.
Once you have deleted the S3 bucket, there are two options for deleting the deployed guidance:
- Using the AWS Management Console
- Open the AWS CloudFormation console, and select the AWS Region into which you have deployed the guidance.
- Select the radio button for the deployed stack (such as, PlayerSkills-Stack).
- Choose Delete to start the stack deletion.
- Choose Delete to confirm stack deletion.
- Using the CDK AWS Command Line Interface (AWS CLI)
- Using your terminal on your device, change to the root of the cloned repository:
cd ~ /player-insights
- Run the command to delete the CloudFormation stack:
cdk destroy
- When prompted, “Are you sure you want to delete”, enter Y to confirm stack deletion.
- Using your terminal on your device, change to the root of the cloned repository:
Delete the Amazon SageMaker AI endpoint
- Navigate to the Amazon SageMaker AI console and under the Inference section, choose
- Select the radio button next to the endpoint you created, and choose Actions, then Delete.
Delete the Amazon SageMaker AI domain
- Navigate to the Amazon SageMaker AI console. Under the left side menu, choose Domains.
- Choose your domain, and choose the User Profiles
- Select your user profile, and then select Delete.
- Navigate back to the Domain Settings tab.
- Scroll down to the Delete domain section, and choose the Delete domain
Delete the Amazon GameLift Testing Toolkit
Delete the S3 buckets
- Navigate to the S3 console and empty all S3 buckets with a name beginning with AGTT- by selecting the radio button for the bucket, then choosing Empty.
- For each bucket you emptied, select the radio button again and choose Delete.
There are two options for deleting the Amazon GameLift Testing Toolkit:
- Using deployment script
- You can remove the toolkit using the deployment script by opening a terminal window, navigate to the toolkit’s root directory, and then run the following command (remember to enter in the profile name you created):
cd ~/amazon-gamelift-testing-toolkit
yarn delete-toolkit [--profile <profileName>]
- Using the AWS Management Console
- Navigate to the AWS CloudFormation console.
- Select Stacks.
- Select the AGTT-ManagementConsoleStack-WebStack stack, choose Delete, and wait until complete.
- Select the AGTT-ManagementConsoleStack-BackendStack stack, choose Delete, and wait until complete.
- Select the AGTT-ManagementConsoleStack-SecurityStack stack, choose Delete, and wait until complete.
- Select the AGTT-ManagementConsoleStack-DataStack stack and choose Delete.
Conclusion
In this final blog of our two-part series, we demonstrated how to use Amazon GameLift Servers FlexMatch to match players based on the skill value produced by the ML model created from the first blog. We also highlighted how to simulate matchmaking using the Amazon GameLift Testing Toolkit in order to test both the model and your matchmaking parameters—without deploying full blown servers to your production workload.
You now know how to create a machine learning-powered matchmaking system that considers multiple skill factors to create more balanced, competitive, and engaging matches. By leveraging Amazon SageMaker AI, with Amazon GameLift Servers FlexMatch, you accomplished this without needing to perform extensive data science operations or having to develop and modify complex machine learning algorithms. As you gather more data and user feedback, you can continue to improve your matchmaking system, making it even more accurate and valuable for your users.
Contact an AWS Representative to know how we can help accelerate your business.
Further reading
Author: Christina Defoor