コード例 #1
0
ファイル: Board.cs プロジェクト: gwalton2/CS155
        public void IsCheckMate(Game.PieceColor color)
        {
            ulong allmoves = 0;

            for (int i = 0; i < 64; i++)
            {
                char piece = _myboard[i / 8, i % 8];
                if (piece.Equals('-'))
                {
                    continue;
                }
                else if (char.IsUpper(piece) && color == Game.PieceColor.White)
                {
                    allmoves |= GetMoves(i / 8, i % 8);
                }
                else if (char.IsLower(piece) && color == Game.PieceColor.Black)
                {
                    allmoves |= GetMoves(i / 8, i % 8);
                }
            }

            if (allmoves == 0)
            {
                game.GameOver = true;
            }
        }
コード例 #2
0
 public AI(ChessBoard chessboard, Board board, Game game, int depth, Game.PieceColor mycolor)
 {
     this.chessboard = chessboard;
     this.board      = board;
     this.game       = game;
     this.depth      = depth;
     this.mycolor    = mycolor;
     GameOver        = false;
 }
コード例 #3
0
 private bool Win(Game.PieceColor color)
 {
     if (color == Game.PieceColor.White)
     {
         return(chessboard.BlackKing == 0);
     }
     else
     {
         return(chessboard.WhiteKing == 0);
     }
 }
コード例 #4
0
ファイル: Board.cs プロジェクト: gwalton2/CS155
        public bool InCheck(Game.PieceColor color)
        {
            ulong attacks;
            ulong king;

            if (color == Game.PieceColor.White)
            {
                king    = chessboard.WhiteKing;
                attacks = Moves.GetAllBlackMoves(chessboard);
            }
            else
            {
                king    = chessboard.BlackKing;
                attacks = Moves.GetAllWhiteMoves(chessboard);
            }
            return((king & attacks) != 0);
        }
コード例 #5
0
        private List <int[]> GetQueenMoves(List <int> indexes, Game.PieceColor color)
        {
            List <int[]> moves = new List <int[]>();

            foreach (int ind in indexes)
            {
                int rank = ind / 8;
                int file = ind % 8;

                if (color == Game.PieceColor.White)
                {
                    List <int[]> thesemoves = ConvertMove(board.ClipCheck(Moves.GetQueenMoves(rank, file, chessboard.AllPieces, chessboard.AllWhite), ind), ind);
                    moves.AddRange(thesemoves);
                }
                else
                {
                    List <int[]> thesemoves = ConvertMove(board.ClipCheck(Moves.GetQueenMoves(rank, file, chessboard.AllPieces, chessboard.AllBlack), ind), ind);
                    moves.AddRange(thesemoves);
                }
            }
            return(moves);
        }
コード例 #6
0
ファイル: Board.cs プロジェクト: gwalton2/CS155
        public bool IsCheck(ulong move, int selected, Game.PieceColor color)
        {
            List <int> index = Moves.ConvertBitboard(move);

            MoveBitBoard(selected, index[0]);

            ulong attacks;
            ulong king;

            if (color == Game.PieceColor.White)
            {
                king    = chessboard.WhiteKing;
                attacks = Moves.GetAllBlackMoves(chessboard);
            }
            else
            {
                king    = chessboard.BlackKing;
                attacks = Moves.GetAllWhiteMoves(chessboard);
            }

            UndoLastMoveBitBoard();
            return((king & attacks) != 0);
        }
コード例 #7
0
        private List <int[]> GetKingMoves(List <int> indexes, Game.PieceColor color)
        {
            List <int[]> moves = new List <int[]>();

            foreach (int ind in indexes)
            {
                int rank = ind / 8;
                int file = ind % 8;

                if (color == Game.PieceColor.White)
                {
                    ulong        wkmoves    = Moves.GetKingMoves(rank, file, chessboard.AllWhite) | Moves.GetWhiteCastleMoves(rank, file, chessboard.AllWhite, board, chessboard);
                    List <int[]> thesemoves = ConvertMove(board.ClipCheck(wkmoves, ind), ind);
                    moves.AddRange(thesemoves);
                }
                else
                {
                    ulong        bkmoves    = Moves.GetKingMoves(rank, file, chessboard.AllBlack) | Moves.GetBlackCastleMoves(rank, file, chessboard.AllBlack, board, chessboard);
                    List <int[]> thesemoves = ConvertMove(board.ClipCheck(bkmoves, ind), ind);
                    moves.AddRange(thesemoves);
                }
            }
            return(moves);
        }