Ejemplo n.º 1
0
        public unsafe void TestGetCastlingSingleRooks()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Board.SetPiece(b, 4, Board.PIECE_KING, Board.COLOR_WHITE);
            Board.SetPiece(b, 60, Board.PIECE_KING, Board.COLOR_BLACK);


            Board.SetPiece(b, 0, Board.PIECE_ROOK, Board.COLOR_WHITE);
            var castling = Board.GetCastling(b);

            Assert.AreEqual(Board.CASTLE_WQ, castling);
            Board.ClearPiece(b, 0);

            Board.SetPiece(b, 7, Board.PIECE_ROOK, Board.COLOR_WHITE);
            castling = Board.GetCastling(b);
            Assert.AreEqual(Board.CASTLE_WK, castling);
            Board.ClearPiece(b, 7);

            Board.SetPiece(b, 56, Board.PIECE_ROOK, Board.COLOR_BLACK);
            castling = Board.GetCastling(b);
            Assert.AreEqual(Board.CASTLE_BQ, castling);
            Board.ClearPiece(b, 56);

            Board.SetPiece(b, 63, Board.PIECE_ROOK, Board.COLOR_BLACK);
            castling = Board.GetCastling(b);
            Assert.AreEqual(Board.CASTLE_BK, castling);
            Board.ClearPiece(b, 63);
        }
Ejemplo n.º 2
0
        private unsafe void SetupBoard(BoardStruct *b, State state, byte playerTurn)
        {
            b->Boards[0]     = 0;
            b->Boards[1]     = 0;
            b->Boards[2]     = 0;
            b->Boards[3]     = 0;
            b->Boards[4]     = 0;
            b->Boards[5]     = 0;
            b->Boards[6]     = 0;
            b->Boards[7]     = 0;
            b->Castle        = 0;
            b->EnPassantTile = 0;
            b->Hash          = 0;
            Board.SetPiece(b, state.PieceLocation[0], state.Pieces[0] & 0x0F, state.Pieces[0] & 0xF0);
            Board.SetPiece(b, state.PieceLocation[1], state.Pieces[1] & 0x0F, state.Pieces[1] & 0xF0);
            Board.SetPiece(b, state.PieceLocation[2], state.Pieces[2] & 0x0F, state.Pieces[2] & 0xF0);
            Board.SetPiece(b, state.PieceLocation[3], state.Pieces[3] & 0x0F, state.Pieces[3] & 0xF0);
            b->AttacksBlack = Board.AttackMap(b, Board.COLOR_BLACK);
            b->AttacksWhite = Board.AttackMap(b, Board.COLOR_WHITE);

            b->PlayerTurn = playerTurn;
            b->Hash       = b->Hash ^ Zob.Keys[Zobrist.ZOBRIST_SIDE, b->PlayerTurn];

            Assert(b->Hash == state.Hash, "Hashes do not match");
        }
Ejemplo n.º 3
0
        public unsafe void WhiteKingTest1()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            b->Boards[Board.BOARD_KINGS] = Bitboard.Set((b->Boards[Board.BOARD_KINGS]), 4);
            b->Boards[Board.BOARD_WHITE] = Bitboard.Set((b->Boards[Board.BOARD_WHITE]), 4);
            Board.GenerateTileMap(b);

            ulong movesKing = MoveClasses.King.Read(4);

            Assert.AreEqual((ulong)0x3828, movesKing);

            // allow all castling
            b->Castle = Board.CASTLE_BK | Board.CASTLE_BQ | Board.CASTLE_WK | Board.CASTLE_WQ;

            // standard king moves plus castling moves
            ulong moves = Moves.GetMoves(b, 4);

            Assert.AreEqual((ulong)0x386C, moves);

            // disallow castling
            b->Castle = 0;

            // standard king moves plus castling moves
            moves = Moves.GetMoves(b, 4);
            Assert.AreEqual((ulong)0x3828, moves);
        }
