﻿#   ----------------------
#   José OUIN
#   http://www.joseouin.fr
#   ----------------------

# Question Q2 : Quel est le temps moyen (nombre moyen de minutes) mis
# par la souris pour atteindre le fromage ?
# ------------------------

import numpy as np
from random import *
import matplotlib.pyplot as plt

N = 100000 # Nombre total d'essais
Ty =  np.zeros(101)
Tx = np.linspace(0,100,101)

Nk = 0 # Nombre d'essais
t = 0
P = "G" # Position Garage

def MouveMouse(X) :
    if X == "G" :
        NX = choice(["G","G","C","S"])
    elif X == "C" :
        NX = choice(["C","C","G","F"])
    elif X == "S" :
        NX = choice(["S","S","G","F"])
    else :
        NX = "F"
    return NX

while Nk < N  :
    #Mouvement
    P = MouveMouse(P)
    t =  t + 1
    if t > 100 :
        t = 0
        Nk = Nk + 1
        P = "G"
    elif P == "F" :
        Ty[t] = Ty[t] + 1
        t = 0
        Nk = Nk + 1
        P = "G"


Tm = sum(Tx*Ty/N)
Tf = Ty/N
print("Temps moyen Tm = ",Tm," minutes.")

plt.bar(Tx,Tf,align ='center', width = 0.7, color = 'r')
plt.show()