Ejemplo n.º 1
0
        private MoveSet GetValidMoves(PieceName pieceName)
        {
            if (null == _cachedValidMovesByPiece)
            {
                _cachedValidMovesByPiece = new MoveSet[EnumUtils.NumPieceNames];
            }

            int pieceNameIndex = (int)pieceName;

            if (null != _cachedValidMovesByPiece[pieceNameIndex])
            {
                // MoveSet is cached in L1 cache
                ValidMoveCacheMetricsSet["ValidMoves." + EnumUtils.GetShortName(pieceName)].Hit();
            }
            else
            {
                // MoveSet is not cached in L1 cache
                ValidMoveCacheMetricsSet["ValidMoves." + EnumUtils.GetShortName(pieceName)].Miss();

                // Calculate MoveSet
                Piece   targetPiece = GetPiece(pieceName);
                MoveSet moves       = GetValidMovesInternal(targetPiece);
                moves.Lock();

                // Populate cache
                _cachedValidMovesByPiece[pieceNameIndex] = moves;
            }

            return(_cachedValidMovesByPiece[pieceNameIndex]);
        }
Ejemplo n.º 2
0
        public MoveSet GetValidMoves()
        {
            MoveSet moves = new MoveSet();

            if (GameInProgress)
            {
                foreach (PieceName pieceName in CurrentTurnPieces)
                {
                    moves.Add(GetValidMoves(pieceName));
                }

                if (moves.Count == 0)
                {
                    moves.Add(Move.Pass);
                }
            }

            moves.Lock();

            return(moves);
        }