/// <summary> /// Extracts the current piece from the board. /// </summary> /// <param name="screenshot">The screenshot to extract the piece from.</param> /// <param name="maxFallingDistance">Expected maximal falling distance.</param> /// <returns>The piece and it's probability.</returns> public ProbabilisticResult <Piece> ExtractPieceFuzzy(IScreenshot screenshot, int maxFallingDistance) { if (screenshot == null) { throw new ArgumentNullException(nameof(screenshot)); } if (maxFallingDistance < 0) { throw new ArgumentException("maxFallingDistance must be positive"); } double bestProbability = 0; Piece expectedPiece = null; for (int yDelta = 0; yDelta <= maxFallingDistance; yDelta++) { foreach (var tetromino in Tetriminos.All) { foreach (var pose in tetromino.GetPoses()) { var piece = pose.Fall(yDelta); var probability = _templateMatcher.GetProbabilityCurrentPiece(screenshot, piece); if (probability > bestProbability) { bestProbability = probability; expectedPiece = piece; } } } } return(new ProbabilisticResult <Piece>(expectedPiece, bestProbability)); }