Beispiel #1
0
        /// <summary>
        /// Lấy toàn bộ di chuyển có thể trong bàn cờ
        /// </summary>
        /// <param name="board"></param>
        /// <param name="side"></param>
        /// <returns></returns>
        List <Move> GetAllMove(Board board, ChessPieceSide?side = null)
        {
            //neu side=null co nghia la get toan bo quan co
            //nguoc lai chi get ben side thoi ne.

            List <Move> listmove = new List <Move>();

            //int count = 0;
            //string str = "";
            if (side != null)
            {
                foreach (Cell cell in board.listCell)
                {
                    ChessPieces piece = cell.GetChessPieces();
                    //neu tai vi tri cell nay co quan co
                    // va la quan co dang can lay thi lay cai move cua no
                    if (piece != null && piece.side == side)
                    {
                        //count++;
                        listmove.AddRange(piece.getLegalMoves(board));
                        //str = str + "   " +piece.chessPieceType.chessPieceName+"  "+piece.side+"   ";
                    }
                }
            }
            // MessageBox.Show("so quan co: " + count+": "+str);
            //MessageBox.Show(board.listCell.Count()+"");
            return(listmove);
        }
Beispiel #2
0
        /// <summary>
        /// kiểm tra nguy hiểm của nước cờ tới vua của đối phương để đưa ra cảnh báo
        /// </summary>
        void checkDangerousForTheKing(Board board)
        {
            List <Move> listMoveFuture = new List <Move>();
            ChessPieces p = (ChessPieces)board.GetCell(this.destination).GetChessPieces();

            listMoveFuture = p.getLegalMoves(board);

            King king = board.GetNextPlayer().king;

            foreach (Move m in listMoveFuture)
            {
                if (m.destination == king.chessPiecePosition)
                {
                    // MessageBox.Show("Chiếu tướng. hahahaa !!!");
                    this.chieuTuong = true;
                    break;
                }
            }
        }