using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MathModEduPr02
{
    internal class Monte_CarloProblem
    {
        public static double FindPi(double r = 1, int n = 1000, double h=0.1)
        {
            int k = 0;
            Random random = new Random();
            for (double i = 0; i < n; ++i)
            {
                double xi = random.Next(0, (int)(r*2*(1/h))) * h;
                double yi = random.Next(0, (int)(r * 2 * (1 / h))) * h;
                if (Math.Pow(xi - r, 2) + Math.Pow(yi - r, 2) <= Math.Pow(r, 2)) ++k;
            }
            return (double)k / (double)n * 4*r*r;
        }
        public delegate bool funtions(double x, double y, ref bool previos);
        public static double FindAreaOfShape(double a, double b,  funtions fs, 
        double startX = 0, int n=1000000, double h=0.001)
        {
            int k = 0;
            Random random = new Random();
            for (double i = 0; i < n; ++i)
            {
                double xi = random.Next(0, (int)(a * (1 / h))) * h + startX;
                double yi = random.Next(0, (int)(b * (1 / h))) * h;
                bool kFallsIntoArea = true;
                fs(xi, yi, ref kFallsIntoArea);
                if(kFallsIntoArea)++k;
            }
            return a * b * k / n;
        }
    }
}
