I am writing a domino draw game in C# and would like to know if there is a simpler/better way to know the player that has been dealt the highest double bone (where x equals y) and what bone it is:
public class Player
{
public string Name { get; set; }
public List<Bone> Bones;
public Player(string name)
{
Name = name;
}
}
public class Bone
{
public int x { get; set; }
public int y { get; set; }
}
Code in question (players is a list of player):
//select player with highest double and select the double
var pdb = players.SelectMany(pl => pl.Bones.Where(b => b.x == b.y)
.Select(b => new { player = pl, doublebones = b }))
.OrderByDescending(db => db.doublebones.x)
.First();
Player playerWithHighestDouble = pdb.player;
Bone highestBone = pdb.doublebones;