private Coalition[] searchList(int[] g, Double maxOfg)
        {
            Double vck   = 0;
            Double vcs   = ValueOfCoalitionStructure(cs);
            var    k     = 0;
            var    stack = new StackStructForSearchList(g.Length); //stack for searching
            var    ck    = new List <Coalition>();                 //list of current coalitions

            stack.players[0] = (Player[])players.Clone();
            stack.m[k]       = -1; //coalition's index

            stack.alpha[0] = 1;
            stack.mSet[k]  = getMSet(g, k, g[k] - 1, stack.players[k], stack.alpha[k]); //set of coalitions at first level

            while (k >= 0 && !stop)
            {
                stack.m[k]++;
                if (stack.m[k] < stack.mSet[k].Count) //if it's a valid coalition index
                {
                    if (stack.m[k] > 0)
                    {
                        vck -= ((Coalition)ck[ck.Count - 1]).getMaximumValue();
                        ck.RemoveAt(ck.Count - 1); //remove previous Coalition
                    }
                    var currentCoalition = stack.mSet[k][stack.m[k]];
                    ck.Add(currentCoalition);
                    vck += currentCoalition.getMaximumValue();
                    if (k == g.Length - 1 && vck > vcs) // new best coalition structure
                    {
                        cs = ck.ToArray();
                        addtoFoundStructures();
                        vcs = vck;
                    }
                    else if (vcs < getMaximumValueOfBuildableCoalitionStructure(vck, g, k + 1))            //can the current CS better than the best so far
                    {
                        var newLengthOfPlayers = stack.players[k].Length - currentCoalition.Players.Count; // calculate number of rest players
                        stack.players[k + 1] = new Player[newLengthOfPlayers];
                        var j = 0;
                        for (var i = 0; i < stack.players[k].Length; i++)
                        {
                            if (!currentCoalition.Players.Contains(stack.players[k][i]))
                            {
                                stack.players[k + 1][j] = stack.players[k][i]; // players whos arent used yet
                                j++;
                            }
                        }
                        k++;
                        stack.m[k] = -1;
                        var index = 0;
                        if (k > 0 && g[k - 1] != g[k])
                        {
                            stack.alpha[k] = 1;
                        }
                        else
                        {
                            for (var i = 0; i < players.Length; i++)
                            {
                                if (players[i] == currentCoalition.Players[0])
                                {
                                    index = i;
                                }
                            }
                            stack.alpha[k] = index + 1;
                        } // calculate next level lower bound
                        stack.mSet[k] = getMSet(g, k, g[k] - 1, stack.players[k], stack.alpha[k]);
                        //calculate new coalitions to add current coalition structure at kth level
                    }
                }
                else
                {
                    if (stack.m[k] > 0)
                    {
                        vck -= ((Coalition)ck[ck.Count - 1]).getMaximumValue();
                        ck.RemoveAt(ck.Count - 1); // remove previous coalition
                    }
                    k--;
                }
                if (vcs == maxOfg) //if the cs is the best at this claster
                {
                    return(cs);
                }
            }
            return(cs);
        }
        private Coalition[] searchList(int[] g, Double maxOfg)
        {
            Double vck = 0;
            Double vcs = ValueOfCoalitionStructure(cs);
            var k = 0;
            var stack = new StackStructForSearchList(g.Length); //stack for searching
            var ck = new List<Coalition>(); //list of current coalitions
            stack.players[0] = (Player[])players.Clone();
            stack.m[k] = -1; //coalition's index

            stack.alpha[0] = 1;
            stack.mSet[k] = getMSet(g, k, g[k] - 1, stack.players[k], stack.alpha[k]); //set of coalitions at first level

            while (k >= 0 && !stop)
            {
                stack.m[k]++;
                if (stack.m[k] < stack.mSet[k].Count) //if it's a valid coalition index
                {
                    if (stack.m[k] > 0)
                    {
                        vck -= ((Coalition)ck[ck.Count - 1]).getMaximumValue();
                        ck.RemoveAt(ck.Count - 1); //remove previous Coalition
                    }
                    var currentCoalition = stack.mSet[k][stack.m[k]];
                    ck.Add(currentCoalition);
                    vck += currentCoalition.getMaximumValue();
                    if (k == g.Length - 1 && vck > vcs) // new best coalition structure
                    {
                        cs = ck.ToArray();
                        addtoFoundStructures();
                        vcs = vck;
                    }
                    else if (vcs < getMaximumValueOfBuildableCoalitionStructure(vck, g, k + 1)) //can the current CS better than the best so far
                    {
                        var newLengthOfPlayers = stack.players[k].Length - currentCoalition.Players.Count; // calculate number of rest players
                        stack.players[k + 1] = new Player[newLengthOfPlayers];
                        var j = 0;
                        for (var i = 0; i < stack.players[k].Length; i++)
                        {
                            if (!currentCoalition.Players.Contains(stack.players[k][i]))
                            {
                                stack.players[k + 1][j] = stack.players[k][i]; // players whos arent used yet
                                j++;
                            }
                        }
                        k++;
                        stack.m[k] = -1;
                        var index = 0;
                        if (k > 0 && g[k - 1] != g[k])
                        {
                            stack.alpha[k] = 1;
                        }
                        else
                        {
                            for (var i = 0; i < players.Length; i++)
                            {
                                if (players[i] == currentCoalition.Players[0])
                                    index = i;
                            }
                            stack.alpha[k] = index + 1;
                        } // calculate next level lower bound
                        stack.mSet[k] = getMSet(g, k, g[k] - 1, stack.players[k], stack.alpha[k]);
                        //calculate new coalitions to add current coalition structure at kth level
                    }
                }
                else
                {
                    if (stack.m[k] > 0)
                    {
                        vck -= ((Coalition)ck[ck.Count - 1]).getMaximumValue();
                        ck.RemoveAt(ck.Count - 1); // remove previous coalition
                    }
                    k--;
                }
                if (vcs == maxOfg) //if the cs is the best at this claster
                {
                    return cs;
                }
            }
            return cs;
        }