public static Expression Combine(this Expression left, Expression right, CombineType combineType)
    {
        if (left == null)
        {
            return(right);
        }
        if (right == null)
        {
            return(left);
        }

        if (left is ParameterExpression || left is MemberExpression)
        {
            return(right);
        }
        if (right is ParameterExpression || right is MemberExpression)
        {
            return(left);
        }

        switch (combineType)
        {
        case CombineType.And:
            return(Expression.AndAlso(left, right));

        case CombineType.Or:
            return(Expression.OrElse(left, right));

        default:
            return(right);
        }
    }
Example #2
0
        public PhraseCombineInfo(PowerPhraseData pd, PowerPhraseInfo p1, PowerPhraseInfo p2, CombineType combineType, PhraseMetricType metricType)
        {
            PrevPhrase = p1;
            NextPhrase = p2;
            this.CombineType = combineType;
            IntersectionLen = CalcIntersectionLen(p1.Phrase, p2.Phrase);
            if (combineType == CombineType.Overlap && IntersectionLen == 0)
                throw new Exception();

            CommandsStr = p2.Phrase.Substring(IntersectionLen);

            var fakeUnitState = new UnitState(new Cell(0, 0), 0);
            Commands = MovesPrinter.GetCommands(CommandsStr);
            MinX = 0;
            MaxX = 0;
            foreach (var cmd in Commands)
            {
                fakeUnitState = UnitState.MoveFuncs[cmd](fakeUnitState);
                MinX = Math.Min(MinX, fakeUnitState.Pivot.x);
                MaxX = Math.Max(MaxX, fakeUnitState.Pivot.x);
            }
            DY = fakeUnitState.Pivot.y;

            switch (combineType)
            {
                case CombineType.Overlap:
                    EffectiveLen = pd.CalcEffectiveLen(p1.Phrase + CommandsStr) - p1.EffectiveLength;
                    break;
                case CombineType.Append:
                    EffectiveLen = p2.EffectiveLength;
                    break;
                case CombineType.MoveDownAppend:
                    EffectiveLen = p2.EffectiveLength;
                    ++DY;
                    break;
            }

            switch (metricType)
            {
                case PhraseMetricType.Div:
                    Metric = (double)EffectiveLen / DY;
                    break;
                case PhraseMetricType.Diff:
                    Metric = (double)EffectiveLen - DY;
                    break;
                case PhraseMetricType.Div2:
                    Metric = (double)EffectiveLen / (DY + LAST_MOVE_PENALTY[Commands[Commands.Length - 1]]);
                    break;
                case PhraseMetricType.Div3:
                    Metric = (double)EffectiveLen / (DY + LAST_MOVE_PENALTY[Commands[Commands.Length - 1]] * 2);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("metricType");
            }

            DebugPrinter.WriteLine("Phrase combine: \"{0}\" and \"{1}\" with type {2}, effective len {3}, DY {4}, metric {5}",
                p1.Phrase, p2.Phrase, combineType, EffectiveLen, DY, Metric);
        }
Example #3
0
    public static Behavior GetOpenModuleBehavior(string moduleName, CombineType combineType = CombineType.Independent)
    {
        string previousModuleName = GlobalData.CurrentModule;

        return(new Behavior(isRedo => ModuleUtil.OpenModule(moduleName),
                            isReUndo => ModuleUtil.OpenModule(previousModuleName),
                            BehaviorType.OpenModule,
                            false,
                            combineType));
    }
Example #4
0
 public Behavior(Action <bool> doBehavior, Action <bool> undoBehavior, BehaviorType type, bool isModify = true, CombineType combineType = CombineType.Independent)
 {
     Do               = doBehavior;
     Undo             = undoBehavior;
     IsDone           = IsUndone = false;
     Type             = type;
     IsModify         = isModify;
     CombineType      = combineType;
     CreateFrameCount = Time.frameCount;
 }
Example #5
0
 public static Behavior GetUpdateSelectDisplayObjectBehavior(string moduleName,
                                                             List <string> addElements    = null,
                                                             List <string> removeElements = null,
                                                             CombineType combineType      = CombineType.Independent)
 {
     return(new Behavior(isReDo => DisplayObjectUtil.UpdateSelectDisplayObjectDicBehavior(moduleName, addElements, removeElements),
                         isReUndo => DisplayObjectUtil.UpdateSelectDisplayObjectDicBehavior(moduleName, removeElements, addElements),
                         BehaviorType.UpdateSelectedDisplayObjectDic,
                         false,
                         combineType));
 }
Example #6
0
        public static void Combine(CombineType type, List <Skill> list)
        {
            switch (type)
            {
            case CombineType.SliceAndDice:
                Combine("Slice", "Dice", list);
                break;

            case CombineType.DiceAndFinish:
                Combine("Dice", "And finish this!", list);
                break;
            }
        }
