from random import *
import matplotlib.pyplot as plt

def direction():
    return randint(0,1)

def horizontal(x,y):
    plt.plot([x,x+1],[y,y],"r",linewidth=6)
    x=x+1
    return(x,y)

def vertical(x,y):
    plt.plot([x,x],[y,y+1],"r",linewidth=6)
    y=y+1
    return(x,y)

def repere():
    plt.plot(4,4,'bo',linewidth=20)
    plt.axis([0,5,0,5])
    plt.grid(True)

def robot(x,y,n):
    for k in range (1,n+1):
        d=direction()
        if d==1:
            x,y=horizontal(x,y)
        else:
            x,y=vertical(x,y)
    return (x,y)

def repetition(m):
    compteur=0
    for k in range (m):
        x,y=robot(0,0,8)
        if x==4 and y==4:
            compteur=compteur+1
    fq=compteur/m
    return fq