franc_carreau.py

Created by elnix91

Created on March 22, 2024

1.21 KB

Calcule la probabilité de gagner au jeu du franc carreau avec une carreau de 36 de coté et une pièce de 8 de rayon. ATTENTION ce programme n’est pas fini, ni optimisé et comporte plusieurs éléments en phase de test. Il peut en résulter des bugs ou d’autre disfonctionnements du même type.


from kandinsky import fill_rect as f,draw_string as d;from random import randrange as r;from ion import keydown as k
def croix(x,y,c):
  f(x-3,y,7,1,c)
  f(x,y-3,1,7,c)

SKY=(0,)*3
TXT=(255,)*3
V,T=0,0
first=1
x=0

f(0,0,320,222,SKY)
d("Taille du carreau:",65,50,(0,255,255),SKY)
while k(4)or k(56):1
while not (k(4)or k(56)):
  if k(0)or k(3)or first:
    if first:first=0
    x=(x+(k(3)-k(0)))%6
    d("  < "+str((x+1)*36)+" >  ",160-len(str((x+1)*36))*5-40,80,(0,255,0),SKY)
    while k(0)or k(3):1
#x+=1
x=1
#y=6-x
y=1
z=(222-y*x*36)//2
#print(222-y*x*36)
#print(x,y,z)

f(0,0,222,222,TXT)
f(z,z,x*y*36,x*y*36,SKY)
#d(str(z),310,0)

f(0,0,320,222,SKY)
d("Nombre",230,10,(0,0,255),SKY)
d("de tests:",230,30,(0,0,255),SKY)
d("Taux de",230,120,(0,255,0),SKY)
d("Victoires:",230,140,(0,255,0),SKY)

#if 1:
while 1:
#  for X in range(1,36*x+1):
#    for Y in range(1,36*x+1):
      X,Y=r(1,36*x),r(1,36*x)
#      c=(255,0,0)
      if X>=8*x+1 and X<=28*x:
        if Y>=8*x+1 and Y<=28*x:
          V+=1
#          c=(0,255,0)
#      croix(X*y,Y*y,c)
#      f(z+(X-1)*y,z+(Y-1)*y,1*y,1*y,c)
      T+=1
      d(str(T),240,60,TXT,SKY)
      d(str(V*100/T),240,170,TXT,SKY)
print(str(V)+" / "+str(T)+" = \n"+str(V*100/T))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.