Exercise: Esports Matchmaking Lobby

Filter, sort, and project a list of online gamers to build an active 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 GamerTag property 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 resulting Player objects 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 Where requires 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 a foreach loop.

Exercise: Esports Matchmaking Lobby

Filter, sort, and project a list of online gamers to build an active 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 GamerTag property 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 resulting Player objects 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 Where requires 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 a foreach loop.

C# 14.0
using Matchmaking;
// 1. Attaining the data source
var connectedPlayers = new List<Player>
{
new Player { GamerTag = "ShadowSniper", MMR = 2100, Status = "Available" },
new Player { GamerTag = "LaserBeam", MMR = 2450, Status = "In Game" },
new Player { GamerTag = "NoobSlayer99", MMR = 1500, Status = "Available" },
new Player { GamerTag = "ProGamerXYZ", MMR = 2800, Status = "Offline" },
new Player { GamerTag = "TheWall", MMR = 2300, Status = "Available" }
};
// 2. Create your LINQ query here
// var availableGamerTags = ...
// 3. Execute the query and print the results
Console.WriteLine("Players looking for a match:");
// foreach(...) { ... }