Ejemplo n.º 4
0
        /*private bool AreKingsTouching(State s)
         * {
         *      var x1 = s.PieceLocation[0] % 8;
         *      var y1 = s.PieceLocation[0] >> 3;
         *
         *      var x2 = s.PieceLocation[2] % 8;
         *      var y2 = s.PieceLocation[2] >> 3;
         *
         *      return (Math.Abs(x1 - x2) <= 1 && Math.Abs(y1 - y2) <= 1);
         * }*/

        /// <summary>
        /// Gets all moves that a piece can make that will RESULT IN the given position.
        /// All pieces can reverse their own move, so backwards move are the same as forwards
        /// except for pawns, they only move one way.
        /// </summary>
        /// <param name="b"></param>
        /// <param name="playerColor"></param>
        /// <returns></returns>
        private unsafe byte[][] GetMovesReverse(BoardStruct *b, byte playerColor)
        {
            var moves = new List <byte[]>();

            byte[] locations = null;

            if (playerColor == Board.COLOR_WHITE)
            {
                locations = Bitboard.Bitboard_BitList(b->Boards[Board.BOARD_WHITE]);
            }
            else
            {
                locations = Bitboard.Bitboard_BitList(b->Boards[Board.BOARD_BLACK]);
            }

            for (byte i = 0; i < locations.Length; i++)
            {
                var to         = locations[i];
                var pieceMoves = Moves.GetMoves(b, to);

                // filter out all captures.. remember, this is in reverse!
                pieceMoves = pieceMoves & ~(b->Boards[Board.BOARD_WHITE] | b->Boards[Board.BOARD_BLACK]);

                var sources = Bitboard.Bitboard_BitList(pieceMoves);

                for (int j = 0; j < sources.Length; j++)
                {
                    moves.Add(new byte[] { sources[j], to });
                }
            }

            return(moves.ToArray());
        }
Ejemplo n.º 5
0
        public unsafe void BlackKingTest1()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            b->Boards[Board.BOARD_KINGS] = Bitboard.Set((b->Boards[Board.BOARD_KINGS]), 60);
            b->Boards[Board.BOARD_BLACK] = Bitboard.Set((b->Boards[Board.BOARD_BLACK]), 60);
            Board.GenerateTileMap(b);

            ulong movesKing = MoveClasses.King.Read(60);

            Assert.AreEqual((ulong)0x2838000000000000, movesKing);

            // allow all castling
            b->Castle = Board.CASTLE_BK | Board.CASTLE_BQ | Board.CASTLE_WK | Board.CASTLE_WQ;

            // standard king moves plus castling moves
            ulong moves = Moves.GetMoves(b, 60);

            Assert.AreEqual((ulong)0x6C38000000000000, moves);

            // disallow castling
            b->Castle = 0;

            // standard king moves plus castling moves
            moves = Moves.GetMoves(b, 60);
            Assert.AreEqual((ulong)0x2838000000000000, moves);
        }
Ejemplo n.º 6
0
        public unsafe void SwitchKings()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            // kings on the wrong side, should NOT allow castling

            //white king at 60
            b->Boards[Board.BOARD_KINGS] = Bitboard.Set((b->Boards[Board.BOARD_KINGS]), 60);
            b->Boards[Board.BOARD_WHITE] = Bitboard.Set((b->Boards[Board.BOARD_WHITE]), 60);

            //black king at 4
            b->Boards[Board.BOARD_KINGS] = Bitboard.Set((b->Boards[Board.BOARD_KINGS]), 4);
            b->Boards[Board.BOARD_BLACK] = Bitboard.Set((b->Boards[Board.BOARD_BLACK]), 4);
            Board.GenerateTileMap(b);

            // We have disabled all castling, this should prevent any castling moves
            b->Castle = 0;

            ulong moves = Moves.GetMoves(b, 4);

            Assert.AreEqual((ulong)0x3828, moves);

            moves = Moves.GetMoves(b, 60);
            Assert.AreEqual((ulong)0x2838000000000000, moves);
        }
Ejemplo n.º 7
0
        public unsafe void TestGetCastlingSingleAllowances()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Board.SetPiece(b, 4, Board.PIECE_KING, Board.COLOR_WHITE);
            Board.SetPiece(b, 60, Board.PIECE_KING, Board.COLOR_BLACK);

            Board.SetPiece(b, 0, Board.PIECE_ROOK, Board.COLOR_WHITE);
            Board.SetPiece(b, 7, Board.PIECE_ROOK, Board.COLOR_WHITE);
            Board.SetPiece(b, 56, Board.PIECE_ROOK, Board.COLOR_BLACK);
            Board.SetPiece(b, 63, Board.PIECE_ROOK, Board.COLOR_BLACK);

            b->Castle = Board.CASTLE_WQ;
            var castling = Board.GetCastling(b);

            Assert.AreEqual(Board.CASTLE_WQ, castling);

            b->Castle = Board.CASTLE_WK;
            castling  = Board.GetCastling(b);
            Assert.AreEqual(Board.CASTLE_WK, castling);

            b->Castle = Board.CASTLE_BQ;
            castling  = Board.GetCastling(b);
            Assert.AreEqual(Board.CASTLE_BQ, castling);

            b->Castle = Board.CASTLE_BK;
            castling  = Board.GetCastling(b);
            Assert.AreEqual(Board.CASTLE_BK, castling);
        }
