Пример #1
0
        private MoveSet GetValidMoves(PieceName pieceName)
        {
            if (null == _cachedValidMovesByPiece)
            {
                _cachedValidMovesByPiece = new MoveSet[EnumUtils.NumPieceNames];
            }

            int pieceNameIndex = (int)pieceName;

            if (null == _cachedValidMovesByPiece[pieceNameIndex])
            {
#if DEBUG
                // MoveSet is not cached in L1 cache
                ValidMoveCacheMetricsSet["ValidMoves." + EnumUtils.GetShortName(pieceName)].Miss();
#endif
                // Calculate MoveSet
                Piece   targetPiece = GetPiece(pieceName);
                MoveSet moves       = GetValidMovesInternal(targetPiece);

                // Populate cache
                _cachedValidMovesByPiece[pieceNameIndex] = moves;
            }
#if DEBUG
            else
            {
                // MoveSet is cached in L1 cache
                ValidMoveCacheMetricsSet["ValidMoves." + EnumUtils.GetShortName(pieceName)].Hit();
            }
#endif

            return(_cachedValidMovesByPiece[pieceNameIndex]);
        }
Пример #2
0
        public static string ToBoardSpacePieceName(PieceName pieceName)
        {
            string name = EnumUtils.GetShortName(pieceName);

            if (null != name && name.Length > 0)
            {
                name = name[0].ToString().ToLower() + name.Substring(1);
            }

            return(name);
        }
Пример #3
0
 public override string ToString()
 {
     return(string.Format("{0}[{1}]", EnumUtils.GetShortName(PieceName), null != Position ? Position.ToString() : ""));
 }