I have a module object that contains a list of roles. These roles can represent one or more roles (Es: "RoleA", or maybe "RoleA;RoleB")
// Example
var roles = [
'Por',
'Ds',
'Dc',
'Dc',
'Dd',
'M',
'M;C',
'T',
'W',
'W;A',
'A;Pc'
]
I have another array. It's a list of players object. Each player has a 'role' and a 'value'. The role again can be single or multiple.
// Example
var players = [
{
name: 'NameA',
role : 'A',
value: 15
},
{
name: 'NameB',
role : 'A;W',
value: 15
},
{
name: 'NameC',
role : 'Dd;Dc',
value: 15
},
...
]
My goal is to assign a player to each role of the 'roles' array maximizing the total value of the team (calculated by summing the value of the single players)
I've done it iterating over roles array trying to find each time the best option. It had some issues I fixed by adding some simple mechanisms but in some cases, i still have some problems.
Can anyone with some algorithm understanding explain what is the best way to face these kinds of problems?
// Example
var roles = [
['Por', playerA],
['Ds', playerB],
['Dc', playerC],
['Dc', playerD],
['Dd', playerE],
['M', playerF],
['M;C', playerG],
['T', playerH],
['W', playerI],
['W;A', playerL],
['A;Pc, playerM]
]