Example #7
0
    public static Behavior GetAddDisplayObjectBehavior(string moduleName,
                                                       string elementName,
                                                       string imageUrl,
                                                       Vector2 pos,
                                                       Vector2 size,
                                                       CombineType combineType = CombineType.Independent)
    {
        Element element = new Element {
            Name    = elementName,
            X       = Element.ConvertX(pos.x),
            Y       = Element.ConvertY(pos.y),
            Width   = size.x,
            Height  = size.y,
            Visible = true
        };

        return(new Behavior(isRedo => DisplayObjectUtil.AddDisplayObjectBehavior(moduleName, element, imageUrl),
                            isReUndo => DisplayObjectUtil.RemoveDisplayObjectBehavior(moduleName, element.Name),
                            BehaviorType.AddDisplayObject,
                            true,
                            combineType));
    }
Example #8
0
        public static string CombineAll(CombineType type, params string[] paths)
        {
            string path = paths[0];

            if (paths.Length > 1)
            {
                for (int i = 1; i < paths.Length; i++)
                {
                    if (type == CombineType.File)
                    {
                        path = Path.Combine(path, paths[i]);
                    }
                    else
                    {
                        path = CombineURL(path, paths[i]);
                    }
                }
                if (type == CombineType.File)
                {
                    path = path.Replace('/', '\\');
                }
            }
            return(path);
        }
Example #9
0
 public static Behavior GetCopyDisplayObjectsBehavior(string moduleName, List <Element> copiedElements, bool needSelect = true, CombineType combineType = CombineType.Independent)
 {
     return(new Behavior(isReDo => DisplayObjectUtil.CopySelectDisplayObjectsBehavior(moduleName, copiedElements, needSelect),
                         isReUndo => DisplayObjectUtil.RemoveDisplayObjectsBehavior(moduleName, copiedElements),
                         BehaviorType.CopyDisplayObjects,
                         true,
                         combineType));
 }
Example #10
0
 /// <summary>
 /// Returns a <see cref="System.String" /> that represents this instance.
 /// </summary>
 /// <returns>A <see cref="System.String" /> that represents this instance.</returns>
 public override string ToString()
 {
     return(CombineType.ToString());
 }
Example #11
0
 public RectangularRegion(int minX, int minY, int maxX, int maxY, CombineType combineType)
 {
     Min         = new Vector2(minX, minY);
     Max         = new Vector2(maxX, maxY);
     CombineType = combineType;
 }
Example #12
0
 void ChangeCombineTypeC()
 {
     _combineType = CombineType.TypeC;
 }
Example #13
0
 void ChangeCombineTypeB()
 {
     _combineType = CombineType.TypeB;
 }
Example #14
0
 void ChangeCombineTypeA()
 {
     _combineType = CombineType.TypeA;
 }
Example #15
0
 public SelectStatementCombine(CombineType combine_type)
 {
     _CombineType = combine_type;
 }
Example #16
0
 public RectangularRegion(float minX, float minY, float maxX, float maxY, CombineType combineType) :
     this((int)minX, (int)minY, (int)maxX, (int)maxY, combineType)
 {
 }
		private void AddSpec(ConjunctionAssertion other, CombineType and)
		{
			AddSpec(other);
			combineTypes.Add(and);
		}
