Beispiel #1
0
        public bool moveChess(ChessObj co)
        {
            Debug.Log("移动了棋子,棋子是:");
            LiuheLogger.Log(co);

            bool result = Rules.Rules.moveChessInBoard(_GameBoard.findChessByIdnum(co._ChessIdentityNumber), _GameBoard);

            return(result);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #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);
            }
        }
Beispiel #5
0
        public static LiuheChessBoard washChessBoard(LiuheChessBoard lcb)
        {
            foreach (SpecialChessLink item in lcb.deads)
            {
                if (item._Type == SpecialLinkType.DEAD)
                {
                    LiuheChess lc = lcb.findChessByIdnum(item._From_Idm);
                    lcb.chesses.Remove(lc);
                }
            }
            GameBoardCalculateItself(lcb);


            return(lcb);
        }
Beispiel #6
0
    public LiuheChessBoard isValid(LiuheChessBoard lcb)
    {
        int idm = lcb.addNewChessUnSafe(this.x, this.y, this.direction, this.ownner);

        Rules.GameBoardCalculateItself(lcb);

        LiuheChess lc = lcb.findChessByIdnum(idm);

        Assert.IsNotNull(lc, "找到了空棋子,ai下子有问题");

        if (lc.health <= 0)
        {
            return(null);
        }
        else
        {
            return(lcb);
        }
    }
Beispiel #7
0
        public bool getTryMoveBoard(ChessObj co)
        {
            LiuheChessBoard lcb = Rules.Rules.getTryEndBoard(co, _GameBoard);

            if (lcb != null)
            {
                int h = lcb.findChessByIdnum(co._ChessIdentityNumber).health;
                Debug.Log(h);
                if (h <= 0)
                {
                    return(false);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #8
0
        private static void checkRing(LiuheChessBoard boardRef, int idm, List <RingInfo> rfs)
        {
            LiuheChess l = boardRef.findChessByIdnum(idm);

            if (l == null)
            {
                Debug.Log("严重错误! 找不到的开始值!");
                return;
            }

            LiuheChess fc = boardRef.findChessInDir(l.x, l.y, l.dir);

            //l指向的不为空,fc是己方
            if (fc != null && fc.ownner == l.ownner)
            {
                getNextLength(fc, l, boardRef, 0, rfs);
            }
            return;
        }
Beispiel #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);
        }
Beispiel #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);
                }
            }
        }
