I am on a mission to create a football squad consisting of 11 players. Each of these players is directly linked to some others, forming what can be visualized as a "neural network architecture with 11 nodes".
Picture this scenario: I have a dedicated list for each position (node area) on the field - GoalKeeper_List, LeftBack_List, CenterMid_List, and so forth.
Within each list, there are 15 potential players. This means that a particular node area can only be filled by the corresponding 15 players.
The fundamental rule in place states that when a node's neighboring positions are occupied (i.e., its neighbors are no longer empty), a function is triggered. This function evaluates how well the node performs alongside its neighbors and returns either "OK" or "Not-OK".
If the function deems the performance "Not-OK", it signals that the entire squad configuration cannot work, regardless of other node statuses.
It is essential to note that the function runs independently for each node, based on the parameters of its neighboring positions, but it can only execute when all of a node's adjacent spots are occupied.
My objective is to have my program generate all possible squads using the pool of 11x15 players (from 11 separate lists). Without any restrictions, there would be a staggering 15^11 possible combinations – equivalent to approximately 8.6 trillion squads, rendering computations nearly impossible. However, applying the rules significantly trims down the available options. Consequently, when the code executes, it typically yields results ranging from 1 to 30000, which the computer can handle effectively. I have conducted several trials to arrive at these figures. Nevertheless, my current implementation suffers from sluggish performance due to the nested loops within the code structure, often leading to variable computation times — sometimes resolving in 40 seconds, other times extending to 10 minutes, or occasionally failing to produce results altogether despite viable squad configurations.
I am convinced that there exists a more efficient approach to enhance the speed of this code execution, thereby necessitating a fresh strategy to tackle this challenge.
Below is the code snippet giving insight into the ongoing process:
let working_squads = []
let current_full_squad = []
for (gk of GK_List){
for(cb1 of CB1_List){
current_full_squad = [gk]
for(cb2 of CB2_List){
current_full_squad = [gk, cb1]
let GK_status = get_player_status(gk, [cb1, cb2])
if(GK_status === "Not-OK") continue
// Nested loop continues...
}
}
}
console.log(working_squads.length.toString() + " squads found! Here they are... ")