Example #18
0
    /// <summary>
    /// Loop of searching possible combines
    /// </summary>
    /// <returns></returns>
    public IEnumerator CheckPossibleCombines()
    {
        if (!itemSprites)
        {
            InitSprites();
        }
        //waiting for 1 second just in case to be sure that field was built
        yield return(new WaitForSeconds(1));

        //allow to show tips
        allowShowTip = true;

        //get max positions of squares
        var maxRow = LevelManager.THIS.levelData.maxRows;
        var maxCol = LevelManager.THIS.levelData.maxCols;

        //variable to check: are we got tip or not
        gotTip = false;

        //break, if the main scripts have not ready yet
        while (LevelManager.THIS == null)
        {
            yield return(new WaitForEndOfFrame());
        }
        //if game is not in Playing status - wait
        while (LevelManager.THIS.gameStatus != GameState.Playing && LevelManager.THIS.gameStatus != GameState.Tutorial)
        {
            yield return(new WaitForEndOfFrame());
        }

        //if drag have not blocked and game status Playing - continue
        if (!LevelManager.THIS.DragBlocked && (LevelManager.THIS.gameStatus == GameState.Playing || LevelManager.THIS.gameStatus == GameState.Tutorial))
        {
            currentPreCombine = new List <Item>();

            if (LevelManager.THIS.gameStatus != GameState.Playing && LevelManager.THIS.gameStatus != GameState.Tutorial)
            {
                yield break;
            }


            //Iteration for search possible combination
            if (itemSprites != null)
            {
                for (var COLOR = 0; COLOR < itemSprites.GetSprites(LevelManager.THIS.currentLevel).Length; COLOR++)
                {
                    if (changeTipAI && Random.Range(0, 2) == 1)
                    {
                        continue;
                    }
                    for (var col = 0; col < LevelManager.THIS.levelData.maxCols; col++)
                    {
                        for (var row = 0; row < LevelManager.THIS.levelData.maxRows; row++)
                        {
                            var square = LevelManager.THIS.GetSquare(col, row);
                            if (square?.GetSubSquare().CanGoOut() == false || square.Item == null)
                            {
                                continue;
                            }
                            //current square called x
                            //o-o-x
                            //	  o
                            vDirection         = Vector3.zero;
                            currentCombineType = CombineType.LShape;
                            if (col > 1 && row < maxRow - 1)
                            {
                                CheckSquare(GetSquare(row + 1, col, square), COLOR, true);
                                CheckSquare(GetSquare(row, col - 1, square), COLOR);
                                CheckSquare(GetSquare(row, col - 2, square), COLOR);
                            }

                            if (currentPreCombine.Count == 3 && GetSquare(row, col, square).CanGoInto())
                            {
                                // StartCoroutine(showTip(nextMoveItems[0], Vector3.up));
                                showTip(currentPreCombine);
                                TipItem    = currentPreCombine[0];
                                vDirection = Vector3.up;
                                yield break;
                            }

                            currentPreCombine.Clear();

                            //    o
                            //o-o x
                            if (col > 1 && row > 0)
                            {
                                CheckSquare(GetSquare(row - 1, col, square), COLOR, true);
                                CheckSquare(GetSquare(row, col - 1, square), COLOR);
                                CheckSquare(GetSquare(row, col - 2, square), COLOR);
                            }

                            if (currentPreCombine.Count == 3 && GetSquare(row, col, square).CanGoInto())
                            {
                                // StartCoroutine(showTip(nextMoveItems[0], Vector3.down));
                                vDirection = Vector3.down;
                                TipItem    = currentPreCombine[0];
                                showTip(currentPreCombine);
                                yield break;
                            }

                            currentPreCombine.Clear();

                            //x o o
                            //o
                            if (col < maxCol - 2 && row < maxRow - 1)
                            {
                                CheckSquare(GetSquare(row + 1, col, square), COLOR, true);
                                CheckSquare(GetSquare(row, col + 1, square), COLOR);
                                CheckSquare(GetSquare(row, col + 2, square), COLOR);
                            }

                            if (currentPreCombine.Count == 3 && GetSquare(row, col, square).CanGoInto())
                            {
                                // StartCoroutine(showTip(nextMoveItems[0], Vector3.up));
                                vDirection = Vector3.up;
                                TipItem    = currentPreCombine[0];
                                showTip(currentPreCombine);
                                yield break;
                            }

                            currentPreCombine.Clear();

                            //o
                            //x o o
                            if (col < maxCol - 2 && row > 0)
                            {
                                CheckSquare(GetSquare(row - 1, col, square), COLOR, true);
                                CheckSquare(GetSquare(row, col + 1, square), COLOR);
                                CheckSquare(GetSquare(row, col + 2, square), COLOR);
                            }

                            if (currentPreCombine.Count == 3 && GetSquare(row, col, square).CanGoInto())
                            {
                                //  StartCoroutine(showTip(nextMoveItems[0], Vector3.down));
                                vDirection = Vector3.down;
                                TipItem    = currentPreCombine[0];
                                showTip(currentPreCombine);
                                yield break;
                            }

                            currentPreCombine.Clear();

                            //o
                            //o
                            //x o
                            if (col < maxCol - 1 && row > 1)
                            {
                                CheckSquare(GetSquare(row, col + 1, square), COLOR, true);
                                CheckSquare(GetSquare(row - 1, col, square), COLOR);
                                CheckSquare(GetSquare(row - 2, col, square), COLOR);
                            }

                            if (currentPreCombine.Count == 3 && GetSquare(row, col, square).CanGoInto())
                            {
                                // StartCoroutine(showTip(nextMoveItems[0], Vector3.left));
                                vDirection = Vector3.left;
                                TipItem    = currentPreCombine[0];
                                showTip(currentPreCombine);
                                yield break;
                            }

                            currentPreCombine.Clear();

                            //x o
                            //o
                            //o
                            if (col < maxCol - 1 && row < maxRow - 2)
                            {
                                CheckSquare(GetSquare(row, col + 1, square), COLOR, true);
                                CheckSquare(GetSquare(row + 1, col, square), COLOR);
                                CheckSquare(GetSquare(row + 2, col, square), COLOR);
                            }

                            if (currentPreCombine.Count == 3 && GetSquare(row, col, square).CanGoInto())
                            {
                                //  StartCoroutine(showTip(nextMoveItems[0], Vector3.left));
                                vDirection = Vector3.left;
                                TipItem    = currentPreCombine[0];
                                showTip(currentPreCombine);
                                yield break;
                            }

                            currentPreCombine.Clear();

                            //	o
                            //  o
                            //o x
                            if (col > 0 && row > 1)
                            {
                                CheckSquare(GetSquare(row, col - 1, square), COLOR, true);
                                CheckSquare(GetSquare(row - 1, col, square), COLOR);
                                CheckSquare(GetSquare(row - 2, col, square), COLOR);
                            }

                            if (currentPreCombine.Count == 3 && GetSquare(row, col, square).CanGoInto())
                            {
                                //  StartCoroutine(showTip(nextMoveItems[0], Vector3.right));
                                vDirection = Vector3.right;
                                TipItem    = currentPreCombine[0];
                                showTip(currentPreCombine);
                                yield break;
                            }

                            currentPreCombine.Clear();

                            //o x
                            //  o
                            //  o
                            if (col > 0 && row < maxRow - 2)
                            {
                                CheckSquare(GetSquare(row, col - 1, square), COLOR, true);
                                CheckSquare(GetSquare(row + 1, col, square), COLOR);
                                CheckSquare(GetSquare(row + 2, col, square), COLOR);
                            }

                            if (currentPreCombine.Count == 3 && GetSquare(row, col, square).CanGoInto())
                            {
                                //  StartCoroutine(showTip(nextMoveItems[0], Vector3.right));
                                vDirection = Vector3.right;
                                TipItem    = currentPreCombine[0];
                                showTip(currentPreCombine);
                                yield break;
                            }

                            currentPreCombine.Clear();

                            //o-x-o-o
                            if (col < maxCol - 2 && col > 0)
                            {
                                CheckSquare(GetSquare(row, col - 1, square), COLOR, true);
                                CheckSquare(GetSquare(row, col + 1, square), COLOR);
                                CheckSquare(GetSquare(row, col + 2, square), COLOR);
                            }

                            if (currentPreCombine.Count == 3 && GetSquare(row, col, square).CanGoInto())
                            {
                                //   StartCoroutine(showTip(nextMoveItems[0], Vector3.right));
                                vDirection = Vector3.right;
                                TipItem    = currentPreCombine[0];
                                showTip(currentPreCombine);
                                yield break;
                            }

                            currentPreCombine.Clear();
                            //o-o-x-o
                            if (col < maxCol - 1 && col > 1)
                            {
                                CheckSquare(GetSquare(row, col + 1, square), COLOR, true);
                                CheckSquare(GetSquare(row, col - 1, square), COLOR);
                                CheckSquare(GetSquare(row, col - 2, square), COLOR);
                            }

                            if (currentPreCombine.Count == 3 && GetSquare(row, col, square).CanGoInto())
                            {
                                //   StartCoroutine(showTip(nextMoveItems[0], Vector3.left));
                                vDirection = Vector3.left;
                                TipItem    = currentPreCombine[0];
                                showTip(currentPreCombine);
                                yield break;
                            }

                            currentPreCombine.Clear();
                            //o
                            //x
                            //o
                            //o
                            if (row < maxRow - 2 && row > 0)
                            {
                                CheckSquare(GetSquare(row - 1, col, square), COLOR, true);
                                CheckSquare(GetSquare(row + 1, col, square), COLOR);
                                CheckSquare(GetSquare(row + 2, col, square), COLOR);
                            }

                            if (currentPreCombine.Count == 3 && GetSquare(row, col, square).CanGoInto())
                            {
                                //  StartCoroutine(showTip(nextMoveItems[0], Vector3.down));
                                vDirection = Vector3.down;
                                TipItem    = currentPreCombine[0];
                                showTip(currentPreCombine);
                                yield break;
                            }

                            currentPreCombine.Clear();

                            //o
                            //o
                            //x
                            //o
                            if (row < maxRow - 2 && row > 1)
                            {
                                CheckSquare(GetSquare(row + 1, col, square), COLOR, true);
                                CheckSquare(GetSquare(row - 1, col, square), COLOR);
                                CheckSquare(GetSquare(row - 2, col, square), COLOR);
                            }

                            if (currentPreCombine.Count == 3 && GetSquare(row, col, square).CanGoInto())
                            {
                                //   StartCoroutine(showTip(nextMoveItems[0], Vector3.up));
                                vDirection = Vector3.up;
                                TipItem    = currentPreCombine[0];
                                showTip(currentPreCombine);
                                yield break;
                            }

                            currentPreCombine.Clear();
                            //  o
                            //o x o
                            //  o
                            var h = 0;
                            var v = 0;
                            currentCombineType = CombineType.VShape;

                            if (row < maxRow - 1)
                            {
                                var square1 = GetSquare(row + 1, col, square);
                                if (square1)
                                {
                                    //1.6
                                    if (square1.Item != null)
                                    {
                                        if (CheckColorCondition(square1, COLOR))
                                        {
                                            vDirection = Vector3.up;
                                            currentPreCombine.Add(square1.Item);
                                            v++;
                                        }
                                    }
                                }
                            }

                            if (row > 0)
                            {
                                var square1 = GetSquare(row - 1, col, square);
                                if (square1)
                                {
                                    //1.6
                                    if (square1.Item != null)
                                    {
                                        if (CheckColorCondition(square1, COLOR))
                                        {
                                            vDirection = Vector3.down;
                                            currentPreCombine.Add(square1.Item);
                                            v++;
                                        }
                                    }
                                }
                            }

                            if (col > 0)
                            {
                                var square1 = GetSquare(row, col - 1, square);
                                if (square1)
                                {
                                    //1.6
                                    if (square1.Item != null)
                                    {
                                        if (CheckColorCondition(square1, COLOR))
                                        {
                                            vDirection = Vector3.right;
                                            currentPreCombine.Add(square1.Item);
                                            h++;
                                        }
                                    }
                                }
                            }

                            if (col < maxCol - 1)
                            {
                                var square1 = GetSquare(row, col + 1, square);
                                if (square1)
                                {
                                    //1.6
                                    if (square1.Item != null)
                                    {
                                        if (CheckColorCondition(square1, COLOR))
                                        {
                                            vDirection = Vector3.left;
                                            currentPreCombine.Add(square1.Item);
                                            h++;
                                        }
                                    }
                                }
                            }

                            //if we found 3or more items and they not lock show tip
                            if (currentPreCombine.Count == 3 && square.CanGoInto() && square.GetSubSquare().CanGoOut())
                            {
                                if (v > h && currentPreCombine[2].square.GetSubSquare().CanGoOut())
                                {
                                    //StartCoroutine(showTip(nextMoveItems[2], new Vector3(Random.Range(-1f, 1f), 0, 0)));
                                    TipItem = currentPreCombine[2];
                                    if (TipItem.transform.position.x > currentPreCombine[0].transform.position.x)
                                    {
                                        vDirection = Vector3.left;
                                    }
                                    else
                                    {
                                        vDirection = Vector3.right;
                                    }
                                    showTip(currentPreCombine);
                                    yield break;
                                }

                                if (v < h && currentPreCombine[0].square.GetSubSquare().CanGoOut())
                                {
                                    // StartCoroutine(showTip(nextMoveItems[0], new Vector3(0, Random.Range(-1f, 1f), 0)));
                                    TipItem = currentPreCombine[0];
                                    if (TipItem.transform.position.y > currentPreCombine[0].transform.position.y)
                                    {
                                        vDirection = Vector3.down;
                                    }
                                    else
                                    {
                                        vDirection = Vector3.up;
                                    }

                                    showTip(currentPreCombine);
                                    yield break;
                                }

                                currentPreCombine.Clear();
                            }
                            else if (square.item && square.item.currentType != ItemsTypes.NONE && square.CanGoInto() && square.GetSubSquare().CanGoOut() &&
                                     square.Item.Combinable &&
                                     square.Item.CombinableWithBonus && currentPreCombine.Count < 3)
                            {
                                currentPreCombine.Clear();
                                List <Square> allNeghborsCross = square.GetAllNeghborsCross();
                                var           neibSquare       = allNeghborsCross.FirstOrDefault(i => i.Item && i.Item.currentType != ItemsTypes.NONE);
                                if (neibSquare && neibSquare.Item && neibSquare.Item.Combinable)
                                {
                                    TipItem    = square.Item;
                                    vDirection = (neibSquare.Item.transform.position - square.Item.transform.position).normalized;
                                    currentPreCombine.Add(square.Item);
                                    currentPreCombine.Add(neibSquare.Item);
                                    showTip(currentPreCombine);
                                    yield break;
                                }

                                currentPreCombine.Clear();
                            }
                            else
                            {
                                currentPreCombine.Clear();
                            }
                        }
                    }
                }
            }

            //if we don't get any tip.  call nomatches to regenerate level
            if (!LevelManager.THIS.DragBlocked && !LevelManager.THIS.field.GetItems().Any(i => i.falling || i.destroying))
            {
                if (!gotTip)
                {
                    LevelManager.THIS.NoMatches();
                }
            }

            //        }
            yield return(new WaitForEndOfFrame());

            //find possible combination again
            if (!LevelManager.THIS.DragBlocked)
            {
                StartCoroutine(CheckPossibleCombines());
            }
            else
            {
                yield return(new WaitForSeconds(2));

                StartCoroutine(CheckPossibleCombines());
            }
        }
    }
