Exercise: Esports Matchmaking Lobby
Problem statement
You are building the matchmaking server for a new competitive online game. You receive a batch of player telemetry data indicating who is currently connected to the server. You need to find all available players, rank them by their skill level to ensure fair matches, and extract their gamer tags to display on the active "Looking for Match" screen.
Task requirements
Filter the provided list of players to include only those whose status is exactly “Available”.
Sort the available players by their Matchmaking Rating (MMR) from highest to lowest.
Extract only the
GamerTagproperty from the sorted players.Iterate through the final sequence and print each gamer tag to the console.
Constraints
You must use the
Where()method to filter the sequence based on the player’s status.You must use the
OrderByDescending()method to sort the players by their MMR.You must use the
Select()method to project the resultingPlayerobjects into a sequence of strings.You must chain the LINQ methods together in a single query expression.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Remember that
Whererequires a lambda expression that evaluates to a boolean (e.g.,p => p.Status == ...).Method chaining works sequentially: filter the data first, sort the remaining data second, and project the final data last.
Your final LINQ query will return an
IEnumerable<string>, which you can iterate over directly using aforeachloop.
Exercise: Esports Matchmaking Lobby
Problem statement
You are building the matchmaking server for a new competitive online game. You receive a batch of player telemetry data indicating who is currently connected to the server. You need to find all available players, rank them by their skill level to ensure fair matches, and extract their gamer tags to display on the active "Looking for Match" screen.
Task requirements
Filter the provided list of players to include only those whose status is exactly “Available”.
Sort the available players by their Matchmaking Rating (MMR) from highest to lowest.
Extract only the
GamerTagproperty from the sorted players.Iterate through the final sequence and print each gamer tag to the console.
Constraints
You must use the
Where()method to filter the sequence based on the player’s status.You must use the
OrderByDescending()method to sort the players by their MMR.You must use the
Select()method to project the resultingPlayerobjects into a sequence of strings.You must chain the LINQ methods together in a single query expression.
Good luck trying the exercise! If you’re unsure how to proceed, check the “Solution” tab above.
Get hints
Remember that
Whererequires a lambda expression that evaluates to a boolean (e.g.,p => p.Status == ...).Method chaining works sequentially: filter the data first, sort the remaining data second, and project the final data last.
Your final LINQ query will return an
IEnumerable<string>, which you can iterate over directly using aforeachloop.