Beispiel #11
0
    public void endTurn()
    {
        if (!_Manager.ifThisPlayerLocal())
        {
            return;
        }

        switch (_RoundState)
        {
        case DisplayState.HAS_NOT_PLACE_CHESS:
            //有棋子
            if (_TempChess != null)
            {
                LiuheChessBoard lcb = _Manager.tryToPlace(_TempChess.x, _TempChess.y, _TempChess._Direction);
                //落子成功
                if (lcb != null)
                {
                    //如果生命值小于等于零
                    if (_TempChess._Health <= 0)
                    {
                        _ChessLogTransform.GetComponent <Animator>().SetTrigger("atten");
                        Destroy(_TempChess.gameObject);
                        _TempChess  = null;
                        _RoundState = DisplayState.PLACE_CHESS_WRONG;
                    }
                    //如果生命值大于零
                    else
                    {
                        //如果可以下棋,则下棋一个
                        _ChessList.Add(_TempChess);
                        _Manager.placeChess(_Manager._Players[_Manager._PlayerNow], _TempChess.x, _TempChess.y, _TempChess._Direction);
                        _TempChess._GridOccupy.setLock();
                        _TempChess = null;
                        //状态转为下过了棋子,再一次调用这个函数
                        _RoundState = DisplayState.HAS_PLACE_CHESS;
                        endTurn();
                    }
                }
                //落子失败
                else
                {
                    _ChessLogTransform.GetComponent <Animator>().SetTrigger("atten");
                    Destroy(_TempChess.gameObject);
                    _TempChess  = null;
                    _RoundState = DisplayState.PLACE_CHESS_WRONG;
                }
            }
            //没有棋子
            else
            {
                //状态转为什么也不干
                _RoundState = DisplayState.DO_NOTHING;
                //告知将结束回合
                _ChessLogTransform.DOMove(_ChessLogStart.position, 0.5f);
                _ChessLog2Transform.DOMove(_ChessLogStart.position, 0.5f);
                _ChessLog3Transform.DOMove(_ChessLogEnd.position, 0.5f);
            }

            break;

        case DisplayState.HAS_PLACE_CHESS:
            //判断下子之后需不需要特殊处理
            if (_Manager._GameBoard.deads.Count > 0)
            {
                //如果有棋子死亡,则转到移动棋子模式,再一次调用这个函数
                _RoundState = DisplayState.MOVE_CHESS;
                endTurn();
            }
            else
            {
                //如果没有棋子死亡,则自动进入下一回合
                //状态转为结束回合,再一次调用这个函数
                _RoundState = DisplayState.ENDTURN;
                endTurn();
            }
            break;

        case DisplayState.PLACE_CHESS_WRONG:
            if (_TempChess != null)
            {
                _RoundState = DisplayState.HAS_NOT_PLACE_CHESS;
                endTurn();
                break;
            }

            //状态转为什么也不干
            _RoundState = DisplayState.DO_NOTHING;
            //告知将结束回合
            _ChessLogTransform.DOMove(_ChessLogStart.position, 0.5f);
            _ChessLog2Transform.DOMove(_ChessLogStart.position, 0.5f);
            _ChessLog3Transform.DOMove(_ChessLogEnd.position, 0.5f);
            break;

        case DisplayState.MOVE_CHESS:       //找出可以移动的棋子
            //移动棋子代码不在这里,这里是设置移动棋子状态的地方

            //杀掉不需要的棋子
            foreach (ChessObj co in _ChessList)
            {
                if (co._Health <= 0)
                {
                    co.kill();
                }
            }

            //把所有的棋子都设为不可移动
            foreach (ChessObj item in _ChessList)
            {
                item.setNotMove();
            }

            //获得尝试结束的结果
            List <SpecialChessLink> scl = _Manager.tryEndAction();
            _HasMoveChessList = new List <ChessObj>();

            //当返回为空、或者没有可当前攻击的棋子时,结束回合;反之,进行移动棋子
            if (scl != null)
            {
                List <ChessObj> cos = new List <ChessObj>();
                //查看所有能攻击的棋子
                foreach (SpecialChessLink item in scl)
                {
                    ChessObj c = findChessObj(item._From_Idm);
                    //当可以攻击的棋子存在并且是当前回合的玩家时
                    if (c != null && c._Ownner == _Manager._PlayerNow)
                    {
                        ChessObj atc = findChessObj(item._To_Idm);
                        if (atc == null)
                        {
                            Debug.Log(item._To_Idm);
                            LiuheLogger.Log(_Manager._GameBoard.findChessByIdnum(c._ChessIdentityNumber));
                            Debug.Log("严重错误!");
                            LiuheLogger.Log(scl);
                        }
                        //设置这个棋子可以移动
                        c.setForward(atc.transform.position, atc, item._To_Idm);
                        cos.Add(c);
                    }
                }

                if (cos.Count > 0)
                {
                    //当有足够的可攻击棋子存在时,去除所有的死亡棋子
                    _Manager.washOut();
                    //状态转换为等待棋子移动
                    _RoundState = DisplayState.HAS_MOVED_CHESS;
                    clickEmypt();
                }
                else
                {
                    //当没有足够可攻击棋子存在时,也就是结束回合
                    _Manager.washOut();
                    _RoundState = DisplayState.ENDTURN;
                    endTurn();
                }
            }
            //当返回为空时,也就是没有合理棋子指着这里
            else
            {
                //结束回合
                _Manager.washOut();
                _RoundState = DisplayState.ENDTURN;
                endTurn();
            }
            break;

        case DisplayState.HAS_MOVED_CHESS:      //移动的棋子移动之后(或者没有移动之后)
        {
            //这里都是已经决定好移动结果后进来的地方
            //也就是移动的代码在别处,这里只提交结果
            if (_HasMoveChessList != null && _HasMoveChessList.Count > 0)
            {
                //判断是否真的可以
                bool            allright = true;
                LiuheChessBoard lcb      = _Manager._GameBoard.getCopy();
                lcb = _Manager.getTryMovesMultiChessBoard(_HasMoveChessList, lcb);
                List <ChessObj> dcoes = new List <ChessObj>();
                foreach (ChessObj co in _HasMoveChessList)
                {
                    if (lcb.findChessByIdnum(co._ChessIdentityNumber).health <= 0)
                    {
                        co.moveToOld();
                        dcoes.Add(co);
                        allright = false;
                        //Debug.Log("应该回去");
                    }
                }

                if (allright)
                {
                    //删除所有死掉的棋子
                    List <ChessObj> dd = new List <ChessObj>();
                    foreach (ChessObj co in _ChessList)
                    {
                        if (!co._IsAlive)
                        {
                            dd.Add(co);
                        }
                    }

                    foreach (ChessObj co in dd)
                    {
                        _ChessList.Remove(co);
                        Destroy(co.gameObject);
                    }

                    _Manager.washOut();


                    //正式移动
                    foreach (ChessObj co in _HasMoveChessList)
                    {
                        _Manager.moveChess(co);
                    }
                    _RoundState = DisplayState.MOVE_CHESS;
                    updateBoard();
                    _HasMoveChessList = new List <ChessObj>();
                    endTurn();
                }
                else
                {
                    foreach (ChessObj c in dcoes)
                    {
                        _HasMoveChessList.Remove(c);
                    }
                }



                #region old

                /*
                 * if (_Manager.getTryMoveBoard(_HasMovedChess))
                 * {
                 *  //删除所有死掉的棋子
                 *  List<ChessObj> dd = new List<ChessObj>();
                 *  foreach (ChessObj co in _ChessList)
                 *  {
                 *      if (!co._IsAlive)
                 *      {
                 *          dd.Add(co);
                 *      }
                 *  }
                 *
                 *  foreach (ChessObj co in dd)
                 *  {
                 *      _ChessList.Remove(co);
                 *      Destroy(co.gameObject);
                 *  }
                 *
                 *  _Manager.washOut();
                 *
                 *
                 *  //正式移动
                 *  _Manager.moveChess(_HasMovedChess);
                 *  _RoundState = DisplayState.MOVE_CHESS;
                 *  updateBoard();
                 *  _HasMovedChess = null;
                 *  endTurn();
                 * }
                 * else
                 * {
                 *  _HasMovedChess.moveToOld();
                 *  _HasMovedChess = null;
                 *  updateBoard();
                 *  Debug.Log("应该回去");
                 * }
                 */
                #endregion
            }
            else
            {
                //删除所有死掉的棋子
                List <ChessObj> dd = new List <ChessObj>();
                foreach (ChessObj co in _ChessList)
                {
                    if (!co._IsAlive)
                    {
                        dd.Add(co);
                    }
                }

                foreach (ChessObj co in dd)
                {
                    _ChessList.Remove(co);
                    Destroy(co.gameObject);
                }

                _RoundState = DisplayState.MOVE_CHESS;
                clickEmypt();
                endTurn();
            }
        }
        break;

        case DisplayState.DO_NOTHING:
            if (_TempChess != null)
            {
                _RoundState = DisplayState.HAS_NOT_PLACE_CHESS;
                endTurn();
                break;
            }

            //状态转为结束游戏,然后再一次调用
            _RoundState = DisplayState.ENDTURN;
            endTurn();
            break;

        case DisplayState.ENDTURN:
            //真正结束回合
            _Manager.endTurn();
            //切换新的指示牌出来
            if (_Manager._Players[_Manager._PlayerNow]._Type == PLAYER_TYPE.LOCAL)
            {
                tintLog2();
                _ChessLog3Transform.DOMove(_ChessLogStart.position, 0.5f);
                _ChessLog2Transform.DOMove(_ChessLogEnd.position, 0.5f);
            }
            //删除所有死掉的棋子
            List <ChessObj> dco = new List <ChessObj>();
            foreach (ChessObj co in _ChessList)
            {
                if (!co._IsAlive)
                {
                    dco.Add(co);
                }
            }

            foreach (ChessObj co in dco)
            {
                _ChessList.Remove(co);
                Destroy(co.gameObject);
            }
            relinkGrid();
            _RoundState = DisplayState.HAS_NOT_PLACE_CHESS;
            break;

        default:
            break;
        }
    }