Ejemplo n.º 1
0
        public static void Log(GridValidState gvs)
        {
            switch (gvs)
            {
            case GridValidState.VOID:
                Debug.Log("当前意向网格的状态为空");
                break;

            case GridValidState.USING:
                Debug.Log("当前意向网格的状态为正在使用中");
                break;

            case GridValidState.INVALID:
                Debug.Log("当前意向网格的状态为非法越界");
                break;

            case GridValidState.OUTRANGE:
                Debug.Log("当前意向网格的状态为尖角越界");
                break;

            default:
                Debug.Log("当前意向网格的状态超脱了限制范围");
                break;
            }
        }
Ejemplo n.º 2
0
        public static bool moveChessInBoard(LiuheChess lc, LiuheChessBoard lcb)
        {
            int[]          pos = lcb.getPointPos(lc.x, lc.y, lc.dir);
            GridValidState gvs = getGridValidState(lcb, pos[0], pos[1]);

            if (gvs != GridValidState.VOID)
            {
                return(false);
            }
            else
            {
                LiuheChessBoard lcb2 = lcb.getCopy();
                LiuheChess      lc2  = lcb2.findChessByIdnum(lc.identityNumber);
                if (lc2 == null)
                {
                    Debug.Log("严重错误");
                    return(false);
                }
                lc2.x = pos[0];
                lc2.y = pos[1];

                GameBoardCalculateItself(lcb2);
                if (lc2.health <= 0)
                {
                    return(false);
                }

                lc.x = pos[0];
                lc.y = pos[1];
                GameBoardCalculateItself(lcb);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public static LiuheChessBoard getTryChessesEndBoard(List <ChessObj> coses, LiuheChessBoard lcb)
        {
            LiuheChessBoard lcb2 = lcb.getCopy();

            foreach (ChessObj co in coses)
            {
                //获取新棋子
                LiuheChess     lc  = lcb.findChessByIdnum(co._ChessIdentityNumber);
                int[]          pos = lcb.getPointPos(lc.x, lc.y, lc.dir);
                GridValidState gvs = getGridValidState(lcb, pos[0], pos[1]);

                if (gvs != GridValidState.VOID)
                {
                    return(null);
                }
                //棋子存在而且位置可用
                else
                {
                    LiuheChess lc2 = lcb2.findChessByIdnum(lc.identityNumber);
                    //移动棋子
                    if (lc2 == null)
                    {
                        //不可移动的时候严重错误
                        Debug.Log("严重错误");
                        return(null);
                    }
                    lc2.x = pos[0];
                    lc2.y = pos[1];
                }
            }

            GameBoardCalculateItself(lcb2);
            return(lcb2);
        }
Ejemplo n.º 4
0
        public static LiuheChessBoard getTryEndBoard(ChessObj co, LiuheChessBoard lcb)
        {
            LiuheChess lc = lcb.findChessByIdnum(co._ChessIdentityNumber);

            int[]          pos = lcb.getPointPos(lc.x, lc.y, lc.dir);
            GridValidState gvs = getGridValidState(lcb, pos[0], pos[1]);

            if (gvs != GridValidState.VOID)
            {
                return(null);
            }
            else
            {
                LiuheChessBoard lcb2 = lcb.getCopy();
                LiuheChess      lc2  = lcb2.findChessByIdnum(lc.identityNumber);
                if (lc2 == null)
                {
                    Debug.Log("严重错误");
                    return(null);
                }
                lc2.x = pos[0];
                lc2.y = pos[1];

                GameBoardCalculateItself(lcb2);
                return(lcb2);
            }
        }
Ejemplo n.º 5
0
        public bool isThisGridEmpty(int xx, int yy)
        {
            GridValidState gvs = Rules.Rules.getGridValidState(_GameBoard, xx, yy);

            if (gvs == GridValidState.VOID)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 6
0
        public static LiuheChessBoard getTryResult(LiuheChessBoard board, int xx, int yy, int dir, LiuhePlayer lp)
        {
            GridValidState gvs = getGridValidState(board, xx, yy);

            if (gvs != GridValidState.VOID)
            {
                LiuheLogger.Log(gvs);
                return(null);
            }
            int idm = board.addNewChess(xx, yy, dir, lp._PlayerIndex);

            if (idm < 0)
            {
                //Debug.Log("此位置存在错误!");
                return(null);
            }

            GameBoardCalculateItself(board);

            return(board);
        }
Ejemplo n.º 7
0
    public static List <PlaceMethod> getAllValidPlaceMethod(LiuheChessBoard lcbIn)
    {
        List <PlaceMethod> pms = new List <PlaceMethod>();

        //预制不下棋到选择里面去
        pms.Add(new PlaceMethod().setNone());

        int ownner, gridLevel;

        ownner    = GameManager._Main._PlayerNow;
        gridLevel = GameManager._Main._BoardLevel;

        LiuheChessBoard lcb  = lcbIn;
        List <int>      udrs = Rules.getUsableDirection(lcb);

        for (int i = 0; i < 2 * gridLevel - 1; i++)
        {
            //上半截
            if (i < gridLevel)
            {
                for (int j = 0; j < i + gridLevel; j++)
                {
                    int xx, yy;
                    xx = i - gridLevel + 1;
                    yy = j - gridLevel + 1;

                    GridValidState gvs = Rules.getGridValidState(lcb, xx, yy);
                    //如果此网格可以用
                    if (gvs == GridValidState.VOID)
                    {
                        for (int k = 0; k < udrs.Count; k++)
                        {
                            pms.Add(new PlaceMethod().addAction(PLACE_TYPE.ADD, xx, yy, udrs[k], ownner));
                        }
                    }
                }
            }
            //下半截
            else
            {
                for (int j = i - gridLevel + 1; j < 2 * gridLevel - 1; j++)
                {
                    int xx, yy;
                    xx = i - gridLevel + 1;
                    yy = j - gridLevel + 1;
                    GridValidState gvs = Rules.getGridValidState(lcb, xx, yy);
                    //如果此网格可以用
                    if (gvs == GridValidState.VOID)
                    {
                        for (int k = 0; k < udrs.Count; k++)
                        {
                            pms.Add(new PlaceMethod().addAction(PLACE_TYPE.ADD, xx, yy, udrs[k], ownner));
                        }
                    }
                }
            }
        }


        List <PlaceMethod> pms2 = new List <PlaceMethod>();

        foreach (PlaceMethod pm in pms)
        {
            if (pm.isValid(lcb))
            {
                pms2.Add(pm);
            }
        }

        return(pms2);
    }
Ejemplo n.º 8
0
    public static PlaceMethod getRandomPlaceMethod()
    {
        List <PlaceMethod> pms = new List <PlaceMethod>();

        //预制不下棋到选择里面去
        pms.Add(new PlaceMethod().setNone());

        int ownner, gridLevel;

        ownner    = GameManager._Main._PlayerNow;
        gridLevel = GameManager._Main._BoardLevel;

        LiuheChessBoard lcb  = GameManager._Main._GameBoard.getCopy();
        List <int>      udrs = Rules.getUsableDirection(lcb);

        for (int i = 0; i < 2 * gridLevel - 1; i++)
        {
            //上半截
            if (i < gridLevel)
            {
                for (int j = 0; j < i + gridLevel; j++)
                {
                    int xx, yy;
                    xx = i - gridLevel + 1;
                    yy = j - gridLevel + 1;

                    GridValidState gvs = Rules.getGridValidState(lcb, xx, yy);
                    //如果此网格可以用
                    if (gvs == GridValidState.VOID)
                    {
                        for (int k = 0; k < udrs.Count; k++)
                        {
                            pms.Add(new PlaceMethod().addAction(PLACE_TYPE.ADD, xx, yy, udrs[k], ownner));
                        }
                    }
                }
            }
            //下半截
            else
            {
                for (int j = i - gridLevel + 1; j < 2 * gridLevel - 1; j++)
                {
                    int xx, yy;
                    xx = i - gridLevel + 1;
                    yy = j - gridLevel + 1;
                    GridValidState gvs = Rules.getGridValidState(lcb, xx, yy);
                    //如果此网格可以用
                    if (gvs == GridValidState.VOID)
                    {
                        for (int k = 0; k < udrs.Count; k++)
                        {
                            pms.Add(new PlaceMethod().addAction(PLACE_TYPE.ADD, xx, yy, udrs[k], ownner));
                        }
                    }
                }
            }
        }


        while (pms.Count > 0)
        {
            PlaceMethod pm;
            int         rand;
            rand = (int)Random.Range(0, pms.Count);
            pm   = pms[rand];
            if (pm.isValid(lcb))
            {
                return(pm);
            }
            else
            {
                pms.Remove(pm);
            }
        }

        Debug.Log("不可能啊!");
        return(null);
    }
Ejemplo n.º 9
0
        public static bool tryPlaceChessToGameBoard(LiuheChessBoard board, int xx, int yy, int dir, LiuhePlayer lp)
        {
            GridValidState gvs = getGridValidState(board, xx, yy);

            if (gvs != GridValidState.VOID)
            {
                LiuheLogger.Log(gvs);
                return(false);
            }

            int ss = board.places.Count;

            if (ss > 2)
            {
                Debug.Log("严重问题!! 过去存储超过限额!");
            }

            if (ss == 1)
            {
                PlaceMemory pm = board.places[0];
                if (pm.placeOwnner == lp._PlayerIndex)
                {
                    Debug.Log("该玩家这回合已经下过了!");
                    return(false);
                }
                if (pm.chessDir == dir)
                {
                    Debug.Log("这个方向是禁手方向!");
                    return(false);
                }
            }
            else if (ss == 2)
            {
                PlaceMemory pm0 = board.places[0];
                PlaceMemory pm1 = board.places[1];
                if (pm1.placeOwnner == lp._PlayerIndex)
                {
                    Debug.Log("该玩家这回合已经下过了!");
                    return(false);
                }
                if (pm0.chessDir == dir || pm1.chessDir == dir)
                {
                    Debug.Log("这个方向是禁手方向!");
                    return(false);
                }
            }


            int idm = board.addNewChess(xx, yy, dir, lp._PlayerIndex);

            if (idm < 0)
            {
                Debug.Log("此位置存在错误!");
                return(false);
            }

            GameBoardCalculateItself(board);

            if (board.findChessByIdnum(idm).health <= 0)
            {
                Debug.Log("下在此处生命值会不够!");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 10
0
        public static void GameBoardCalculateItself(LiuheChessBoard lcb)
        {
            List <LiuheChess> lcs = lcb.chesses;


            //清空buff列表
            foreach (LiuheChess l in lcs)
            {
                l.buffers = new List <BufferEffect>();
            }

            List <RingInfo> rfs;

            rfs = new List <RingInfo>();

            foreach (LiuheChess l in lcs)
            {
                if (hasChessThisInList(rfs, l))
                {
                    continue;
                }
                else
                {
                    checkRing(lcb, l.identityNumber, rfs);
                }
            }

            foreach (RingInfo r in rfs)
            {
                r.chess.buffers.Add(new BufferEffect()
                                    .set(r.chess.identityNumber,
                                         r.chess.identityNumber,
                                         BufferType.RING, r.level, 0, 0));
            }


            //重新获得buff列表(Basic,Thron,Kiss,Ring)
            foreach (LiuheChess l in lcs)
            {
                bool       hasFront = false;
                bool       hasBack  = false;
                LiuheChess fc       = null;
                LiuheChess bc       = null;

                //获取前方棋子
                int[] pos = lcb.getPointPos(l.x, l.y, l.dir);

                int bh;

                bh = 3;

                GridValidState gvs = Rules.getGridValidState(lcb, pos[0], pos[1]);

                if (gvs == GridValidState.USING)
                {
                    hasFront = true;
                    fc       = lcb.findChessByPosition(pos[0], pos[1]);
                    if (fc != null)
                    {
                        if (fc.ownner != l.ownner)
                        {
                            bh--;
                            //Debug.Log("here");
                        }
                    }
                    else
                    {
                        Debug.Log("指向的格子上应该有棋子却找不到!!");
                        return;
                    }
                }
                else
                {
                    hasFront = false;
                }


                //获取后方棋子
                int[] pos2 = lcb.getPointPos(l.x, l.y, (l.dir + 3) % 6);

                gvs = Rules.getGridValidState(lcb, pos2[0], pos2[1]);

                if (gvs == GridValidState.USING)
                {
                    hasBack = true;
                    bc      = lcb.findChessByPosition(pos2[0], pos2[1]);
                    if (bc != null)
                    {
                        if (bc.ownner != l.ownner)
                        {
                            bh--;
                            //Debug.Log("here");
                        }
                    }
                    else
                    {
                        Debug.Log("指向的格子上应该有棋子却找不到!!");
                        return;
                    }
                }
                else
                {
                    hasBack = false;
                }

                //增加基础buff
                l.buffers.Add(new BufferEffect().set(l.identityNumber, l.identityNumber, BufferType.BASIC, bh, 1, 0));


                //如果后背的是己方,并且方向和自己正好相反(背对背),增加双三的buff
                if (hasBack && bc.ownner == l.ownner && (l.dir + 3) % 6 == bc.dir)
                {
                    l.buffers.Add(new BufferEffect().set(bc.identityNumber, l.identityNumber, BufferType.THRON, 0, 3, 0));
                }

                //如果前面是友方,而且方向正好相对(面对面),加上吸收力增值
                if (hasFront && fc.ownner == l.ownner && (l.dir + 3) % 6 == fc.dir)
                {
                    l.buffers.Add(new BufferEffect().set(fc.identityNumber, l.identityNumber, BufferType.ABSORBER, 0, 0, 2));
                    //如果有吸收,而且后方是敌人,就加一个吸收的debuff
                    if (hasBack && bc.ownner != l.ownner)
                    {
                        bc.buffers.Add(new BufferEffect().set(l.identityNumber, bc.identityNumber, BufferType.ABSORBEE, 0, -2, 0));
                    }
                }


                if (hasFront)
                {
                    if (fc.ownner == l.ownner)
                    {
                        fc.buffers.Add(new BufferEffect().set(l.identityNumber, fc.identityNumber, BufferType.SUPPORT, 0, 0, 0));
                    }
                    else
                    {
                        fc.buffers.Add(new BufferEffect().set(l.identityNumber, fc.identityNumber, BufferType.ATTACK, 0, 0, 0));
                    }
                }


                BufferEffect be = l.getSuchBuff(BufferType.BASIC);

                if (be != null)
                {
                    l.health = be.healthChange;
                    l.absorb = 0;
                    l.attack = be.attackChange;
                }
                else
                {
                    Debug.Log("严重错误,没有基础buff");
                }

                be = l.getSuchBuff(BufferType.THRON);
                if (be != null)
                {
                    l.attack = be.attackChange;
                }

                be = l.getSuchBuff(BufferType.ABSORBER);
                if (be != null)
                {
                    l.absorb = be.absorbChange;
                }

                be = l.getSuchBuff(BufferType.RING);
                if (be != null)
                {
                    l.health += be.healthChange;
                }

                //此处不能更新被吸收的buff,因为这个时候可能没加上
            }

            //减少基本攻击力,最小到0
            foreach (LiuheChess l in lcs)
            {
                BufferEffect be = l.getSuchBuff(BufferType.ABSORBEE);
                if (be != null)
                {
                    l.attack += be.attackChange;
                    if (l.attack < 0)
                    {
                        l.attack = 0;
                    }
                }
            }


            //更新互助列表
            foreach (LiuheChess l in lcs)
            {
                List <BufferEffect> bes = l.getSuchBuffAll(BufferType.SUPPORT);
                foreach (BufferEffect bfe in bes)
                {
                    LiuheChess nc = lcb.findChessByIdnum(bfe.perfromChess);
                    if (nc == null)
                    {
                        Debug.Log("重大错误!! 找不到本能找到的棋子!");
                        return;
                    }
                    bfe.attackChange = nc.attack;
                    bfe.absorbChange = 0;
                    bfe.healthChange = 1;
                }
            }

            //更新攻击列表,直接减少生命
            foreach (LiuheChess l in lcs)
            {
                List <BufferEffect> bes = l.getSuchBuffAll(BufferType.SUPPORT);
                foreach (BufferEffect bfe in bes)
                {
                    l.attack += bfe.attackChange;
                    l.health += bfe.healthChange;
                }
            }

            foreach (LiuheChess l in lcs)
            {
                List <BufferEffect> bes = l.getSuchBuffAll(BufferType.ATTACK);
                foreach (BufferEffect bfe in bes)
                {
                    LiuheChess nc = lcb.findChessByIdnum(bfe.perfromChess);
                    if (nc == null)
                    {
                        Debug.Log("重大错误!! 找不到本能找到的棋子!");
                        return;
                    }
                    l.health -= nc.attack;
                }
            }

            lcb.attacks = new List <SpecialChessLink>();
            lcb.skills  = new List <SpecialChessLink>();
            lcb.deads   = new List <SpecialChessLink>();

            List <SpecialChessLink> tscl = new List <SpecialChessLink>();

            foreach (LiuheChess lc in lcb.chesses)
            {
                if (lc.health <= 0)
                {
                    lcb.deads.Add(new SpecialChessLink(SpecialLinkType.DEAD, lc.identityNumber, lc.identityNumber));
                    List <BufferEffect> bes = lc.buffers;
                    foreach (BufferEffect be in bes)
                    {
                        if (be.bfType == BufferType.ATTACK)
                        {
                            tscl.Add(new SpecialChessLink(SpecialLinkType.ATTACK, be.perfromChess, be.acceptChess));
                        }
                    }
                }
            }

            foreach (SpecialChessLink scl in tscl)
            {
                if (!lcb.deads.Contains(scl))
                {
                    lcb.attacks.Add(scl);
                }
            }
        }