Ejemplo n.º 8
0
        public unsafe void TestRookMoves1x()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Board.SetPiece(b, 28, Board.PIECE_ROOK, Board.COLOR_WHITE);

            ulong attacks = Moves.GetAttacks(b, 28);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Checks for the invalid state where kings are attacking each other
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        private bool AreKingsTouching(BoardStruct *b)
        {
            var whiteKing      = Bitboard.ForwardBit(b->Boards[Board.BOARD_WHITE] & b->Boards[Board.BOARD_KINGS]);
            var blackKingBoard = b->Boards[Board.BOARD_BLACK] & b->Boards[Board.BOARD_KINGS];

            var attacks = Moves.GetAttacks(b, whiteKing);

            return((blackKingBoard & attacks) > 0);
        }
Ejemplo n.º 10
0
        private unsafe static void GenericGameTest(List <PGNMove> moves, string endState)
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Board.Init(b, 1);

            var finalBoard = Chess.Base.Notation.ReadFEN(endState);
            var fBoard     = Helpers.ManagedBoardToNative(finalBoard);

            Assert.AreEqual(Zobrist.Calculate(fBoard), fBoard->Hash);

            var stateStack = new IntPtr[150];
            int head       = 0;

            for (int i = 0; i < moves.Count; i++)
            {
                stateStack[head] = Board.Copy(b);
                head++;
                var ok = Board.Make(b, moves[i].From, moves[i].To);
                if (moves[i].Promotion != 0)
                {
                    bool promoteOk = Board.Promote(b, moves[i].To, (int)moves[i].Promotion);
                    Assert.AreEqual(true, promoteOk);
                }

                Assert.AreEqual(true, ok);
                Assert.AreEqual(Zobrist.Calculate(b), b->Hash);
            }

            Assert.AreEqual(Zobrist.Calculate(fBoard), b->Hash);
            Assert.AreEqual(fBoard->Hash, b->Hash);
            //Assert.AreEqual(fBoard->AttacksWhite, b->AttacksWhite);
            //Assert.AreEqual(fBoard->AttacksBlack, b->AttacksBlack);
            Assert.AreEqual(fBoard->Castle, b->Castle);
            Assert.AreEqual(fBoard->PlayerTurn, b->PlayerTurn);
            Assert.AreEqual(fBoard->FiftyMoveRulePlies, b->FiftyMoveRulePlies);
            Assert.AreEqual(fBoard->CurrentMove, b->CurrentMove);

            while (head > 0)
            {
                head--;
                Board.Unmake(b);
                var bStack = (BoardStruct *)stateStack[head];

                Assert.AreEqual(Zobrist.Calculate(b), b->Hash);
                Assert.AreEqual(bStack->Hash, b->Hash);
                //Assert.AreEqual(bStack->AttacksWhite, b->AttacksWhite);
                //Assert.AreEqual(bStack->AttacksBlack, b->AttacksBlack);
                Assert.AreEqual(bStack->Castle, b->Castle);
                Assert.AreEqual(bStack->PlayerTurn, b->PlayerTurn);
                Assert.AreEqual(bStack->FiftyMoveRulePlies, b->FiftyMoveRulePlies);
                Assert.AreEqual(bStack->CurrentMove, b->CurrentMove);
            }
        }
Ejemplo n.º 11
0
        public unsafe void TestGetCastlingNone()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Board.SetPiece(b, 4, Board.PIECE_KING, Board.COLOR_WHITE);
            Board.SetPiece(b, 60, Board.PIECE_KING, Board.COLOR_BLACK);

            var castling = Board.GetCastling(b);

            Assert.AreEqual(0, castling);
        }
