Example #1
0
        public static ulong GetBlackCastleMoves(int rank, int file, ulong piececolor, Board board, ChessBoard chessboard)
        {
            ulong ks    = 0;
            ulong qs    = 0;
            int   index = rank * 8 + file;
            ulong piece = (ulong)0x1 << index;

            if (board.InCheck(Game.PieceColor.Black))
            {
                return(0);
            }

            if (chessboard.BlackKingSide && ((piece << 1) & ~piececolor) != 0 && !board.IsCheck(piece << 1, index, Game.PieceColor.Black))
            {
                ks = piece << 2;
            }
            if (chessboard.BlackQueenSide && ((piece >> 1) & ~piececolor) != 0 && ((piece >> 3) & ~piececolor) != 0 && !board.IsCheck(piece >> 1, index, Game.PieceColor.Black))
            {
                qs = piece >> 2;
            }

            ulong castles = ks | qs;

            return(castles & ~piececolor);
        }
Example #2
0
        private int StaticScore()
        {
            if (Win(mycolor))
            {
                GameOver = true;
                return(WINSCORE);
            }
            if (Win(game.OppositeColor(mycolor)))
            {
                GameOver = true;
                return(-WINSCORE);
            }

            int score = 0;
            List <List <int> > boardList   = ConvertBoard();
            List <int[, ]>     scorecharts = new List <int[, ]> {
                whitepawnscore, whiteknightscore, whitebishopscore, whiterookscore, whitekingmiddlescore, whitequeenscore,
                blackpawnscore, blackknightscore, blackbishopscore, blackrookscore, blackkingmiddlescore, blackqueenscore
            };

            for (int i = 0; i < 12; i++)
            {
                if (i == 4 && IsEndGame())
                {
                    score += StaticPieceScore(whitekingendscore, boardList[i]);
                }
                else if (i == 10 && IsEndGame())
                {
                    score += StaticPieceScore(blackkingendscore, boardList[i]);
                }
                else
                {
                    score += StaticPieceScore(scorecharts[i], boardList[i]);
                }
            }

            if (board.InCheck(mycolor))
            {
                score -= 100;
            }
            if (board.InCheck(game.OppositeColor(mycolor)))
            {
                score += 100;
            }

            return(score);
        }