Beispiel #1
0
 /// <summary>
 /// 添加一个搜索分段
 /// </summary>
 private void ExtendSearchGrading(Grading grading)
 {
     this._searchSpace.Add(grading);
     this._expireTime = grading.expireTime;
     this._time       = 0;
     ++this._level;
 }
Beispiel #2
0
        public MatchUser CreateUser(ulong id, int rank)
        {
            Grading grading = this.SelectGrading(rank);

            if (grading == null)
            {
                return(null);
            }
            MatchUser user = new MatchUser(id, rank);

            grading.AddUser(user);
            return(user);
        }
Beispiel #3
0
 public void InitFromDefs(Hashtable json)
 {
     this.mode = json.GetByte("mode");
     Hashtable[] gradingDefs = json.GetMapArray("gradings");
     //是否每个分段定义
     if (gradingDefs != null)
     {
         int count = gradingDefs.Length;
         for (int i = 0; i < count; i++)
         {
             Hashtable gradingDef  = gradingDefs[i];
             int       @from       = gradingDef.GetInt("from");
             int       to          = gradingDef.GetInt("to");
             int       expire      = gradingDef.GetInt("extend_interval");
             int       searchRange = gradingDef.GetInt("max_extend_count");
             Grading   grading     = new Grading(this, @from, to, expire, searchRange);
             if (i > 0)
             {
                 grading.prev      = this._gradings[i - 1];
                 grading.prev.next = grading;
             }
             this._gradings.Add(grading);
         }
     }
     else
     {
         int gradingStep  = json.GetInt("extend_range");
         int gradingCount = json.GetInt("grading_count");
         int searchRange  = json.GetInt("max_extend_count");
         int expire       = json.GetInt("extend_interval");
         for (int i = 0, k = 0; i < gradingCount; i++)
         {
             int @from = k;
             k += gradingStep;
             int     to      = k - 1;
             Grading grading = new Grading(this, @from, to, expire, searchRange);
             if (i > 0)
             {
                 grading.prev      = this._gradings[i - 1];
                 grading.prev.next = grading;
             }
             this._gradings.Add(grading);
         }
     }
 }
Beispiel #4
0
        internal bool ProcessMatch(long dt)
        {
            int c1 = this._searchSpace.Count;

            if (c1 == 0)
            {
                return(false);
            }

            Grading grading = null;

            for (int i = 0; i < c1; i++)
            {
                //搜索第i层
                grading = this._searchSpace[i];
                int numUsers = grading.system.numUsers;
                int c2       = grading.users.Count;
                for (int j = 0; j < c2; j++)
                {
                    MatchUser user = grading.users[j];
                    //添加到等候室
                    if (this._matchingLounge.AddUser(user))
                    {
                        //添加事件
                        this._owner.system.RaiseEvent(MatchUserEvent.Type.AddToLounge, user, user.lounge.GetState());

                        if (this._matchingLounge.numUsers == numUsers)
                        {
                            //匹配成功
                            MatchState state = this._matchingLounge.GetState();
                            this._owner.system.RaiseEvent(MatchUserEvent.Type.MatchSuccess, null, state);
                            this.Clear();
                            return(true);
                        }
                    }
                }
            }

            //超过搜索时间,扩大搜索空间
            if (this._time >= this._expireTime && this._searchSpace.Count <= grading.maxExtends)
            {
                grading = this._searchSpace[0];
                Grading prev = null, next = null;
                //找到需要扩展的分段
                for (int i = 0; i < this._level; i++)
                {
                    prev = grading.prev;
                    if (prev == null)
                    {
                        break;
                    }
                }
                for (int i = 0; i < this._level; i++)
                {
                    next = grading.next;
                    if (next == null)
                    {
                        break;
                    }
                }
                if (prev != null && next != null)
                {
                    //随机顺序加入到搜索空间
                    double rnd = this._rnd.NextDouble();
                    if (rnd < 0.5)
                    {
                        this.ExtendSearchGrading(prev);
                        this.ExtendSearchGrading(next);
                    }
                    else
                    {
                        this.ExtendSearchGrading(next);
                        this.ExtendSearchGrading(prev);
                    }
                }
                else if (prev != null || next != null)
                {
                    this.ExtendSearchGrading(prev ?? next);
                }
            }
            this._time += dt;
            return(false);
        }
Beispiel #5
0
 public Matcher(Grading owner)
 {
     this._owner          = owner;
     this._matchingLounge = new MatchingLounge(this._owner.system.numTeam, this._owner.system.numUserPerTeam);
     this.ExtendSearchGrading(owner);
 }