コード例 #1
0
        public void CoalitionMaxTest()
        {
            Coalition     c  = new Coalition(5);
            ValueFunction vf = new ValueFunction("");

            int[]  materials = new int[5];
            double max = 0, res = 0;

            materials[0] = 1;
            materials[1] = 5;
            materials[2] = 3;
            materials[3] = 8;
            materials[4] = 4;
            Player p1 = new Player(vf, materials);

            c.addPlayer(p1);
            p1.Materials = materials;

            foreach (var i in materials)
            {
                if (i > max)
                {
                    max = i;
                }

                if (i > c.getMaximumValue())
                {
                    res = i;
                }
            }

            Assert.AreEqual(max, res);
        }
コード例 #2
0
        public void CoalitionMaxTest()
        {
            Coalition     c  = new Coalition(5);
            ValueFunction vf = new ValueFunction();

            int[] materials = new int[5];
            int   max       = 0;

            materials[0] = 1;
            materials[1] = 5;
            materials[2] = 3;
            materials[3] = 8;
            materials[4] = 4;

            /*int[] materials2 = new int[3];
             * materials[0] = 1;
             * materials[1] = 3;
             * materials[2] = 5; */
            /*int[] materials3 = new int[4];
             * materials[0] = 10;
             * materials[1] = 9;
             * materials[2] = 3;
             * materials[3] = 4;*/
            Dynamic_Games.coop.models.Player p1 = new Dynamic_Games.coop.models.Player(vf, materials);
            //Dynamic_Games.coop.models.Player p2 = new Dynamic_Games.coop.models.Player();
            //Dynamic_Games.coop.models.Player p3 = new Dynamic_Games.coop.models.Player();
            c.addPlayer(p1);
            //c.addPlayer(p2);
            //c.addPlayer(p3);
            p1.Materials = materials;
            //p2.Materials = materials2;
            //p3.Materials = materials3;

            for (int i = 0; i < materials.Length; i++)
            {
                if (materials[i] > max)
                {
                    max = materials[i];
                }
            }
            int res = c.calculateMaximumValue();

            Assert.AreEqual(max, res);
        }
コード例 #3
0
        //calculate l, combinations of Coalitions
        private List <Coalition>[] getCombinations(int n, Player[] players, int m)
        {
            var result = new List <Coalition> [n];
            var stack  = new int[n];

            for (int i = 1; i <= n; i++)
            {
                stack[0]      = -1;
                result[i - 1] = new List <Coalition>();
                int l = 0;
                while (l >= 0)
                {
                    stack[l]++;
                    if (stack[l] >= n)
                    {
                        l--;
                    }
                    else
                    {
                        if (l == i - 1)
                        {
                            Coalition coalition = new Coalition(m);
                            for (var j = 0; j < i; j++)
                            {
                                coalition.addPlayer(players[stack[j]]);
                            }
                            result[i - 1].Add(coalition);
                        }
                        else
                        {
                            l++;
                            stack[l] = stack[l - 1];
                        }
                    }
                }
            }
            return(result);
        }