/// <summary>
        /// Initializes a new instance of PieceLocationManager from another PieceLocationManager.
        /// </summary>
        /// <param name="pieceLocationManager">PieceLocationManager to clone from.</param>
        public PieceLocationManager(PieceLocationManager pieceLocationManager)
            : this()
        {
            m_locationLast = pieceLocationManager.m_locationLast;

              for (int i = 0; i < SIZEOF_LOCATION_LIST; ++i)
            m_pieceLocationList[i] = pieceLocationManager.m_pieceLocationList[i];

              for (int i = 0; i < SIZEOF_BOARD_MAP; ++i)
            m_boardToListMap[i] = pieceLocationManager.m_boardToListMap[i];
        }
        /// <summary>
        /// Initializes a new instance of PieceLocationManager from another PieceLocationManager.
        /// </summary>
        /// <param name="pieceLocationManager">PieceLocationManager to clone from.</param>
        public PieceLocationManager(PieceLocationManager pieceLocationManager)
            : this()
        {
            m_locationLast = pieceLocationManager.m_locationLast;

            for (int i = 0; i < SIZEOF_LOCATION_LIST; ++i)
            {
                m_pieceLocationList[i] = pieceLocationManager.m_pieceLocationList[i];
            }

            for (int i = 0; i < SIZEOF_BOARD_MAP; ++i)
            {
                m_boardToListMap[i] = pieceLocationManager.m_boardToListMap[i];
            }
        }
Example #3
0
        public Board(Board board)
        {
            m_squares = new Piece[board.m_squares.Length];
            for (int i = 0; i < m_squares.Length; ++i)
            {
                m_squares[i] = board.m_squares[i];
            }

            m_state = board.m_state;

            m_history           = new HashHistory(board.m_history);
            m_pieceFactory      = FlyweightPieceFactory.Instance();
            m_whiteLocationList = new PieceLocationManager(board.m_whiteLocationList);
            m_blackLocationList = new PieceLocationManager(board.BlackPieceLocations);
            m_whiteKingLocation = board.m_whiteKingLocation;
            m_blackKingLocation = board.m_blackKingLocation;
            m_boardHash         = new ZobristHash(board.m_boardHash);
        }
Example #4
0
        /// <summary>
        /// Evaluates a board from the perspective of the current player.
        /// </summary>
        /// <param name="board">Board to evaluate.</param>
        /// <returns>Score for board.</returns>
        public int EvaluatePosition(Board board)
        {
            m_board = board;
              m_whiteLocations = board.WhitePieceLocations;
              m_blackLocations = board.BlackPieceLocations;

              m_whiteScore = 0;
              m_blackScore = 0;

              EvaluateMaterial();
              EvaluatePositions();
              EvaluatePawns();

              switch (m_board.State.ColorToPlay)
              {
            case PieceColor.Black:
              return m_blackScore - m_whiteScore;

            case PieceColor.White:
              return m_whiteScore - m_blackScore;

            default:
              return 0;
              }
        }
Example #5
0
        public Board(Board board)
        {
            m_squares = new Piece[board.m_squares.Length];
              for (int i = 0; i < m_squares.Length; ++i)
            m_squares[i] = board.m_squares[i];

              m_state = board.m_state;

              m_history = new HashHistory(board.m_history);
              m_pieceFactory = FlyweightPieceFactory.Instance();
              m_whiteLocationList = new PieceLocationManager(board.m_whiteLocationList);
              m_blackLocationList = new PieceLocationManager(board.BlackPieceLocations);
              m_whiteKingLocation = board.m_whiteKingLocation;
              m_blackKingLocation = board.m_blackKingLocation;
              m_boardHash = new ZobristHash(board.m_boardHash);
        }
