Fide Rating Calculate for Unrated

Fide Rating Calculate for Unrated Player


This is coding only to calculate rating for unrated player...
So, Get your results from chess results and paste in txt file like show in below....

Then copy and paste these code in your py file
and run it....

CODE:

with open('rating.txt', 'r') as file:
    result = [line.strip() for line in file]

dp = {"0" : "800",
"0.01" : "677",
"0.02" : "589",
"0.03" : "538",
"0.04" : "501",
"0.05" : "470",
"0.06" : "444",
"0.07" : "422",
"0.08" : "401",
"0.09" : "383",
"0.1" : "366",
"0.11" : "351",
"0.12" : "336",
"0.13" : "322",
"0.14" : "309",
"0.15" : "296",
"0.16" : "284",
"0.17" : "273",
"0.18" : "262",
"0.19" : "251",
"0.2" : "240",
"0.21" : "230",
"0.22" : "220",
"0.23" : "211",
"0.24" : "202",
"0.25" : "193",
"0.26" : "184",
"0.27" : "175",
"0.28" : "166",
"0.29" : "158",
"0.3" : "149",
"0.31" : "141",
"0.32" : "133",
"0.33" : "125",
"0.34" : "117",
"0.35" : "110",
"0.36" : "102",
"0.37" : "95",
"0.38" : "87",
"0.39" : "80",
"0.4" : "72",
"0.41" : "65",
"0.42" : "57",
"0.43" : "50",
"0.44" : "43",
"0.45" : "36",
"0.46" : "29",
"0.47" : "21",
"0.48" : "14",
"0.49" : "7"
    }

total_rating = 0
pts = 0
n_r = 0
for x in result:
    if len(x) == 10 or len(x) == 8:
        n_r += 1
        total_rating += int(x[0:4])
        if len(x) == 8:
            if x[7] == "1":
                pts += 1
        else:
            pts += 0.5

avg = int(total_rating / n_r)
avg_rating = n_r / 2


if n_r >= 5 and pts != 0:
    if avg_rating == pts:
        print("Your rating is " + str(avg))
    elif pts > avg_rating:
        y = pts - avg_rating
        avg = int(avg + (y * 40))
        print("Your rating is " + str(avg))
    else:
        z = pts / n_r
        a = round(z, 2)
        b = int(dp[str(a)])
        avg = avg - b
        print("Your Rating is " + str(avg))
else:
    print("You not fulfilled Fide rule, So no get rating...")

--------
End


Regards
PyKAR


Comments

Popular posts from this blog

Hardy - Ramanujan Number (Magic Number) Program in Python

FLAMES CODE ON PYTHON

Count Swap for Sorting in Python