Example #19
0
 public MixCurve(MixCurve other)
 {
   m_enabled = other.m_enabled;
   m_animated = other.m_animated;
   m_foldout = other.m_foldout;
   //
   m_curveType = other.m_curveType;
   m_animationTarget = other.m_animationTarget;
   m_animationMode = other.m_animationMode;
   m_combine = other.m_combine;
   //
   m_speed = other.m_speed;
   m_scaleX = other.m_scaleX;
   m_scaleY = other.m_scaleY;
   m_translateX = other.m_translateX;
   m_translateY = other.m_translateY;
   m_absolute = other.m_absolute;
 }
Example #20
0
    /// <summary>
    /// Loop of searching possible combines
    /// </summary>
    /// <returns></returns>
    public IEnumerator CheckPossibleCombines()
    {
        //waiting for 1 second just in case to be sure that field was built
        yield return(new WaitForSeconds(1));

        //allow to show tips
        allowShowTip = true;

        //get max positions of squares
        int maxRow = EliminationMgr.Instance.maxRows;
        int maxCol = EliminationMgr.Instance.maxCols;

        //variable to check: are we got tip or not
        gotTip = false;

        //break, if the main scripts have not ready yet
        while (EliminationMgr.Instance == null)
        {
            yield return(new WaitForEndOfFrame());
        }
        //if game is not in Playing status - wait
        while (EliminationMgr.Instance.GameStatus != GameStatusEnum.Playing)
        {
            yield return(new WaitForEndOfFrame());
        }

        //if drag have not blocked and game status Playing - continue
        if (!EliminationMgr.Instance.DragBlocked && EliminationMgr.Instance.GameStatus == GameStatusEnum.Playing)
        {
            nextMoveItems = new List <Item> ();

            if (EliminationMgr.Instance.GameStatus != GameStatusEnum.Playing)
            {
                yield break;
            }


            Item it = GameObject.FindGameObjectWithTag("Item").GetComponent <Item> ();

            //Iteration for search possible combination
            foreach (int COLOR in EliminationMgr.Instance.colorLimitLst)
            {
//			for (int COLOR = 0; COLOR < 14; COLOR++) {
                for (int col = 0; col < EliminationMgr.Instance.maxCols; col++)
                {
                    for (int row = 0; row < EliminationMgr.Instance.maxRows; row++)
                    {
                        Square square = EliminationMgr.Instance.GetSquare(col, row);
                        if (square.type == SquareTypes.WIREBLOCK || square.item == null)
                        {
                            continue;
                        }
                        //current square called x
                        //o-o-x
                        //	  o
                        vDirection  = Vector3.zero;
                        combineType = CombineType.LShape;
                        if (col > 1 && row < maxRow - 1)
                        {
                            CheckSquare(GetSquare(row + 1, col), COLOR, true);
                            CheckSquare(GetSquare(row, col - 1), COLOR);
                            CheckSquare(GetSquare(row, col - 2), COLOR);
                        }
                        if (nextMoveItems.Count == 3 && GetSquare(row, col).CanGoInto())
                        {
                            // StartCoroutine(showTip(nextMoveItems[0], Vector3.up));
                            showTip(nextMoveItems);
                            tipItem    = nextMoveItems [0];
                            vDirection = Vector3.up;
                            yield break;
                        }
                        else
                        {
                            nextMoveItems.Clear();
                        }

                        //    o
                        //o-o x
                        if (col > 1 && row > 0)
                        {
                            CheckSquare(GetSquare(row - 1, col), COLOR, true);
                            CheckSquare(GetSquare(row, col - 1), COLOR);
                            CheckSquare(GetSquare(row, col - 2), COLOR);
                        }
                        if (nextMoveItems.Count == 3 && GetSquare(row, col).CanGoInto())
                        {
                            // StartCoroutine(showTip(nextMoveItems[0], Vector3.down));
                            vDirection = Vector3.down;
                            tipItem    = nextMoveItems [0];
                            showTip(nextMoveItems);
                            yield break;
                        }
                        else
                        {
                            nextMoveItems.Clear();
                        }

                        //x o o
                        //o
                        if (col < maxCol - 2 && row < maxRow - 1)
                        {
                            CheckSquare(GetSquare(row + 1, col), COLOR, true);
                            CheckSquare(GetSquare(row, col + 1), COLOR);
                            CheckSquare(GetSquare(row, col + 2), COLOR);
                        }
                        if (nextMoveItems.Count == 3 && GetSquare(row, col).CanGoInto())
                        {
                            // StartCoroutine(showTip(nextMoveItems[0], Vector3.up));
                            vDirection = Vector3.up;
                            tipItem    = nextMoveItems [0];
                            showTip(nextMoveItems);
                            yield break;
                        }
                        else
                        {
                            nextMoveItems.Clear();
                        }

                        //o
                        //x o o
                        if (col < maxCol - 2 && row > 0)
                        {
                            CheckSquare(GetSquare(row - 1, col), COLOR, true);
                            CheckSquare(GetSquare(row, col + 1), COLOR);
                            CheckSquare(GetSquare(row, col + 2), COLOR);
                        }
                        if (nextMoveItems.Count == 3 && GetSquare(row, col).CanGoInto())
                        {
                            //  StartCoroutine(showTip(nextMoveItems[0], Vector3.down));
                            vDirection = Vector3.down;
                            tipItem    = nextMoveItems [0];
                            showTip(nextMoveItems);
                            yield break;
                        }
                        else
                        {
                            nextMoveItems.Clear();
                        }

                        //o
                        //o
                        //x o
                        if (col < maxCol - 1 && row > 1)
                        {
                            CheckSquare(GetSquare(row, col + 1), COLOR, true);
                            CheckSquare(GetSquare(row - 1, col), COLOR);
                            CheckSquare(GetSquare(row - 2, col), COLOR);
                        }
                        if (nextMoveItems.Count == 3 && GetSquare(row, col).CanGoInto())
                        {
                            // StartCoroutine(showTip(nextMoveItems[0], Vector3.left));
                            vDirection = Vector3.left;
                            tipItem    = nextMoveItems [0];
                            showTip(nextMoveItems);
                            yield break;
                        }
                        else
                        {
                            nextMoveItems.Clear();
                        }

                        //x o
                        //o
                        //o
                        if (col < maxCol - 1 && row < maxRow - 2)
                        {
                            CheckSquare(GetSquare(row, col + 1), COLOR, true);
                            CheckSquare(GetSquare(row + 1, col), COLOR);
                            CheckSquare(GetSquare(row + 2, col), COLOR);
                        }
                        if (nextMoveItems.Count == 3 && GetSquare(row, col).CanGoInto())
                        {
                            //  StartCoroutine(showTip(nextMoveItems[0], Vector3.left));
                            vDirection = Vector3.left;
                            tipItem    = nextMoveItems [0];
                            showTip(nextMoveItems);
                            yield break;
                        }
                        else
                        {
                            nextMoveItems.Clear();
                        }

                        //	o
                        //  o
                        //o x
                        if (col > 0 && row > 1)
                        {
                            CheckSquare(GetSquare(row, col - 1), COLOR, true);
                            CheckSquare(GetSquare(row - 1, col), COLOR);
                            CheckSquare(GetSquare(row - 2, col), COLOR);
                        }
                        if (nextMoveItems.Count == 3 && GetSquare(row, col).CanGoInto())
                        {
                            //  StartCoroutine(showTip(nextMoveItems[0], Vector3.right));
                            vDirection = Vector3.right;
                            tipItem    = nextMoveItems [0];
                            showTip(nextMoveItems);
                            yield break;
                        }
                        else
                        {
                            nextMoveItems.Clear();
                        }

                        //o x
                        //  o
                        //  o
                        if (col > 0 && row < maxRow - 2)
                        {
                            CheckSquare(GetSquare(row, col - 1), COLOR, true);
                            CheckSquare(GetSquare(row + 1, col), COLOR);
                            CheckSquare(GetSquare(row + 2, col), COLOR);
                        }
                        if (nextMoveItems.Count == 3 && GetSquare(row, col).CanGoInto())
                        {
                            //  StartCoroutine(showTip(nextMoveItems[0], Vector3.right));
                            vDirection = Vector3.right;
                            tipItem    = nextMoveItems [0];
                            showTip(nextMoveItems);
                            yield break;
                        }
                        else
                        {
                            nextMoveItems.Clear();
                        }

                        //o-x-o-o
                        if (col < maxCol - 2 && col > 0)
                        {
                            CheckSquare(GetSquare(row, col - 1), COLOR, true);
                            CheckSquare(GetSquare(row, col + 1), COLOR);
                            CheckSquare(GetSquare(row, col + 2), COLOR);
                        }
                        if (nextMoveItems.Count == 3 && GetSquare(row, col).CanGoInto())
                        {
                            //   StartCoroutine(showTip(nextMoveItems[0], Vector3.right));
                            vDirection = Vector3.right;
                            tipItem    = nextMoveItems [0];
                            showTip(nextMoveItems);
                            yield break;
                        }
                        else
                        {
                            nextMoveItems.Clear();
                        }
                        //o-o-x-o
                        if (col < maxCol - 1 && col > 1)
                        {
                            CheckSquare(GetSquare(row, col + 1), COLOR, true);
                            CheckSquare(GetSquare(row, col - 1), COLOR);
                            CheckSquare(GetSquare(row, col - 2), COLOR);
                        }
                        if (nextMoveItems.Count == 3 && GetSquare(row, col).CanGoInto())
                        {
                            //   StartCoroutine(showTip(nextMoveItems[0], Vector3.left));
                            vDirection = Vector3.left;
                            tipItem    = nextMoveItems [0];
                            showTip(nextMoveItems);
                            yield break;
                        }
                        else
                        {
                            nextMoveItems.Clear();
                        }
                        //o
                        //x
                        //o
                        //o
                        if (row < maxRow - 2 && row > 0)
                        {
                            CheckSquare(GetSquare(row - 1, col), COLOR, true);
                            CheckSquare(GetSquare(row + 1, col), COLOR);
                            CheckSquare(GetSquare(row + 2, col), COLOR);
                        }
                        if (nextMoveItems.Count == 3 && GetSquare(row, col).CanGoInto())
                        {
                            //  StartCoroutine(showTip(nextMoveItems[0], Vector3.down));
                            vDirection = Vector3.down;
                            tipItem    = nextMoveItems [0];
                            showTip(nextMoveItems);
                            yield break;
                        }
                        else
                        {
                            nextMoveItems.Clear();
                        }

                        //o
                        //o
                        //x
                        //o
                        if (row < maxRow - 2 && row > 1)
                        {
                            CheckSquare(GetSquare(row + 1, col), COLOR, true);
                            CheckSquare(GetSquare(row - 1, col), COLOR);
                            CheckSquare(GetSquare(row - 2, col), COLOR);
                        }
                        if (nextMoveItems.Count == 3 && GetSquare(row, col).CanGoInto())
                        {
                            //   StartCoroutine(showTip(nextMoveItems[0], Vector3.up));
                            vDirection = Vector3.up;
                            tipItem    = nextMoveItems [0];
                            showTip(nextMoveItems);
                            yield break;
                        }
                        else
                        {
                            nextMoveItems.Clear();
                        }
                        //  o
                        //o x o
                        //  o
                        int h = 0;
                        int v = 0;
                        combineType = CombineType.VShape;

                        if (row < maxRow - 1)
                        {
                            square = GetSquare(row + 1, col);
                            if (square)                              //1.6
                            {
                                if (square.item != null)
                                {
                                    if (square.item.color == COLOR)
                                    {
                                        vDirection = Vector3.up;
                                        nextMoveItems.Add(square.item);
                                        v++;
                                    }
                                }
                            }
                        }
                        if (row > 0)
                        {
                            square = GetSquare(row - 1, col);
                            if (square)                              //1.6
                            {
                                if (square.item != null)
                                {
                                    if (square.item.color == COLOR)
                                    {
                                        vDirection = Vector3.down;
                                        nextMoveItems.Add(square.item);
                                        v++;
                                    }
                                }
                            }
                        }
                        if (col > 0)
                        {
                            square = GetSquare(row, col - 1);
                            if (square)                              //1.6
                            {
                                if (square.item != null)
                                {
                                    if (square.item.color == COLOR)
                                    {
                                        vDirection = Vector3.right;
                                        nextMoveItems.Add(square.item);
                                        h++;
                                    }
                                }
                            }
                        }
                        if (col < maxCol - 1)
                        {
                            square = GetSquare(row, col + 1);
                            if (square)                              //1.6
                            {
                                if (square.item != null)
                                {
                                    if (square.item.color == COLOR)
                                    {
                                        vDirection = Vector3.left;
                                        nextMoveItems.Add(square.item);
                                        h++;
                                    }
                                }
                            }
                        }

//if we found 3or more items and they not lock show tip
                        if (nextMoveItems.Count == 3 && GetSquare(row, col).CanGoInto() && GetSquare(row, col).type != SquareTypes.WIREBLOCK)
                        {
                            if (v > h && nextMoveItems [2].square.type != SquareTypes.WIREBLOCK)                               //StartCoroutine(showTip(nextMoveItems[2], new Vector3(Random.Range(-1f, 1f), 0, 0)));
                            {
                                tipItem = nextMoveItems [2];
                                if (tipItem.transform.position.x > nextMoveItems [0].transform.position.x)
                                {
                                    vDirection = Vector3.left;
                                }
                                else
                                {
                                    vDirection = Vector3.right;
                                }
                                showTip(nextMoveItems);
                                yield break;
                            }
                            else if (v < h && nextMoveItems [0].square.type != SquareTypes.WIREBLOCK)                                 // StartCoroutine(showTip(nextMoveItems[0], new Vector3(0, Random.Range(-1f, 1f), 0)));
                            {
                                tipItem = nextMoveItems [0];
                                if (tipItem.transform.position.y > nextMoveItems [0].transform.position.y)
                                {
                                    vDirection = Vector3.down;
                                }
                                else
                                {
                                    vDirection = Vector3.up;
                                }

                                showTip(nextMoveItems);
                                yield break;
                            }
                            else
                            {
                                nextMoveItems.Clear();
                            }
                        }
                        else
                        {
                            nextMoveItems.Clear();
                        }
                    }
                }
            }
//if we don't get any tip.  call nomatches to regenerate level
            if (!EliminationMgr.Instance.DragBlocked)
            {
                if (!gotTip)
                {
                    EliminationMgr.Instance.NoMatches();
                }
            }
        }
        yield return(new WaitForEndOfFrame());

//find possible combination again
        if (!EliminationMgr.Instance.DragBlocked)
        {
            StartCoroutine(CheckPossibleCombines());
        }

        // }
    }