Example #6
0
        /// <summary>
        /// Initializes a new instance of Board ready to be played on
        /// and with pieces put on their initial locations.
        /// </summary>
        public Board()
        {
            //we make board twice as big as we use the 0x88 scheme for representing the board
              m_squares = new Piece[NOF_SQUARS];
              for (int i = 0; i < m_squares.Length; ++i)
            m_squares[i] = Piece.None;

              m_squares[(int)Square.A1] = Piece.WhiteRook;
              m_squares[(int)Square.B1] = Piece.WhiteKnight;
              m_squares[(int)Square.C1] = Piece.WhiteBishop;
              m_squares[(int)Square.D1] = Piece.WhiteQueen;
              m_squares[(int)Square.E1] = Piece.WhiteKing;
              m_squares[(int)Square.F1] = Piece.WhiteBishop;
              m_squares[(int)Square.G1] = Piece.WhiteKnight;
              m_squares[(int)Square.H1] = Piece.WhiteRook;
              m_squares[(int)Square.A2] = Piece.WhitePawn;
              m_squares[(int)Square.B2] = Piece.WhitePawn;
              m_squares[(int)Square.C2] = Piece.WhitePawn;
              m_squares[(int)Square.D2] = Piece.WhitePawn;
              m_squares[(int)Square.E2] = Piece.WhitePawn;
              m_squares[(int)Square.F2] = Piece.WhitePawn;
              m_squares[(int)Square.G2] = Piece.WhitePawn;
              m_squares[(int)Square.H2] = Piece.WhitePawn;
              m_squares[(int)Square.A7] = Piece.BlackPawn;
              m_squares[(int)Square.B7] = Piece.BlackPawn;
              m_squares[(int)Square.C7] = Piece.BlackPawn;
              m_squares[(int)Square.D7] = Piece.BlackPawn;
              m_squares[(int)Square.E7] = Piece.BlackPawn;
              m_squares[(int)Square.F7] = Piece.BlackPawn;
              m_squares[(int)Square.G7] = Piece.BlackPawn;
              m_squares[(int)Square.H7] = Piece.BlackPawn;
              m_squares[(int)Square.A8] = Piece.BlackRook;
              m_squares[(int)Square.B8] = Piece.BlackKnight;
              m_squares[(int)Square.C8] = Piece.BlackBishop;
              m_squares[(int)Square.D8] = Piece.BlackQueen;
              m_squares[(int)Square.E8] = Piece.BlackKing;
              m_squares[(int)Square.F8] = Piece.BlackBishop;
              m_squares[(int)Square.G8] = Piece.BlackKnight;
              m_squares[(int)Square.H8] = Piece.BlackRook;

              m_state.ColorToPlay = PieceColor.White;
              m_state.WhiteCanCastleShort = true;
              m_state.WhiteCanCastleLong = true;
              m_state.BlackCanCastleShort = true;
              m_state.BlackCanCastleLong = true;
              m_state.EnPassantTarget = Square.None;
              m_state.NonHitAndPawnMovesPlayed = 0;

              m_history = new HashHistory();
              m_pieceFactory = FlyweightPieceFactory.Instance();

              m_whiteLocationList = new PieceLocationManager();
              m_blackLocationList = new PieceLocationManager();
              foreach (Square square in this)
              {
            if (GetPieceColor(square) == PieceColor.White)
              m_whiteLocationList.PlacePiece(square);

            if (GetPieceColor(square) == PieceColor.Black)
              m_blackLocationList.PlacePiece(square);
              }
              m_whiteKingLocation = Square.E1;
              m_blackKingLocation = Square.E8;

              m_boardHash = new ZobristHash(this);
              AddToHistory();
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of Board ready to be played on
        /// and with pieces put on their initial locations.
        /// </summary>
        public Board()
        {
            //we make board twice as big as we use the 0x88 scheme for representing the board
            m_squares = new Piece[NOF_SQUARS];
            for (int i = 0; i < m_squares.Length; ++i)
            {
                m_squares[i] = Piece.None;
            }

            m_squares[(int)Square.A1] = Piece.WhiteRook;
            m_squares[(int)Square.B1] = Piece.WhiteKnight;
            m_squares[(int)Square.C1] = Piece.WhiteBishop;
            m_squares[(int)Square.D1] = Piece.WhiteQueen;
            m_squares[(int)Square.E1] = Piece.WhiteKing;
            m_squares[(int)Square.F1] = Piece.WhiteBishop;
            m_squares[(int)Square.G1] = Piece.WhiteKnight;
            m_squares[(int)Square.H1] = Piece.WhiteRook;
            m_squares[(int)Square.A2] = Piece.WhitePawn;
            m_squares[(int)Square.B2] = Piece.WhitePawn;
            m_squares[(int)Square.C2] = Piece.WhitePawn;
            m_squares[(int)Square.D2] = Piece.WhitePawn;
            m_squares[(int)Square.E2] = Piece.WhitePawn;
            m_squares[(int)Square.F2] = Piece.WhitePawn;
            m_squares[(int)Square.G2] = Piece.WhitePawn;
            m_squares[(int)Square.H2] = Piece.WhitePawn;
            m_squares[(int)Square.A7] = Piece.BlackPawn;
            m_squares[(int)Square.B7] = Piece.BlackPawn;
            m_squares[(int)Square.C7] = Piece.BlackPawn;
            m_squares[(int)Square.D7] = Piece.BlackPawn;
            m_squares[(int)Square.E7] = Piece.BlackPawn;
            m_squares[(int)Square.F7] = Piece.BlackPawn;
            m_squares[(int)Square.G7] = Piece.BlackPawn;
            m_squares[(int)Square.H7] = Piece.BlackPawn;
            m_squares[(int)Square.A8] = Piece.BlackRook;
            m_squares[(int)Square.B8] = Piece.BlackKnight;
            m_squares[(int)Square.C8] = Piece.BlackBishop;
            m_squares[(int)Square.D8] = Piece.BlackQueen;
            m_squares[(int)Square.E8] = Piece.BlackKing;
            m_squares[(int)Square.F8] = Piece.BlackBishop;
            m_squares[(int)Square.G8] = Piece.BlackKnight;
            m_squares[(int)Square.H8] = Piece.BlackRook;

            m_state.ColorToPlay              = PieceColor.White;
            m_state.WhiteCanCastleShort      = true;
            m_state.WhiteCanCastleLong       = true;
            m_state.BlackCanCastleShort      = true;
            m_state.BlackCanCastleLong       = true;
            m_state.EnPassantTarget          = Square.None;
            m_state.NonHitAndPawnMovesPlayed = 0;

            m_history      = new HashHistory();
            m_pieceFactory = FlyweightPieceFactory.Instance();

            m_whiteLocationList = new PieceLocationManager();
            m_blackLocationList = new PieceLocationManager();
            foreach (Square square in this)
            {
                if (GetPieceColor(square) == PieceColor.White)
                {
                    m_whiteLocationList.PlacePiece(square);
                }

                if (GetPieceColor(square) == PieceColor.Black)
                {
                    m_blackLocationList.PlacePiece(square);
                }
            }
            m_whiteKingLocation = Square.E1;
            m_blackKingLocation = Square.E8;

            m_boardHash = new ZobristHash(this);
            AddToHistory();
        }