Beispiel #1
0
 public Chess(Chess c)
 {
     this.x = c.x;
     this.y = c.y;
     this.isMine = c.isMine;
     this.oldX = c.oldX;
     this.oldY = c.oldY;
     this.oldMine = c.oldMine;
 }
Beispiel #2
0
        public void reset()
        {
            short i = 0;
            for (i = 0; i < 5; ++i)
            {
                chesses[i] = new Chess(2, 2, false);//首先反置,并置错位,使得绘图可以检测出
                chesses[i + 5] = new Chess(2, 2, true);

                changeChessOwner(i);//开始翻转
                changeChessOwner(i + 5);
                moveChess(i, i, 0);//开始移动
                moveChess(i + 5, i, 4);


                for (short k = 0; k < 5; ++k)//全部置零(-1 表示无棋子)
                    locations[i][k] = -1;
            }
            for (i = 0; i < 5; ++i)//将0和4排填上棋子
            {
                locations[i][0] = i;
                locations[i][4] = i + 5;
            }
            selected = -1;
            chessUp = -1;
        }
Beispiel #3
0
        public int[] getCanGo(int index)//此函数尽量少用,在规则判断可以用
        {
            List<int> list = new List<int>();
            if (index > -1 && index < 10)
            {
                Chess selectedChess = chesses[index];
                int dirCount = selectedChess.x % 2 == selectedChess.y % 2 ? 8 : 4;//一奇一偶的只可走上下左右

                bool revese = Global.client.whoseTurn != GameState.MY_TURN;
                //对方的回合就要判断我方棋子数量
                int countEn = getCount(revese);

                for (int i = 0; i < dirCount; ++i)
                {
                    Chess newC = new Chess(selectedChess);
                    for (int step = 1; step < 5; ++step)
                    {
                        newC += directions[i];
                        if (newC.outBoard() || locations[newC.x][newC.y] != -1)//出界了 || 已经有棋子了
                            break;
                        else
                        {
                            bool canGoIreg = true;
                            if (countEn < 4)
                            {
                                ChessBoard newBoard = this.copyBoard(revese);//复制当前棋盘
                                newBoard.moveChess(index, newC.x, newC.y);//假走

                                switch (countEn)
                                {
                                    case 3://不可同时挑与夹
                                        newBoard.check3(index);
                                        if (newBoard.getCount(false) == 0)
                                            canGoIreg = false;
                                        break;
                                    case 2://不可挑
                                        int[] tiaoRes = newBoard.tiao(index);
                                        if (tiaoRes.Length == 2)
                                            canGoIreg = false;
                                        break;
                                    case 1://不可夹
                                        int[] jaRes = newBoard.ja(index);
                                        if (jaRes.Length == 1)
                                            canGoIreg = false;
                                        break;
                                }
                            }
                            if (canGoIreg)
                                list.Add(newC.y * 5 + newC.x);
                        }
                    }
                }
            }
            return list.ToArray();
        }