Ejemplo n.º 12
0
        public unsafe void TestMakePawn()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Board.Init(b, 1);
            Board.Make(b, 12, 28);

            Assert.AreEqual(20, b->EnPassantTile);
            Assert.AreEqual(true, Bitboard.Get(b->Boards[Board.BOARD_PAWNS], 28));
            Assert.AreEqual(false, Bitboard.Get(b->Boards[Board.BOARD_PAWNS], 12));
        }
Ejemplo n.º 13
0
        public unsafe void TestKnightMoves2()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            b->Boards[Board.BOARD_KNIGHTS] = Bitboard.Set((b->Boards[Board.BOARD_KNIGHTS]), 14);
            b->Boards[Board.BOARD_WHITE]   = Bitboard.Set((b->Boards[Board.BOARD_WHITE]), 14);
            Board.GenerateTileMap(b);

            ulong moves = Moves.GetMoves(b, 14);

            Assert.AreEqual((ulong)0xA0100010, moves);
        }
Ejemplo n.º 14
0
        public unsafe void TestWhitePawnSingle3()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            b->Boards[Board.BOARD_PAWNS] = Bitboard.Set((b->Boards[Board.BOARD_PAWNS]), 55);
            b->Boards[Board.BOARD_WHITE] = Bitboard.Set((b->Boards[Board.BOARD_WHITE]), 55);
            Board.GenerateTileMap(b);

            ulong moves = Moves.GetAttacks(b, 55);

            Assert.AreEqual((ulong)0x4000000000000000, moves);
        }
Ejemplo n.º 15
0
        public unsafe void BlackCastleQueensideOnly()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Board.SetPiece(b, 60, Board.PIECE_KING, Board.COLOR_BLACK);
            Board.SetPiece(b, 61, Board.PIECE_KNIGHT, Board.COLOR_BLACK);

            // standard king moves plus castling moves
            ulong moves = Moves.GetMoves(b, 60);

            Assert.AreEqual((ulong)0xC38000000000000, moves);
        }
Ejemplo n.º 16
0
        public unsafe void TestWhiteQueen1()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            b->Boards[Board.BOARD_QUEENS] = Bitboard.Set((b->Boards[Board.BOARD_QUEENS]), 28);
            b->Boards[Board.BOARD_WHITE]  = Bitboard.Set((b->Boards[Board.BOARD_WHITE]), 28);
            Board.GenerateTileMap(b);

            var moves = Moves.GetMoves(b, 28);

            Assert.AreEqual((ulong)0x11925438EF385492, moves);
        }
Ejemplo n.º 17
0
        public unsafe void TestBlackPawnSingle3()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            b->Boards[Board.BOARD_PAWNS] = Bitboard.Set((b->Boards[Board.BOARD_PAWNS]), 8);
            b->Boards[Board.BOARD_BLACK] = Bitboard.Set((b->Boards[Board.BOARD_BLACK]), 8);
            Board.GenerateTileMap(b);

            ulong moves = Moves.GetAttacks(b, 8);

            Assert.AreEqual((ulong)0x2, moves);
        }
Ejemplo n.º 18
0
        public unsafe void TestBoardInit()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Board.Init(b, 0);

            byte allCastle = Board.CASTLE_BK | Board.CASTLE_BQ | Board.CASTLE_WK | Board.CASTLE_WQ;

            Assert.AreEqual((ulong)0, b->Boards[Board.BOARD_WHITE]);
            Assert.AreEqual((ulong)0, b->Boards[Board.BOARD_BLACK]);
            Assert.AreEqual(allCastle, b->Castle);
        }
Ejemplo n.º 19
0
        public unsafe void TestWhiteEnPassantMoveRight()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Board.SetPiece(b, 33, Board.PIECE_PAWN, Board.COLOR_WHITE);
            Board.SetPiece(b, 34, Board.PIECE_PAWN, Board.COLOR_BLACK);
            b->EnPassantTile = 42;

            ulong moves = Moves.GetMoves(b, 33);

            // tile 41, 42
            Assert.AreEqual((ulong)0x60000000000, moves);
        }
Ejemplo n.º 20
0
        public unsafe void TestWhiteEnPassantMoveLeft()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Board.SetPiece(b, 38, Board.PIECE_PAWN, Board.COLOR_WHITE);
            Board.SetPiece(b, 37, Board.PIECE_PAWN, Board.COLOR_BLACK);
            b->EnPassantTile = 45;

            ulong moves = Moves.GetMoves(b, 38);

            // tile 45, 46
            Assert.AreEqual((ulong)0x600000000000, moves);
        }