Example #21
0
        private IEnumerable<List<int>> EnumeratePreparationMoves(CombineType combineType)
        {
            var moves = new List<int>();
            if (combineType != CombineType.MoveDownAppend)
            {
                yield return moves;
            }

            if (combineType != CombineType.Overlap)
            {
                int maxDepth = 10; //_field.Width  + 5;
                int[] firstMoves = combineType == CombineType.Append ? NON_DOWN_MOVES : DOWN_MOVES;

                var visited = new HashSet<UnitState>();

                var stack = new List<MoveInfo>();
                foreach (int firstMove in firstMoves)
                {
                    var unitState = new UnitState(new Cell(0, 0), 0);
                    UnitState newState = UnitState.MoveFuncs[firstMove](unitState);
                    newState.Normalize(_unit);
                    if (visited.Contains(newState))
                        continue;
                    visited.Add(newState);

                    stack.Add(new MoveInfo { Move = firstMove, NextMoveIdx = -1, UnitState = newState });
                    moves.Add(firstMove);

                    while (stack.Count > 0)
                    {
                        var moveInfo = stack[stack.Count - 1];

                        if (moveInfo.NextMoveIdx == -1)
                            yield return moves;

                        ++moveInfo.NextMoveIdx;
                        if (moveInfo.NextMoveIdx < NON_DOWN_MOVES.Length && stack.Count < maxDepth)
                        {
                            int move = NON_DOWN_MOVES[moveInfo.NextMoveIdx];
                            newState = UnitState.MoveFuncs[move](moveInfo.UnitState);
                            newState.Normalize(_unit);
                            if (visited.Contains(newState))
                                continue;
                            visited.Add(newState);
                            stack.Add(new MoveInfo { Move = move, NextMoveIdx = -1, UnitState = newState });
                            moves.Add(move);
                        }
                        else
                        {
                            stack.RemoveAt(stack.Count - 1);
                            moves.RemoveAt(moves.Count - 1);
                        }
                    }
                }
            }
        }
Example #22
0
 private void AddSpec(ConjunctionAssertion other, CombineType and)
 {
     AddSpec(other);
     combineTypes.Add(and);
 }
Example #23
0
        private protected virtual Expression Combine(Expression left, Expression right, CombineType combineType)
        {
            if (left == null)
            {
                return(right);
            }
            if (right == null)
            {
                return(left);
            }

            if (left is ParameterExpression || left is MemberExpression)
            {
                return(right);
            }
            if (right is ParameterExpression || right is MemberExpression)
            {
                return(left);
            }

            switch (combineType)
            {
            case CombineType.And:
                return(Expression.And(left, right));

            case CombineType.Or:
                return(Expression.Or(left, right));

            default:
                return(right);
            }
        }