我有一份玩家名單,每名玩家都有一份技能等級列表。 我想要做的是根據與特定搜索列表匹配的評分排序這些玩家。比較整數列表,然後根據相似性排序它們。
下面是四個球員的榜樣:
List<Skill> skillsA = new List<Skill>();
List<Skill> skillsB = new List<Skill>();
List<Skill> skillsC = new List<Skill>();
List<Skill> skillsD = new List<Skill>();
skillsA.Add(new Skill() { Name = "Speed", Value = 1 });
skillsA.Add(new Skill() { Name = "Agility", Value = 5 });
skillsA.Add(new Skill() { Name = "Strength", Value = 3 });
skillsA.Add(new Skill() { Name = "Endurance", Value = 4 });
skillsB.Add(new Skill() { Name = "Speed", Value = 5 });
skillsB.Add(new Skill() { Name = "Agility", Value = 2 });
skillsB.Add(new Skill() { Name = "Strength", Value = 1 });
skillsB.Add(new Skill() { Name = "Endurance", Value = 3 });
skillsC.Add(new Skill() { Name = "Speed", Value = 5 });
skillsC.Add(new Skill() { Name = "Agility", Value = 3 });
skillsC.Add(new Skill() { Name = "Strength", Value = 2 });
skillsC.Add(new Skill() { Name = "Endurance", Value = 2 });
skillsD.Add(new Skill() { Name = "Speed", Value = 1 });
skillsD.Add(new Skill() { Name = "Agility", Value = 2 });
skillsD.Add(new Skill() { Name = "Strength", Value = 5 });
skillsD.Add(new Skill() { Name = "Endurance", Value = 4 });
Player A = new Player() { Skills = skillsA };
Player B = new Player() { Skills = skillsB };
Player C = new Player() { Skills = skillsC };
Player D = new Player() { Skills = skillsD };
這將是搜索列表我比較:
List<Skill> matchSkill = new List<Skill>();
matchSkill.Add(new Skill() { Name = "Speed", Value = 5 });
matchSkill.Add(new Skill() { Name = "Agility", Value = 2 });
matchSkill.Add(new Skill() { Name = "Strength", Value = 1 });
matchSkill.Add(new Skill() { Name = "Endurance", Value = 1 });
SkillSearch SkillSearch = new SkillSearch() { Skills = matchSkill };
我應該回來的球員名單下令PlayerB,PlayerC,PlayerD ,玩家A
技能列表將始終是相同的大小和順序。技能總是在1-5之間。我試圖用絕對值來比較這些值之間的差異。例如,如果搜索是針對(3)2和4會比1或5
總之更接近的匹配,如果你只是看它們作爲數字數組的你將有:
search = { 5, 2, 1, 1}
playerb = { 5, 2, 1, 3} : difference {0,0,0,2} (2 total)
playerc = { 5, 3, 2, 2} : difference {0,1,1,1} (3 total)
playerd = { 1, 2, 5, 4} : difference {4,0,4,3} (11 total)
playera = { 1, 5, 3, 4} : difference {4,3,2,3} (12 total)
我將如何使用C#訂購這些產品?我更喜歡linq結果。我只是不確定如何得到這些訂單。
對不起,由於某種原因,我忘了添加問題... – 2012-02-03 17:28:27
似乎你已選擇曼哈頓距離作爲你的距離測量。那麼,問題是什麼?您需要計算兩組技能之間絕對差異的總和,並按最低距離對其進行排名。 – Andreas 2012-02-03 18:29:34