Ejemplo n.º 21
0
        public unsafe void TestBlackEnPassantMoveLeft()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Board.SetPiece(b, 30, Board.PIECE_PAWN, Board.COLOR_BLACK);
            Board.SetPiece(b, 29, Board.PIECE_PAWN, Board.COLOR_WHITE);
            b->EnPassantTile = 21;

            ulong moves = Moves.GetMoves(b, 30);

            // tile 17,18
            Assert.AreEqual((ulong)0x600000, moves);
        }
Ejemplo n.º 22
0
        public unsafe void TestWhitePawnBlocker1()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Board.SetPiece(b, 8, Board.PIECE_PAWN, Board.COLOR_WHITE);

            ulong moves = Moves.GetMoves(b, 8);

            Assert.AreEqual((ulong)0x1010000, moves);

            Board.SetPiece(b, 16, Board.PIECE_KNIGHT, Board.COLOR_WHITE);
            moves = Moves.GetMoves(b, 8);
            Assert.AreEqual((ulong)0x0, moves);
        }
Ejemplo n.º 23
0
        public unsafe void TestBoardInitPieces()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Board.Init(b, 1);

            byte allCastle = Board.CASTLE_BK | Board.CASTLE_BQ | Board.CASTLE_WK | Board.CASTLE_WQ;

            Assert.AreEqual((ulong)0xFFFF, b->Boards[Board.BOARD_WHITE]);
            Assert.AreEqual((ulong)0xFFFF000000000000, b->Boards[Board.BOARD_BLACK]);
            Assert.AreEqual((ulong)0xFF00000000FF00, b->Boards[Board.BOARD_PAWNS]);
            Assert.AreEqual((ulong)0x1000000000000010, b->Boards[Board.BOARD_KINGS]);
            Assert.AreEqual(allCastle, b->Castle);
        }
Ejemplo n.º 24
0
        public unsafe void TestBlackPawnSame1()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            b->Boards[Board.BOARD_PAWNS] = Bitboard.Set((b->Boards[Board.BOARD_PAWNS]), 53);
            b->Boards[Board.BOARD_BLACK] = Bitboard.Set((b->Boards[Board.BOARD_BLACK]), 53);

            b->Boards[Board.BOARD_PAWNS] = Bitboard.Set((b->Boards[Board.BOARD_PAWNS]), 46);
            b->Boards[Board.BOARD_BLACK] = Bitboard.Set((b->Boards[Board.BOARD_BLACK]), 46);
            Board.GenerateTileMap(b);

            ulong moves = Moves.GetMoves(b, 53);

            Assert.AreEqual((ulong)0x202000000000, moves);
        }
Ejemplo n.º 25
0
        public unsafe void TestWhiteBlockedWhite()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            b->Boards[Board.BOARD_PAWNS] = Bitboard.Set((b->Boards[Board.BOARD_PAWNS]), 20);
            b->Boards[Board.BOARD_WHITE] = Bitboard.Set((b->Boards[Board.BOARD_WHITE]), 20);

            b->Boards[Board.BOARD_PAWNS] = Bitboard.Set((b->Boards[Board.BOARD_PAWNS]), 28);
            b->Boards[Board.BOARD_WHITE] = Bitboard.Set((b->Boards[Board.BOARD_WHITE]), 28);
            Board.GenerateTileMap(b);

            ulong moves = Moves.GetMoves(b, 20);

            Assert.AreEqual((ulong)0x0, moves);
        }
Ejemplo n.º 26
0
        public unsafe void TestBoardXY()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Assert.AreEqual(5, Board.X(5));
            Assert.AreEqual(5, Board.X(5 + 8));
            Assert.AreEqual(5, Board.X(5 + 16));
            Assert.AreEqual(3, Board.X(8 * 7 + 3));

            Assert.AreEqual(7, Board.Y(7 * 8 + 3));
            Assert.AreEqual(1, Board.Y(1 * 8 + 4));
            Assert.AreEqual(3, Board.Y(3 * 8 + 6));
            Assert.AreEqual(4, Board.Y(4 * 8 + 0));
            Assert.AreEqual(7, Board.Y(7 * 8 + 7));
        }
