예제 #1
0
파일: Helpers.cs 프로젝트: adh2050/Chess
        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;
        }