Exemple #1
0
    public bool RotateCW(Field field, out SearchNode sn)
    {
        bool   ok            = false;
        Mino   tmp           = mino.Clone();
        int    size          = tmp.GetSize();
        string k             = "c";//操作符,踢墙则为大写C
        int    newRotationId = (tmp.GetRotationId() + 1) % 4;

        if (size == 3)
        {
            if (field.IsValid(tmp, newRotationId, tmp.GetPosition()))//如果可以直接转进去
            {
                tmp.CWRotate();
                ok = true;
            }
            else//如果不能就做踢墙检定
            {
                Vector2Int o = Game.WallKickOffset(field, tmp, tmp.GetRotationId(), newRotationId, tmp.GetPosition());
                if (o != new Vector2Int(0, 0))
                {
                    tmp.CWRotate();
                    tmp.Move(o);
                    k  = "C";
                    ok = true;
                }
                else
                {
                    ok = false;
                }
            }
        }
        else if (size == 5)
        {
            Vector2Int o = Game.WallKickOffset_I(field, tmp, tmp.GetRotationId(), newRotationId, tmp.GetPosition(), out bool iSpin);
            if (o != new Vector2Int(0, 0))
            {
                tmp.CWRotate();
                tmp.Move(o);
                if (iSpin)
                {
                    k = "C";
                }
                ok = true;
            }
            else
            {
                ok = false;
            }
        }
        sn = new SearchNode(tmp, op + k);
        return(ok);
    }
Exemple #2
0
    public int CWRotate()//逆时针旋转
    {
        int size          = activeMino.GetSize();
        int newRotationId = (activeMino.GetRotationId() + 1) % 4;

        if (size == 3)
        {
            if (field.IsValid(activeMino, newRotationId, activeMino.GetPosition()))
            {
                activeMino.CWRotate();
                operation += "c";
                return(0);
            }
            else
            {
                Vector2Int o = WallKickOffset(activeMino, activeMino.GetRotationId(), newRotationId, activeMino.GetPosition());
                if (o != new Vector2Int(0, 0))
                {
                    activeMino.CWRotate();
                    activeMino.Move(o);
                    operation += "C";
                    return(0);
                }
            }
        }
        else if (size == 5)
        {
            bool       iSpin = true;
            Vector2Int o     = WallKickOffset_I(field, activeMino, activeMino.GetRotationId(), newRotationId, activeMino.GetPosition(), out iSpin);
            if (o != new Vector2Int(0, 0))
            {
                activeMino.CWRotate();
                activeMino.Move(o);
                if (iSpin)
                {
                    operation += "C";
                }
                else
                {
                    operation += "c";
                }
                return(0);
            }
        }

        return(-1);
    }