Ejemplo n.º 27
0
        public unsafe void TestBlackBlockedBlack()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            b->Boards[Board.BOARD_PAWNS] = Bitboard.Set((b->Boards[Board.BOARD_PAWNS]), 42);
            b->Boards[Board.BOARD_BLACK] = Bitboard.Set((b->Boards[Board.BOARD_BLACK]), 42);

            b->Boards[Board.BOARD_PAWNS] = Bitboard.Set((b->Boards[Board.BOARD_PAWNS]), 34);
            b->Boards[Board.BOARD_BLACK] = Bitboard.Set((b->Boards[Board.BOARD_BLACK]), 34);
            Board.GenerateTileMap(b);

            ulong moves = Moves.GetMoves(b, 42);

            Assert.AreEqual((ulong)0x0, moves);
        }
Ejemplo n.º 28
0
        public unsafe void TestWhitePawnCapture1()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            b->Boards[Board.BOARD_PAWNS] = Bitboard.Set((b->Boards[Board.BOARD_PAWNS]), 8);
            b->Boards[Board.BOARD_WHITE] = Bitboard.Set((b->Boards[Board.BOARD_WHITE]), 8);

            b->Boards[Board.BOARD_PAWNS] = Bitboard.Set((b->Boards[Board.BOARD_PAWNS]), 17);
            b->Boards[Board.BOARD_BLACK] = Bitboard.Set((b->Boards[Board.BOARD_BLACK]), 17);
            Board.GenerateTileMap(b);

            ulong moves = Moves.GetAttacks(b, 8);

            Assert.AreEqual((ulong)0x20000, moves);
        }
Ejemplo n.º 29
0
        public unsafe void TestBlackPawnCapture3()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            b->Boards[Board.BOARD_PAWNS] = Bitboard.Set((b->Boards[Board.BOARD_PAWNS]), 35);
            b->Boards[Board.BOARD_BLACK] = Bitboard.Set((b->Boards[Board.BOARD_BLACK]), 35);

            b->Boards[Board.BOARD_PAWNS] = Bitboard.Set((b->Boards[Board.BOARD_PAWNS]), 35 - 7);
            b->Boards[Board.BOARD_WHITE] = Bitboard.Set((b->Boards[Board.BOARD_WHITE]), 35 - 7);
            Board.GenerateTileMap(b);

            ulong moves = Moves.GetMoves(b, 35);

            Assert.AreEqual((ulong)0x18000000, moves);
        }
Ejemplo n.º 30
0
        public unsafe void TestWhiteEnPassantAttack()
        {
            BoardStruct *b = (BoardStruct *)Board.Create();

            Board.SetPiece(b, 37, Board.PIECE_PAWN, Board.COLOR_WHITE);
            Board.SetPiece(b, 36, Board.PIECE_PAWN, Board.COLOR_BLACK);
            b->EnPassantTile = 44;

            ulong attacks = Moves.GetAttacks(b, 37);

            Assert.AreEqual((ulong)0x500000000000, attacks);

            ulong moves = Moves.GetMoves(b, 37);

            Assert.AreEqual((ulong)0x300000000000, moves);
        }
Ejemplo n.º 31
0
        public void Position(string fenString, List<UciMove> moves)
        {
            SendInfo("Reading position");

            if ((long)BoardPtr != 0)
                Chess.Lib.Board.Delete(BoardPtr);

            if (fenString == null)
            {
                BoardPtr = Chess.Lib.Board.Create();
                Chess.Lib.Board.Init(BoardPtr, 1);
            }
            else
            {
                var bx = Chess.Base.Notation.ReadFEN(fenString);
                BoardPtr = Helpers.ManagedBoardToNative(bx);
            }

            foreach (var move in moves)
            {
                var moved = Board.Make(BoardPtr, move.From, move.To);
                if (!moved)
                    SendInfo("Illegal move: " + move.ToString());

                if (move.Promotion != UciPiece.None)
                {
                    var promoted = Board.Promote(BoardPtr, move.To, (int)move.Promotion);
                    if (!promoted)
                        SendInfo("Illegal promotion: " + move.ToString());
                }
            }
        }
Ejemplo n.º 32
0
 public void UciNewGame()
 {
     SendInfo("Starting new game");
     BoardPtr = Chess.Lib.Board.Create();
     Chess.Lib.Board.Init(BoardPtr, 1);
 }
Ejemplo n.º 33
0
 public Engine()
 {
     BoardPtr = (BoardStruct*)0;
 }