#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
    int n = 0;
    int i = 0;
    int piece = 0;
    int check_t = 0;
    int check_a = 0;
    float fortune_t = 10.0;
    float fortune_a = 10.0;
    int goal = 50;
    float somme_t = 0.0;
    float somme_a = 0.0;

    float moyenne_t = 0;
    float moyenne_a = 0;

    float fortune_t_tab[1000] = {0.0};
    float fortune_a_tab[1000] = {0.0};

    srand(time(NULL));

    while (i != 1000)
    {
        fortune_t = 10;

        check_t = 0;

        fortune_a = 10;

        check_a = 0;

        for (n = 0; n < 1000000; n = n + 1)
        {
            piece = rand()%5;

            if (piece%2 == 0)
            {

                fortune_t = fortune_t - 1;

                if (fortune_a > goal/2)
                {
                    fortune_a = fortune_a - (goal - fortune_a);
                }

                else if (fortune_a < goal/2)
                {
                    fortune_a = fortune_a - fortune_a;
                }
            }

            else if (piece%2 == 1)
            {

                fortune_t = fortune_t + 1;

                if (fortune_a >= goal/2)
                {
                    fortune_a = fortune_a + (goal - fortune_a);
                }

                else if (fortune_a < goal/2)
                {
                    fortune_a = fortune_a + fortune_a;
                }
            }

            if (fortune_t == goal)
            {
                check_t = 1;
            }

            if (fortune_a == goal)
            {
                check_a = 1;
            }

        }

        if (check_t == 1)
        {
            fortune_t_tab[i] = goal;
        }

        else
        {
            fortune_t_tab[i] = fortune_t;
        }


        if (check_a == 1)
        {
            fortune_a_tab[i] = goal;
        }

        else
        {
            fortune_a_tab[i] = fortune_a;
        }

        i = i + 1;
    }

    for (i = 0 ; i < 1000 ; i = i + 1)
    {
        somme_t = somme_t + fortune_t_tab [i];
        somme_a = somme_a + fortune_a_tab [i];

    }

    moyenne_t = somme_t/1000;
    moyenne_a = somme_a/1000;

    printf("Approche timide : %f \n", moyenne_t);
    printf("Approche audacieuse : %f", moyenne_a);

    return 0;
}
