示例#1
0
        public void Compute(List <Line> data, int fieldSize)
        {
            int totalcount = data.Count;

            int limit = GetiRatingLimit();

            // count the cars registrated with an irating upper than the limit
            int moreThanLimitCars   = (from r in data where r.rating > limit select r).Count();
            int moreThanLimitSplits = Convert.ToInt32(
                Math.Floor(
                    Convert.ToDouble(moreThanLimitCars) / Convert.ToDouble(fieldSize)
                    )
                );

            // and round it to be a multiple of field size
            moreThanLimitCars = moreThanLimitSplits * fieldSize;


            // create two lists : moreThanLimit and lessThanLimit
            var moreThanLimit = (from r in data orderby r.rating descending select r).Take(moreThanLimitCars).ToList();

            var lessThanLimit = new List <Line>();

            foreach (var line in data)
            {
                if (!moreThanLimit.Contains(line))
                {
                    lessThanLimit.Add(line);
                }
            }


            // compute both list separatly

            // more than limit split calculation
            c = GetGroupMatchMaker();
            BetterMatchMaking.Library.BetterMatchMakingCalculator.CopyParameters(this, c);
            c.Compute(moreThanLimit, fieldSize);
            Splits = c.Splits;

            // less than limit split calculation
            double approxSplitsCount = Convert.ToDouble(lessThanLimit.Count) / fieldSize;
            double newFieldSize      = Convert.ToDouble(lessThanLimit.Count) / Math.Ceiling(approxSplitsCount);

            fieldSize = Convert.ToInt32(Math.Ceiling(newFieldSize));

            c = GetGroupMatchMaker();
            BetterMatchMaking.Library.BetterMatchMakingCalculator.CopyParameters(this, c);
            c.Compute(lessThanLimit, fieldSize);
            Splits.AddRange(c.Splits); // merge the two lists

            // re count splits
            int counter = 1;

            foreach (var s in Splits)
            {
                s.Number = counter;
                counter++;
            }
        }
示例#2
0
        // -->



        public void Compute(List <Line> data, int fieldSize)
        {
            this.data = data;

            // Split cars per class, and enum class Ids
            carclasses    = Tools.SplitCarsPerClass(data);
            carClassesIds = (from r in carclasses select r.CarClassId).ToList();

            // initialize the base algorithm
            baseAlgorithm = GetBaseAlgorithm();
            BetterMatchMakingCalculator.CopyParameters(this, baseAlgorithm as IMatchMaking);

            // Compute with be base Algorithm and get results
            (baseAlgorithm as IMatchMaking).Compute(data, fieldSize);
            Splits = (baseAlgorithm as IMatchMaking).Splits;

            // Before the move down process, the the true field size targetted
            this.fieldSize = Convert.ToInt32(Math.Ceiling((from r in Splits select r.TotalCarsCount).Average()));

            // at this point, results it the same than the base algorithm


            // now, enter to the Smart Move Down process
            SmartMoveDownProcess();
        }
示例#3
0
        public GameController()
        {
            ServicePartitionKey servicePartitionKey = new ServicePartitionKey(0);

            matchMaking = ServiceProxy.Create <IMatchMaking>(new Uri("fabric:/TicTacToe/MatchMaking"), servicePartitionKey);
        }
        public void Compute(List <Line> data, int fieldSize)
        {
            int totalcount = data.Count;

            int limit = GetiRatingLimit();

            // count the cars registrated with an irating upper than the limit
            int moreThanLimitCars   = (from r in data where r.rating > limit select r).Count();
            int moreThanLimitSplits = Convert.ToInt32(
                Math.Floor(
                    Convert.ToDouble(moreThanLimitCars) / Convert.ToDouble(fieldSize)
                    )
                );

            // and round it to be a multiple of field size
            moreThanLimitCars = moreThanLimitSplits * fieldSize;


            // create two lists : moreThanLimit and lessThanLimit
            var moreThanLimit2 = (from r in data orderby r.rating descending select r).Take(moreThanLimitCars).ToList();

            var lessThanLimit = new List <Line>();

            foreach (var line in data)
            {
                if (!moreThanLimit2.Contains(line))
                {
                    lessThanLimit.Add(line);
                }
            }


            // now we when to cut the moreThanLimit2 in 2 parts, by the middle
            int middlevalue = moreThanLimit2[moreThanLimit2.Count / 2].rating;

            moreThanLimitCars   = (from r in data where r.rating >= middlevalue select r).Count();
            moreThanLimitSplits = Convert.ToInt32(
                Math.Floor(
                    Convert.ToDouble(moreThanLimitCars) / Convert.ToDouble(fieldSize)
                    )
                );
            moreThanLimitCars = moreThanLimitSplits * fieldSize;
            var moreThanLimit1 = (from r in data orderby r.rating descending select r).Take(moreThanLimitCars).ToList();


            moreThanLimit2.Clear();
            foreach (var line in data)
            {
                if (!moreThanLimit1.Contains(line) && !lessThanLimit.Contains(line))
                {
                    moreThanLimit2.Add(line);
                }
            }


            // compute both list separatly
            int originalFieldSize = fieldSize;

            // more than limit 1 split calculation
            c = GetGroupMatchMaker();
            c.Compute(moreThanLimit1, fieldSize);
            Splits = c.Splits;

            // less than limit 2 split calculation
            double approxSplitsCount = Convert.ToDouble(moreThanLimit2.Count) / originalFieldSize;
            double newFieldSize      = Convert.ToDouble(moreThanLimit2.Count) / Math.Ceiling(approxSplitsCount);

            fieldSize = Convert.ToInt32(Math.Ceiling(newFieldSize));

            c = GetGroupMatchMaker();
            c.Compute(moreThanLimit2, fieldSize);
            Splits.AddRange(c.Splits); // merge the two lists

            // less than limit split calculation
            approxSplitsCount = Convert.ToDouble(lessThanLimit.Count) / originalFieldSize;
            newFieldSize      = Convert.ToDouble(lessThanLimit.Count) / Math.Ceiling(approxSplitsCount);
            fieldSize         = Convert.ToInt32(Math.Ceiling(newFieldSize));

            c = GetGroupMatchMaker();
            c.Compute(lessThanLimit, fieldSize);
            Splits.AddRange(c.Splits); // merge the two lists

            // re count splits
            int counter = 1;

            foreach (var s in Splits)
            {
                s.Number = counter;
                counter++;
            }
        }