Example #1
0
    private void CheckMove(Vector3 dir, int start, int end, int timesRotated = 0)
    {
        Vector3 down  = new Vector3(0.0f, -1.0f, 0.0f);
        int     times = 0;

        for (int i = start; i <= end; i++)
        {
            GameObject temp = GameObject.Instantiate(currentPieceCopy); // get a clone of current piece
            temp.SetActive(false);
            temp.GetComponent <Piece>().Interactable = false;
            Piece script = temp.GetComponent <Piece>();
            script.Move(dir * times);

            if (!script.CanMoveInDirection(Vector3.zero))
            {
                break;
            }

            while (script.CanMoveInDirection(down, boardManager))
            {
                script.Move(down); // go down and try to collide
            }

            boardManager.AddObject(temp);
            int holes     = boardManager.getHolesByColumn().Sum();
            int highestY  = boardManager.getHeightByColumn().Max();
            int willClear = boardManager.getFullLines();

            // keep best values for direction
            if (!directions.ContainsKey(dir * times))
            {
                directions[dir * times] = new List <Vector4> {
                    new Vector4(willClear, holes, highestY, timesRotated)
                };
            }
            else
            {
                directions[dir * times].Add(new Vector4(willClear, holes, highestY, timesRotated));
            }

            boardManager._board = GameManager.instance.BoardManager._board.Clone() as GameObject[, ];
            times++;
            GameObject.Destroy(temp);
        }
    }