Esempio n. 1
0
        /// <summary>
        /// Updates the number of pieces of the specified type and color that are on the board.
        /// </summary>
        public void UpdateBoardInfo(string piece, PieceColor pieceColor)
        {
            PieceInfo pieceInfo = new PieceInfo(0, 0);

            switch (pieceColor)
            {
            case PieceColor.Black:
                // Increment the number of black pieces of the current piece type
                if (boardInfo.TryGetValue(piece, out pieceInfo))
                {
                    pieceInfo.black++;
                }
                // Create new PieceInfo entry in dictionary and increment the number of
                // black pieces of the current piece type
                else
                {
                    boardInfo.Add(piece, new PieceInfo(1, 0));
                }
                break;

            case PieceColor.White:
                // Increment the number of white pieces of the current piece type
                if (boardInfo.TryGetValue(piece, out pieceInfo))
                {
                    pieceInfo.white++;
                }
                // Create new PieceInfo entry in dictionary and increment the number of
                // white pieces of the current piece type
                else
                {
                    boardInfo.Add(piece, new PieceInfo(0, 1));
                }
                break;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the number of pieces of the specified type and color that are on the board.
        /// </summary>
        public int GetBoardInfo(string piece, PieceColor pieceColor)
        {
            PieceInfo pieceInfo = new PieceInfo(0, 0);

            // Check if key exists
            if (boardInfo.TryGetValue(piece, out pieceInfo))
            {
                switch (pieceColor)
                {
                case PieceColor.Black:
                    return(pieceInfo.black);

                case PieceColor.White:
                    return(pieceInfo.white);

                default:
                    // Should never run
                    break;
                }
            }
            return(0);
        }