public void Load(string path) { var players = LoadFromFile(path); var formations = Exhaust.GetFormations(players); formations.ForEach(formation => { if (Filter(formation)) { Formations.Add(formation); } }); }
public static List <Formation> GetFormations(List <Player> players) { Exhaust exhaust = new Exhaust(); //players.ForEach(player => //{ // var temp = new List<Player>(players); // temp.Remove(player); // temp.Insert(0, player); // LinkedList<Player> playerLinkedList = new LinkedList<Player>(temp); // Traverse(playerLinkedList.First, new List<Place>(), exhaust); //}); LinkedList <Player> playerLinkedList = new LinkedList <Player>(players); Traverse(playerLinkedList.First, new List <Place>(), exhaust); return(exhaust.Formations); }
private static void Traverse(LinkedListNode <Player> linkedListNode, List <Place> formation, Exhaust exhaust) { var player = linkedListNode.Value; player.Places.ForEach(place => { formation.Add(place); if (linkedListNode.Next == null) { if (Filter(formation)) { exhaust.AddFormation(formation); } } else { Traverse(linkedListNode.Next, formation, exhaust); } formation.Remove(place); }); }