Example #1
0
        public unsafe void TestManagedBoardToNativeInit()
        {
            var board = new Chess.Base.Board(true);
            var b = Helpers.ManagedBoardToNative(board);

            var b2 = Board.Create();
            Board.Init(b2, 1);

            Assert.AreEqual(b2->Hash, b->Hash);
        }
Example #2
0
        public unsafe void TestManagedBoardToNativeInit()
        {
            var board = new Chess.Base.Board(true);
            var b     = Helpers.ManagedBoardToNative(board);

            var b2 = Board.Create();

            Board.Init(b2, 1);

            Assert.AreEqual(b2->Hash, b->Hash);
        }
Example #3
0
        /// <summary>
        /// Returns all possible attacks for a knight from the given square.
        /// Uses the (slow) C# move generator to create the bitboard moves.
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        static ulong GetMoves(int index)
        {
            var b = new Chess.Base.Board();
            b.State[index] = Chess.Base.Colors.Val(Chess.Base.Piece.Knight, Chess.Base.Color.White);
            var moves = Chess.Base.Moves.GetMoves(b, index);

            ulong output = 0;
            foreach (var move in moves)
                Bitboard.SetRef(ref output, move);

            return output;
        }
Example #4
0
        public static unsafe BoardStruct *ManagedBoardToNative(Chess.Base.Board board)
        {
            var b = Board.Create();

            b->Castle = 0;

            if (board.CastlingRights.Contains(Base.Castling.KingsideBlack))
            {
                b->Castle |= Board.CASTLE_BK;
            }
            if (board.CastlingRights.Contains(Base.Castling.QueensideBlack))
            {
                b->Castle |= Board.CASTLE_BQ;
            }
            if (board.CastlingRights.Contains(Base.Castling.KingsideWhite))
            {
                b->Castle |= Board.CASTLE_WK;
            }
            if (board.CastlingRights.Contains(Base.Castling.QueensideWhite))
            {
                b->Castle |= Board.CASTLE_WQ;
            }

            b->EnPassantTile      = (byte)board.EnPassantTile;
            b->FiftyMoveRulePlies = (byte)board.FiftyMoveRulePlies;
            b->PlayerTurn         = (byte)board.PlayerTurn;

            b->CurrentMove = (board.MoveCount - 1) * 2;
            if (b->PlayerTurn == Board.COLOR_BLACK)
            {
                b->CurrentMove++;
            }

            for (int i = 0; i < 64; i++)
            {
                Chess.Base.Color color = board.GetColor(i);
                Chess.Base.Piece piece = board.GetPiece(i);

                if (color == 0 || piece == 0)
                {
                    continue;
                }

                Board.SetPiece(b, i, (int)piece, (int)color);
            }

            //b->AttacksBlack = Board.AttackMap(b, Board.COLOR_BLACK);
            //b->AttacksWhite = Board.AttackMap(b, Board.COLOR_WHITE);
            b->Hash = Zobrist.Calculate(b);
            //b->MoveHistory // N/A
            return(b);
        }
Example #5
0
        /// <summary>
        /// Returns all possible attacks for a knight from the given square.
        /// Uses the (slow) C# move generator to create the bitboard moves.
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        static ulong GetMoves(int index)
        {
            var b = new Chess.Base.Board();

            b.State[index] = Chess.Base.Colors.Val(Chess.Base.Piece.Knight, Chess.Base.Color.White);
            var moves = Chess.Base.Moves.GetMoves(b, index);

            ulong output = 0;

            foreach (var move in moves)
            {
                Bitboard.SetRef(ref output, move);
            }

            return(output);
        }
Example #6
0
        public void TestBishopMovesAll()
        {
            for (int i = 0; i < 64; i++)
            {
                var b = new Chess.Base.Board(false);
                b.State[i] = Chess.Base.Colors.Val(Chess.Base.Piece.Bishop, Chess.Base.Color.White);
                var movesBasic = Chess.Base.Moves.GetMoves(b, i);
                movesBasic = movesBasic.OrderBy(x => x).ToArray();

                var movesFast = Bishop.Read(i, 0);
                var list = Bitboard.Bitboard_BitList(movesFast);
                list = list.OrderBy(x => x).ToArray();

                Assert.AreEqual(movesBasic.Length, list.Length);
                for (int j = 0; j < movesBasic.Length; j++)
                    Assert.AreEqual((int)movesBasic[j], (int)list[j]);
            }
        }
Example #7
0
        static unsafe ulong GetMoves(int index)
        {
            // I use the old move generator to create the bitboard moves

            var b = new Chess.Base.Board();
            b.CanCastleKBlack = false;
            b.CanCastleKWhite = false;
            b.CanCastleQBlack = false;
            b.CanCastleQWhite = false;
            b.State[index] = Chess.Base.Colors.Val(Chess.Base.Piece.King, Chess.Base.Color.White);
            var moves = Chess.Base.Moves.GetMoves(b, index);

            ulong output = 0;
            foreach (var move in moves)
                Bitboard.SetRef(ref output, move);

            return output;
        }
Example #8
0
        public void TestBishopMovesAll()
        {
            for (int i = 0; i < 64; i++)
            {
                var b = new Chess.Base.Board(false);
                b.State[i] = Chess.Base.Colors.Val(Chess.Base.Piece.Bishop, Chess.Base.Color.White);
                var movesBasic = Chess.Base.Moves.GetMoves(b, i);
                movesBasic = movesBasic.OrderBy(x => x).ToArray();

                var movesFast = Bishop.Read(i, 0);
                var list      = Bitboard.Bitboard_BitList(movesFast);
                list = list.OrderBy(x => x).ToArray();

                Assert.AreEqual(movesBasic.Length, list.Length);
                for (int j = 0; j < movesBasic.Length; j++)
                {
                    Assert.AreEqual((int)movesBasic[j], (int)list[j]);
                }
            }
        }
Example #9
0
        static unsafe ulong GetMoves(int index)
        {
            // I use the old move generator to create the bitboard moves

            var b = new Chess.Base.Board();

            b.CanCastleKBlack = false;
            b.CanCastleKWhite = false;
            b.CanCastleQBlack = false;
            b.CanCastleQWhite = false;
            b.State[index]    = Chess.Base.Colors.Val(Chess.Base.Piece.King, Chess.Base.Color.White);
            var moves = Chess.Base.Moves.GetMoves(b, index);

            ulong output = 0;

            foreach (var move in moves)
            {
                Bitboard.SetRef(ref output, move);
            }

            return(output);
        }