You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.2 KiB
38 lines
1.2 KiB
8 months ago
|
from math import sqrt #importe la racine carré
|
||
8 months ago
|
|
||
|
def reussite(name, act):
|
||
|
tirs = 0
|
||
|
tirs_reussies = 0
|
||
|
for read in table:
|
||
|
if read[0] == name and read[1][0] == act:
|
||
|
tirs += 1
|
||
|
if read[1][1][:3] == "reu":
|
||
|
tirs_reussies += 1
|
||
|
return tirs, tirs_reussies
|
||
|
|
||
|
def points(x, y):
|
||
8 months ago
|
return 2 if sqrt(x**2 + (y-300)**2) < 250 or sqrt((x-1000)**2 + (y-300)**2) < 250 else 3
|
||
8 months ago
|
|
||
|
def totalPoints(joueur):
|
||
|
total_points = 0
|
||
|
for read in table:
|
||
|
if read[0] == joueur and read[1][1] == "reussi":
|
||
|
total_points += points(int(read[2]), int(read[3]))
|
||
|
return total_points
|
||
|
|
||
|
|
||
|
# Lecture du fichier stats.txt
|
||
|
with open("stats.txt", "r") as stats_file:
|
||
|
stats = stats_file.readlines()
|
||
|
|
||
|
# Création de la table à partir des données lues
|
||
|
table = []
|
||
|
for line in stats:
|
||
|
table.append(line.split())
|
||
|
table[-1][1] = table[-1][1].split("-")
|
||
|
|
||
|
# Exemples d'utilisation
|
||
|
print(reussite("J2", "tir")) # Renvoie le nombre de tirs tentés et réussis par le joueur J1
|
||
|
print(points(83, 478)) # Renvoie le nombre de points marqués pour un point aux coordonnées (500, 400)
|
||
|
print(totalPoints("J2")) # Renvoie le nombre total de points marqués par le joueur J1
|