<jupyter_start><jupyter_text>Chess game result prediction<jupyter_code>import numpy as np
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>Parameter for the game:<jupyter_code># Ratings (player 1 and player 2)
R1 = 1825
R2 = 1775

# rating difference
rd = R1 - R2
print('Rating difference rd = {}'.format(rd))

# rating average
ra = (R1 + R2)/2
print('Rating average ra = {}'.format(ra))<jupyter_output>Rating difference rd = 50
Rating average ra = 1800.0<jupyter_text>Draw rateThe rate of drawing depends of Rating Differece $rd$ and the Rating Average $ra$. At lower $rd$ and greater $ra$ the probability of a draw increases.According to http://kirill-kryukov.com/chess/kcec/draw_rate.html we can create a function to get the draw rate $dr$:<jupyter_code>def get_draw_rate(R1, R2):
    rd = np.abs(R1 - R2)
    ra = (R1 + R2)/2
    
    dr = -rd/32.49 + np.exp((ra-2254.7)/208.49)+23.87
    return dr/100
dr = get_draw_rate(R1, R2)
print('Drawing Rate dr = {:0.2f} %'.format(dr*100))<jupyter_output>Drawing Rate dr = 22.44 %<jupyter_text>Game result expectationThe probability that Player 1 wins is $P_{W1}$ is:$$P_{W1} = \frac{1}{1 + 10^{\frac{-rd}{400}}} - \frac{1}{2}dr$$The probability that Player 1 loses is $P_{L1}$ is:$$P_{L1} = \frac{1}{1 + 10^{\frac{rd}{400}}} - \frac{1}{2}dr$$<jupyter_code>def get_result_expectation(R1, R2):
    rd = R1 - R2
    dr = get_draw_rate(R1, R2)
    
    Pw = 1 / (1 + np.power(10, -1*rd/400)) - 0.5*dr
    Pl = 1 / (1 + np.power(10, rd/400)) - 0.5*dr
    Pd = dr
    return Pw, Pl, Pd
Pw1, Pl1, Pd1 = get_result_expectation(R1, R2)

print('Player 1 (ELO = {}):'.format(R1))
print('\tWin chances = {:0.2f} %'.format(Pw1*100))
print('\tLose chances = {:0.2f} %'.format(Pl1*100))
print('\tDraw chances = {:0.2f} %'.format(Pd1*100))
Pw2, Pl2, Pd2 = get_result_expectation(R2, R1)

print('Player 2 (ELO = {}):'.format(R2))
print('\tWin chances = {:0.2f} %'.format(Pw2*100))
print('\tLose chances = {:0.2f} %'.format(Pl2*100))
print('\tDraw chances = {:0.2f} %'.format(Pd2*100))<jupyter_output>Player 2 (ELO = 1775):
	Win chances = 31.63 %
	Lose chances = 45.92 %
	Draw chances = 22.44 %<jupyter_text>Probabilities vs ELO rate differenceThe probabilities curves are calculated depending of $ra$ value.<jupyter_code>rd_min = -600
rd_max = 600
N = 1000

rd_vals = np.linspace(rd_min, rd_max, N)
R1_vals = R1*np.ones(rd_vals.shape)
R2_vals = R1 - rd_vals

Pw, Pl, Pd = get_result_expectation(R1_vals, R2_vals)
plt.figure(figsize=(10,5))
plt.plot(rd_vals, Pw, label='Pw')
plt.plot(rd_vals, Pl, label='Pl')
plt.plot(rd_vals, Pd, label='Pd')
plt.grid()
plt.legend()
plt.ylim(0,1)
plt.title('Probabilities for Player 1')
plt.xlabel('Rate difference R1-R2')
plt.axvline(x=rd)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1740072202166065, 'fraction_numerical': 0.07328519855595668, 'mean_word_length': 4.689938398357289, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '399486', 'license': 'MIT', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1155, 'n_words': 271, 'path': 'GameResultEstimation.ipynb', 'repo_name': 'francof2a/ELO_multiplayer_match', 'size': '2770'}