Beispiel #1
0
        /// <summary>
        /// Returns the list of the unbound vectors.
        /// Unbound means, at least 1 non-empty grid point should be at the upper directions.
        /// X X B   X X X   B B X
        ///   O       O       O
        /// Bound  UnBound  Bound
        /// </summary>
        /// <returns></returns>
        public List <ushort> RemoveUnBounds()
        {
            OutputLog.AddLog("Remove unbounds...");

            List <ushort> unbounds = new List <ushort>();

            int sizeX = Size.X;
            int sizeY = Size.Y;

            for (int y = 0; y < sizeY; y++)
            {
                for (int x = 0; x < sizeX; x++)
                {
                    Vector position = new Vector(x, y);

                    var point = GetFromPosition(position);
                    if (point != null)
                    {
                        bool found = false;

                        // check for point.
                        for (int i = 0; i < 3; i++)
                        {
                            var cPosition = position + seekDirections[DirectionCount - i - 1];

                            if (cPosition.Y < 0 || GetFromPosition(cPosition) != null)
                            {
                                found = true;
                                break;
                            }
                        }

                        if (!found)
                        {
                            // gone.
                            unbounds.Add(point.Id);
                            RemoveFromPosition(position);
                        }
                    }
                }
            }

            return(unbounds);
        }
Beispiel #2
0
        public List <Vector> SeekForCombine(Vector mustContain)
        {
            int sizeY = Size.Y;
            int sizeX = Size.X;

            int bestLength = 0;
            int lastY      = sizeY + 1;

            List <Vector> best = new List <Vector>();

            for (int y = 0; y < sizeY; y++)
            {
                for (int x = 0; x < sizeX; x++)
                {
                    Vector position = new Vector(x, y);

                    var bubble = GetFromPosition(position);
                    if (bubble == null)
                    {
                        continue;
                    }

                    var cType = bubble.Numberos;

                    var combines = GetCombinations(cType, position);
                    combines.Insert(0, position);

                    if (((bestLength == combines.Count && combines[combines.Count - 1].Y < lastY) || bestLength < combines.Count) &&
                        combines.Contains(mustContain))
                    {
                        bestLength = combines.Count;
                        best       = combines;
                        lastY      = combines[combines.Count - 1].Y;
                        OutputLog.AddLog("better combine path found, count => " + bestLength + ", y= " + lastY);
                    }
                }
            }

            return(best);
        }
Beispiel #3
0
        private void CheckForMatch(Vector position)
        {
            var combines = map.SeekForCombine(position);

            OutputLog.AddLog("combine count." + combines.Count);

            if (combines.Count < 2)
            {
                OutputLog.AddLog("no match.");
            }
            else
            {
                var mixTarget = map.GetFromPosition(position); // first member of combinations will get mixes, and start to combine.

                var except = new List <Vector>();
                except.AddRange(combines);

                var mixes = map.GetMixes(mixTarget.Numberos, position, except);

                int mixCount = mixes.Count;
                OutputLog.AddLog("mix count => " + mixCount);

                // first mix
                for (int i = 0; i < mixCount; i++)
                {
                    OutputLog.AddLog("mixing:" + mixes[i] + " to " + mixTarget.Id);
                    GameEvents.OnBubbleMixed?.Invoke(map.GetFromPosition(mixes[i]).Id, mixTarget.Id);

                    AddScore(mixTarget.Numberos);

                    map.RemoveFromPosition(mixes[i]);
                }

                int length = combines.Count;

                for (int i = 0; i < length; i++)
                {
                    OutputLog.AddLog("combine member: " + combines[i]);
                }

                List <Vector> gonnaExplode = new List <Vector>();
                for (int i = 0; i < length - 1; i++)
                {
                    var first = map.GetFromPosition(combines[i]);
                    var next  = map.GetFromPosition(combines[i + 1]);

                    //OutputLog.AddLog("combining: " + first.Id + " to " + next.Id);
                    AddScore(next.Numberos);
                    GameEvents.OnBubbleCombined?.Invoke(first.Id, next.Id);

                    if (!next.IncreaseNumberos())
                    { // max level reached. Explode
                        gonnaExplode.Add(combines[i + 1]);
                    }

                    /// remove first.
                    map.RemoveFromPosition(combines[i]);
                }

                ExplodeThisPoints(gonnaExplode);
            }
        }