コード例 #1
0
        private void Merge(LinkedPair closestPair)
        {
            var first  = closestPair.GetFirst();
            var second = closestPair.GetSecond();

            for (var other = 0; other < _numItems; other++)
            {
                _matrix[Math.Min(first, other)][Math.Max(first, other)] = Link(GetDistance(first, other), GetDistance(second, other));
            }
        }
コード例 #2
0
    public override void Start()
    {
        base.Start();
        partnerRenderer = partner.GetComponent <Renderer>();
        partnerMaterial = partnerRenderer.material;
        _propBlock      = new MaterialPropertyBlock();

        partnerLinkedPair      = partner.GetComponent <LinkedPair>();
        previewRenderer        = transform.Find("Activated Renderer").GetComponent <Renderer>();
        partnerPreviewRenderer = partner.transform.Find("Activated Renderer").GetComponent <Renderer>();
    }
コード例 #3
0
        private LinkedPair GetClosestPair()
        {
            LinkedPair closestPair = null;

            if (_isScoreMatrix)
            {
                var max = 0.0;

                foreach (var i in _indicesToCheck)
                {
                    foreach (var j in _indicesToCheck)
                    {
                        if (j <= i)
                        {
                            continue;
                        }

                        if (!(_matrix[i][j] >= max))
                        {
                            continue;
                        }
                        max         = _matrix[i][j];
                        closestPair = new LinkedPair(i, j, max);
                    }
                }
            }
            else
            {
                var min = double.MaxValue;

                foreach (var i in _indicesToCheck)
                {
                    foreach (var j in _indicesToCheck)
                    {
                        if (j <= i)
                        {
                            continue;
                        }

                        if (!(_matrix[i][j] <= min))
                        {
                            continue;
                        }
                        min         = _matrix[i][j];
                        closestPair = new LinkedPair(i, j, min);
                    }
                }
            }

            return(closestPair);
        }
コード例 #4
0
    // Add a line, this function is also the key logic of linked
    private void TryLinkStar(GameObject goBegin, GameObject goEnd)
    {
        if (goBegin == null || goEnd == null)
        {
            return;
        }
        int indexB = goBegin.GetComponent <Star>().index;
        int indexE = goEnd.GetComponent <Star>().index;

        //Check whether already linke
        int index = this.GetLinkedLine(indexB, indexE);

        if (index >= 0)
        {
            //Already linked, try to delete it
            GameObject goLine = _linkedLineList[index].line;
            //delte from list
            _linkedLineList.RemoveAt(index);
            //modify hash table
            if (IsStarLinked(indexB))
            {
                _starDictionary[indexB]--;
            }
            if (IsStarLinked(indexE))
            {
                _starDictionary[indexE]--;
            }
            //delete the line
            Destroy(goLine);
            //remove two star from anwser
            RemoveAnswerFromList(indexB, indexE);
        }
        else
        {
            // Try to link two stars
            Transform beginTransform = goBegin.transform;
            Transform endTransform   = goEnd.transform;
            // Instantiate line
            GameObject linkedLine = levelPlayView.AddLine(beginTransform, endTransform);
            // Add record to List
            LinkedPair lp = new LinkedPair(indexB, indexE, linkedLine);
            _linkedLineList.Add(lp);
            // Add record to Hash
            if (_starDictionary.ContainsKey(indexB))
            {
                _starDictionary[indexB]++;
            }
            else
            {
                _starDictionary[indexB] = 1;
            }
            if (_starDictionary.ContainsKey(indexE))
            {
                _starDictionary[indexE]++;
            }
            else
            {
                _starDictionary[indexE] = 1;
            }
            //Add two star to answerList
            this.AddAnswerToList(indexB, indexE);
        }

        // Reset ready starts
        _readyStar = null;
        // Refresh the stars state
        this.RefreshStar(goBegin);
        this.RefreshStar(goEnd);
        levelPlayView.RefreshLabelNum();
    }