2支球队拥有相同的球员和权力

时间:2017-01-06 08:53:44

标签: c# sql algorithm model-view-controller

我有Sql数据库,其中有10个玩家,每个玩家的力量从1到10.这些是我的玩家和团队类

public partial class Team
{
    public int TeamId { get; set; }
    public string TeamName { get; set; }
    public Nullable<int> TeamPlayers { get; set; }
    public Nullable<int> TeamPower { get; set; }
}

public partial class Player
{
    public int PlayerId { get; set; }        
    public Nullable<int> PlayerPower { get; set; }
}

现在我要创建2个团队。在每支球队应该是5名球员。从SQL数据库中随机选择玩家,每个团队应该保持平衡。如何从SQL中选择玩家并以均衡的力量创建2个团队。 先谢谢

1 个答案:

答案 0 :(得分:1)

将玩家列表添加到2个小组:

public partial class Team
{
    public int TeamId { get; set; }
    public string TeamName { get; set; }
    public List<Player> TeamPlayers { get; set; }  //<-- have "team players"
    //public Nullable<int> TeamPower { get; set; } //Dont need this if teams are supposed to have equal powers.
}

public partial class Player
{
    public int PlayerId { get; set; }        
    public Nullable<int> PlayerPower { get; set; }
}

要随机选择玩家并平衡权力,你可以在SQL中这样做,如果这就是你填充2队的方式。这将是一个统计权力的案例,并继续将球员交换到不同的球队,直到每支球队的力量相同。我会把这作为练习留给你,用它作为灵感:Algorithm - Attempting to balance out team skill levels, while having a equal amount of players