{
  "id": 192,
  "title": "6th place(UriB) by Uri Blass",
  "content": "<P>I calculated rating for every player in months 101-105 and after having the rating I have a simple formula to calculate the expected result only based on the rating and the color.<BR>The tricks that I used were mainly in calculating the rating but I will start explaining the simple part.<BR><BR>The first part was calculating the bonus for white<BR><BR>I had the following formula for this part:<BR>bonus=maximum((white_rating+black_rating-3100)/40.0,50)<BR><BR>Diff=white_rating+bonus-black_rating&nbsp; <BR><BR>Expected_result=0.5+Diff/850 <BR>When I changed it to be not more than <FONT size=2>0.970588 and not less than 0.1(practically it had a very small effect&nbsp;<BR>because&nbsp;the result was always bigger than 0.1 and there was only one case when I needed to reduce it to 0.970588)</P>\r\n<P></FONT><BR>Now we go to the hard part that is how to calculate the rating for every player.<BR>For this purpose I admit that I used the future to predict the past(but I have also prediction based on a different model in the top 10 when I did not use the future to predict the past).<BR><BR>I used a function that I called repeat_strength_estimate<BR>The function get the following parameters:<BR>1)k that is the last month that is not missing.<BR>For the prediction of months 101-105 k=100 but for testing my parameters I used k=90,91,92,...99<BR>2)max_months(practically get the value 81 and I admit that it is not a good name)<BR>The meaning of max_months=81 is practically that I&nbsp;do not use the first 20 months to predict month 101 and that I do not use the first 21 months to predict month 102 and generally <BR>I do not use the first&nbsp;m-81 months to predict month number m.<BR><BR>3)<FONT size=2>big_dif=310<BR>big_dif was used to calculate performance rating and for some reason I found that small values give better results<BR>in my tests so I used this small value<BR><BR><FONT size=2>My formula for performance rating was</P>\r\n<P>performance_rating=avg_rating+((result-opponents)/opponents)*big_dif;<BR><BR>the value of the division can be at most 1 and at least -1 because result is practically weighted half points and is something between 0 and twice the weight of the opponent.<BR><BR>opponents in this formula mean the number of weight opponents(when the weight is based on the distance in month from&nbsp;the month to predict)&nbsp;&nbsp;<BR>This formula means that even if a player lost all the games against the opponents then he still got performance rating that is only 310 elo weaker than the average of the opponents because the result of the division is always between -1 for losing all games and 1 for winning all games.<BR></FONT></FONT><BR>I guess that it was good because not all games are included so person who played against strong opponents probably performed practically better than his real score and it is not good for the real world when games are not missing.<BR><BR>4)num_avg=5.9 similiar to chess metrics(I added 5.9 faked opponents with average rating)<BR><BR>5)num_weak=2.2(added 2.2 faked weak opponents)<BR><BR>6)<FONT size=2>value_weak=2210(rating of the weak opponents like chess metrics<BR><BR>7)<FONT size=2>unrated=2285(I think that practically had no effect because players always&nbsp;have games in the last 80 months)</P></FONT>\r\n<P></FONT><BR>8)<FONT size=2>minimal_game_finished=15(I reduce rating to players with less than 15 weighted games similiar to chess metrics)<BR><BR>9)reduction_per_game=12(the number that I reduce for less of experience for player without many weight games)<BR><BR>10)adding=39(the number that I add to rating of players after every iteration)<BR><BR>repeat_strength_estimate basically did 10 iterations for evaluating the strength of every player in every month.<BR></FONT>The evaluation of&nbsp;the strengh was based on 2 steps when step 1 was the function that calculate strength that is similiar to chess metrics but there are important differences and step 2 was deciding that place 50 has rating 2625 in the rating list that is exactly the same as chess metrics.<BR><BR><FONT size=2></P>\r\n<P>calc_strength_chess_metric is the missing function to understand the algorithm and it basically got 11 parameters(all the 10 parameters that repeat_strength_estimate got and another parameter that is the month that we calculate&nbsp;estimate for it).<BR><BR>Note that&nbsp;the&nbsp;estimate for month 50 of player 1 when months 101-105 are missing is important because if player 2 played with player 1 at month 50 <BR>then it is going to influence the rating of player 2&nbsp; at month 101-105 that is used to calculate the expected result.<BR><BR>I use the word estimate and not rating because rating by definition assume that we do not have future results.<BR><BR>I had basically 2 steps in<BR>calc_strength_chess_metric<BR><BR>The first step was a loop that calculated the estimate for strength for every player in the relevant month.<BR>The second step is a&nbsp;step that I used only when I needed to predict the strength in the missing months and it is practically unfair trick but not something that is forbidden in the competition because I used the information about games and not about the results in the supposed missing months to&nbsp;calculate changes in the rating estimate in these months.<BR></FONT><BR>I did not finish to explain my algorithm&nbsp;and I plan also to send code later but now I need only to explain the 2 steps of calc_strength_chess_metric to explain my algorithm and I will do it later in another post(this part of the program is only slightly more than 100 lines of code in C).<BR></P>",
  "comments": [
    {
      "id": 15765,
      "author_name": "JamesBennett",
      "author_url": "",
      "post_date": "2012-10-17T02:24:11.857000",
      "content": "<p>Thank you for sharing those very detailed steps. Your descriptions really made it easier for me to follow you. The amount of coding that went into that chess rating was crazy!</p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1250,
      "author_name": "Uri Blass",
      "author_url": "",
      "post_date": "2010-11-20T04:38:53",
      "content": "<P><FONT face=Verdana>The first thing that I am going to explain is the first step in my calc_strength_chess_metric function.<BR><BR>it was a loop when I calculated the strength for every player so how did I calculate the strength?<BR><BR>I used a special function that got 12 parameters(the same&nbsp;11 parameters that calc_strength_chess_mertics got and the id of the player to calculate the strength of it that had the name i)<BR><BR>This function simply did a loop on all months from 1-100 at distance of at most 80 months from the month to calculate strength for it <BR>except the missing 5 months.<BR><BR>For every possible month number k&nbsp;that player i played in it<BR>I had a weight&nbsp;that is calculated as<BR><BR>1-|<FONT size=2>month-k|/81 when month is the month that I need to calculate strength for it and k is the month of playing of player i.<BR></FONT><FONT size=2><BR>Every game in this month is calculated as 1-|month-k|/81 games<BR>and I also calculated weight result by multiply&nbsp;the result by that number(result before multiplying is 2 for win of i and 1 for draw&nbsp;and 0 for loss)<BR><BR>For every game I calculated <BR>weighted result and weighted opponent rating and weighted number of opponents that is 1-|month-k|/81 for every game.<BR><BR>I reduced&nbsp;0.03*weight from the weighted result if a player played with the white pieces and added the same&nbsp;number if the player played with the black&nbsp;pieces.<BR>The opponent rating&nbsp;is simply the strength&nbsp;of the player(this strength is 2000 in the first iteration when we have no data about it).<BR><BR>After&nbsp;calculating opponents opp_rating and result I simply use chess metrics formula<BR><BR>after doing all of&nbsp;it I also add for the missing months activity bonus based on the number of games in the end of this function(1.2*numgames when numgames is&nbsp;the number of games&nbsp;in the missing month&nbsp;for example to calculate strength at month 103 assuming months 101-105 are missing <BR>I add 1.2*number of games in months 101-103<BR><BR>This explain the&nbsp;first step but there is also a second step for updating the rating based on&nbsp;opponents in the missing months <BR><FONT size=2>and I use the function add_opp to update them.</P>\r\n<P></FONT><BR><BR>The idea of add_opp is that I&nbsp;compare&nbsp;rating of opponents in the missing 5 months and rating of opponents in the last 12 months that we have and increase rating if I find that the opponents in the future are stronger.<BR><BR>People who are interested in the exact formula may read the function add_opp that I attach in this post(I attach all the code when I commented out part of the code that was about the cross data and is not relevant to the prediction and &nbsp;pushed it to the end).<BR><BR>Note that I did not do much optimization of parameters and I suspect that different parameters could give me the first place.<BR><BR>Note that in order to run the program succesfully you need to have the files&nbsp;of the test data and the&nbsp;training data at the same file&nbsp;as the exe file that is based on the code that I attach.<BR>&nbsp;</P></FONT></FONT>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1251,
      "author_name": "Uri Blass",
      "author_url": "",
      "post_date": "2010-11-20T04:38:53",
      "content": "For some reason I do not find the attachment in the post I did and I witll try another time.<BR><BR>Edit:<BR>I think that in the second time I did a mistake and try to attach the exe file but I see no attachement&nbsp;even in my first&nbsp;post when I tried to attach only&nbsp;the code<BR>so I will attach the code of the missing function directly(I practically used the last 13 months and not the last 12 months)<BR><BR><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT></P></SPAN><FONT color=#0000ff size=2>\r\n<P></FONT></P></SPAN>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> add_opp(</SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">int</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> i,</SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">int</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> missing,</SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">int</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> month)\r\n<P>{</P><FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">int</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> k;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">int</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> num_oppon=0;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">int</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> num_oppon_past=0;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">double</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> opp_rating_past=0;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">int</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> num;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">double</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> opp_rating=0;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">double</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> past_rating=0;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">for</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (k=missing-12;k&lt;=missing;k++)\r\n<P>{</P><FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">if</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (k&gt;=0)\r\n<P>{</P><FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">if</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (num_opp[i][k][0]&gt;0)<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">for</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (num=1;num&lt;=num_opp[i][k][0];num++)\r\n<P>{</P>\r\n<P>opp_rating_past+=strength[num_opp[i][k][num]][k];</P>\r\n<P>num_oppon_past+=1;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>}</P><FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">for</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (k=missing+1;k&lt;=missing+5;k++)<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">if</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (num_opp[i][k][0]&gt;0)<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">for</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (num=1;num&lt;=num_opp[i][k][0];num++)\r\n<P>{</P>\r\n<P>opp_rating+=strength[num_opp[i][k][num]][k];</P>\r\n<P>num_oppon+=1;</P>\r\n<P>}</P><FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">if</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (num_oppon&gt;0)\r\n<P>opp_rating=opp_rating/num_oppon;</P><FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">else</SPAN></SPAN></P><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \">\r\n<P>opp_rating=strength[i][month];</P><FONT size=2>\r\n<P></FONT></P></SPAN>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">if</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (num_oppon_past&gt;0)\r\n<P>opp_rating_past=opp_rating_past/num_oppon_past;</P><FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">else</SPAN></SPAN></P><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \">\r\n<P>opp_rating=strength[i][month];</P><FONT size=2>\r\n<P></FONT></P></SPAN>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">if</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (opp_rating&gt;opp_rating_past+60)<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">return</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> 12;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">if</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (opp_rating<OPP_RATING_PAST-60)< P> <FONT size=2>\r\n<P></FONT></P></SPAN>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">return</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> -12;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">return</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (opp_rating-opp_rating_past)*0.2;</P>\r\n<P>}<BR><BR>Edit:last comment: It is possible that I could get the first place only by doing more iterations(considering the small distance to the first place)&nbsp;and it may be interesting to check it.<BR><BR>Unfortunately<BR>I did not think about doing more iterations in the last moment.</P></SPAN>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1257,
      "author_name": "Uri Blass",
      "author_url": "",
      "post_date": "2010-11-20T04:38:53",
      "content": "<FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>I decided to post all the code that I have for my best prediction in this competition directly<BR>so everybody can run the code and verify the results<BR><BR>#include</FONT></FONT><FONT size=2> </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>&lt;stdio.h&gt;</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>#include</FONT></FONT><FONT size=2> </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>&lt;stdlib.h&gt;</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>#include</FONT></FONT><FONT size=2> </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>&lt;assert.h&gt;</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>#include</FONT></FONT><FONT size=2> </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>&lt;memory.h&gt;</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>#include</FONT></FONT><FONT size=2> </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>&lt;math.h&gt;</P></FONT></FONT><FONT size=2>\r\n<P>FILE *stream_training, *stream_test;</P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>\r\n<P>//stream_test step1 test data,stream_training step 2 training_data</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>const</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> games_training=65053;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>const</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> games_test=7809;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>const</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> total_games=73062;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>const</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> aboveidnumber=8632;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> isplayer2[aboveidnumber];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 1</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> month_test[games_test];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 1</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> month[total_games];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 1</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> whiteplayer[total_games];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 1</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> blackplayer[total_games];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 1</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> whiteplayer_test[games_test];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 1</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> blackplayer_test[games_test];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 1</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> isplayer[aboveidnumber];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 2</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> result[total_games];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 2</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>float</FONT></FONT><FONT size=2> read_result[total_games];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 2</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> num_opp[aboveidnumber][106][40];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//third field start with number of players to play at constant after step 3</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> result_player[aboveidnumber];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 3</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> num_color[aboveidnumber][106][40];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 3</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> num_result[aboveidnumber][106][40];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 3</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> numgames[aboveidnumber][106];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 3</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> connected[aboveidnumber];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 3</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> observed_result[aboveidnumber][106];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 4</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> observed_result_small[aboveidnumber][106][5];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 4</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> experienced_players[total_games][5];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 4 is used to calculate the expected result</P>\r\n<P>//and get 1 only if the relevant game is by 2 players with at least 48 games to be considered for RMSE </P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> expected_result_small[aboveidnumber][106][5];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//initiailized in step 3 and is the expected result for RMSE</P>\r\n<P>//(calculated at step 6</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> strength[aboveidnumber][106];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//strength is based on all the data constant after step 5 that repeats itself</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> expect_result_game[total_games][5];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 6 and </P>\r\n<P>//used to calculate later the expected result and the expected_result_small tables</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> predicted[games_test];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//used only in the final step of the program to build the submission</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> expected_result[aboveidnumber][106];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//the expected result that include unexperienced players </P>\r\n<P>//initinalized in step 6 but I did not use it</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>const</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> whitecolor=0;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>const</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> blackcolor=1;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> read_test()</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 1 of the program that read the test data</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//for every game we have month white and black and it is also saved in the full data that include the training data</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2> c;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((stream_test = fopen(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"test_data.csv\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"r+b\"</FONT></FONT><FONT size=2>)) == NULL) {</P>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"The file 'test_data.csv' was not opened\\n\"</FONT></FONT><FONT size=2>);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2>;</P>\r\n<P>} </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"The file 'test_data.csv' was opened\\n\"</FONT></FONT><FONT size=2>);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (stream_test) {</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* start reading from stream */</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 1; i &lt; 53; i++) {</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; aboveidnumber; i++)</P>\r\n<P>isplayer2[i] = 0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; games_test; i++) {</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, &amp;month_test[i]);</P>\r\n<P>month[games_training+i]=month_test[i];</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, &amp;whiteplayer_test[i]);</P>\r\n<P>whiteplayer[games_training+i]=whiteplayer_test[i];</P>\r\n<P>isplayer2[whiteplayer_test[i]] = 1;</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, &amp;blackplayer_test[i]);</P>\r\n<P>blackplayer[games_training+i]=blackplayer_test[i];</P>\r\n<P>isplayer2[blackplayer_test[i]] = 1;</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c); </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* , */</P></FONT></FONT><FONT size=2>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c); </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* enter */</P></FONT></FONT><FONT size=2>\r\n<P>}</P>\r\n<P>fclose(stream_test);</P>\r\n<P>}</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> read_training_data()</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 2 read the training data for every game we have month white black and result </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2> c;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> sum_result=0;</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* start reading from stream */</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 1; i &lt; 53; i++) </P>\r\n<P>{</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, c);</P>\r\n<P>}</P>\r\n<P>memset(isplayer, 0, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>sizeof</FONT></FONT><FONT size=2>(isplayer));</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; games_training; i++) </P>\r\n<P>{</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, &amp;month[i]);</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, &amp;whiteplayer[i]);</P>\r\n<P>isplayer[whiteplayer[i]] = 1;</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, &amp;blackplayer[i]);</P>\r\n<P>isplayer[blackplayer[i]] = 1;</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%f\"</FONT></FONT><FONT size=2>, &amp;read_result[i]); </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* 0.5 */</P></FONT></FONT><FONT size=2>\r\n<P>result[i] = read_result[i];</P>\r\n<P>sum_result=sum_result+result[i];</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c); </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* enter */</P></FONT></FONT><FONT size=2>\r\n<P>}</P>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"sum is %f \"</FONT></FONT><FONT size=2>,sum_result);</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> fill_num_opp_array()</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 3 building the basic arrays</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//the arrays are:1)num_opp[num_player][num_month][0]</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//means number of opponents of player with id num_player in num_month</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//num_opp[num_player][num_month][j] for j&gt;0 means num_player of opponent number j at the same month</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//num_color[num_player][num_month][j] for the same j&gt;0 gives the color that num_player played in game number j of </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//month num_month</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//num_result of the same parameters means the result that the player got in the relevant game when win is 2</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//draw is 1 and loss is 0</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//result_player[i] means the total half points that i got in the training games</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i,j,k,num,sum;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> white,black;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> month1;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> diff;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> weight;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (j=1;j&lt;=100;j++)</P>\r\n<P>num_opp[i][0][j]=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;aboveidnumber;i++)</P>\r\n<P>result_player[i]=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;games_training+games_test;i++)</P>\r\n<P>{</P>\r\n<P>month1=month[i];</P>\r\n<P>white=whiteplayer[i];</P>\r\n<P>black=blackplayer[i];</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (i&lt;games_training)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (result[i] == 1)</P>\r\n<P>result_player[white] += 2;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</FONT></FONT><FONT size=2> </P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (result[i] == 0)</P>\r\n<P>result_player[black] += 2;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</FONT></FONT><FONT size=2> </P>\r\n<P>{</P>\r\n<P>result_player[white]++;</P>\r\n<P>result_player[black]++;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>num_opp[white][month1][0]++;</P>\r\n<P>num_opp[black][month1][0]++;</P>\r\n<P>num_opp[white][month1][num_opp[white][month1][0]]=black;</P>\r\n<P>num_color[white][month1][num_opp[white][month1][0]]=whitecolor;</P>\r\n<P>num_opp[black][month1][num_opp[black][month1][0]]=white;</P>\r\n<P>num_color[black][month1][num_opp[black][month1][0]]=blackcolor;</P>\r\n<P>num_result[white][month1][num_opp[white][month1][0]]=1;</P>\r\n<P>num_result[black][month1][num_opp[black][month1][0]]=1;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (result[i] == 1)</P>\r\n<P>{</P>\r\n<P>num_result[white][month1][num_opp[white][month1][0]]=2;</P>\r\n<P>num_result[black][month1][num_opp[black][month1][0]]=0;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (result[i]==0)</P>\r\n<P>{</P>\r\n<P>num_result[white][month1][num_opp[white][month1][0]]=0;</P>\r\n<P>num_result[black][month1][num_opp[black][month1][0]]=2;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//initialization of arrays like numgames that is the number of games of player i after j months</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//expected_result that is the expected result of player i after j months </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//and obsereved_result that is the observed result of player i after j months</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//connected means that the player is connected to all the player and the default value 0 means not connected</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; aboveidnumber; i++) </P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (j = 0; j &lt; 106; j++) </P>\r\n<P>{</P>\r\n<P>numgames[i][j] = 0;</P>\r\n<P>expected_result[i][j] = 0;</P>\r\n<P>observed_result[i][j] = 0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (k=0;k&lt;=4;k++)</P>\r\n<P>{</P>\r\n<P>observed_result_small[i][j][k]=0;</P>\r\n<P>expected_result_small[i][j][k]=0;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>connected[i] = 0;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//1 is connected and every player who played with 1 or played with a connected player is connected</P></FONT></FONT><FONT size=2>\r\n<P>connected[1] = 1;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (j = 0; j &lt; 5; j++) </P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; games_training; i++) </P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (connected[whiteplayer[i]] == 1)</P>\r\n<P>connected[blackplayer[i]] = 1;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (connected[blackplayer[i]] == 1)</P>\r\n<P>connected[whiteplayer[i]] = 1;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>sum = 0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; aboveidnumber; i++)</P>\r\n<P>sum = sum + connected[i];</P>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"connected=%d\\n\"</FONT></FONT><FONT size=2>, sum);</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//updating the numagames data to be correct</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//we need also to update expected and observed data</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; games_training+games_test; i++) </P>\r\n<P>{</P>\r\n<P>j = month[i];</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>while</FONT></FONT><FONT size=2> (j &lt;= 105) </P>\r\n<P>{</P>\r\n<P>numgames[whiteplayer[i]][j]++;</P>\r\n<P>numgames[blackplayer[i]][j]++;</P>\r\n<P>j++;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//counting players in the test data</P></FONT></FONT><FONT size=2>\r\n<P>sum = 0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; aboveidnumber; i++) </P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (isplayer2[i] == 1) </P>\r\n<P>sum++;</P>\r\n<P>}</P>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"players in test are %d \"</FONT></FONT><FONT size=2>, sum);</P>\r\n<P>&nbsp;</P>\r\n<P>}</P>\r\n<P>&nbsp;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> calc_observed()</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 4 calculating the observed result for every player in every month</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//do it only one time we already initialized the observed array to 0 do the same for</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//observe_small</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i,white,black,order,delay,start_check;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> observed;</P>\r\n<P>i=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>while</FONT></FONT><FONT size=2> (i &lt; games_training) </P>\r\n<P>{</P>\r\n<P>white = whiteplayer[i];</P>\r\n<P>black = blackplayer[i];</P>\r\n<P>order = month[i];</P>\r\n<P>observed = result[i];</P>\r\n<P>observed_result[white][order] += observed;</P>\r\n<P>observed_result[black][order] += (1 - observed);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (delay=1;delay&lt;=5;delay++)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//we are at month number order we have results of month number order-delay and not results of the next 5 months</P></FONT></FONT><FONT size=2>\r\n<P>experienced_players[i][delay-1]=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (order&gt;delay)</P>\r\n<P>{</P>\r\n<P>start_check=order-delay-48;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (start_check&lt;0)</P>\r\n<P>start_check=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((numgames[white][order-delay]-numgames[white][start_check]&gt;=12)&amp;&amp;</P>\r\n<P>(numgames[black][order-delay]-numgames[black][start_check]&gt;=12))</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//player, number month of playing,delay in predicting minus 1</P></FONT></FONT><FONT size=2>\r\n<P>observed_result_small[white][order][delay-1] += observed;</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//the observed results at month number order.</P></FONT></FONT><FONT size=2>\r\n<P>observed_result_small[black][order][delay-1] += (1 - observed);</P>\r\n<P>experienced_players[i][delay-1]=1;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>i++;</P>\r\n<P>}</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> is_candidate_chess_strength(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> month,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> missing,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> candidate)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> sum=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> monthmin=month-48;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> monthmax=month;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (monthmin&lt;0)</P>\r\n<P>{</P>\r\n<P>monthmin=0;</P>\r\n<P>monthmax=48;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((isplayer[i]==1)&amp;&amp;(numgames[i][monthmax]-numgames[i][monthmin]&gt;=10))</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (strength[i][month]&gt;=2625-candidate)</P>\r\n<P>sum++;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((sum&lt;50)&amp;&amp;(candidate&gt;=0))</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//increasing by candidate is needed and done because number 50 is not more than </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>// 2625-candidate&lt;2625</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (isplayer[i]==1) </P>\r\n<P>strength[i][month]+=candidate;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> 1;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((sum&gt;=50)&amp;&amp;(candidate&lt;0))</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//reducing by -candidate is needed and done because </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//there are 50 players with at least 2625-candidate&gt;2625</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (isplayer[i]==1) </P>\r\n<P>strength[i][month]+=candidate;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> 0;</P>\r\n<P>&nbsp;</P>\r\n<P>}</P>\r\n<P>&nbsp;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> fixplace50_chess_strength(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> month,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> missing)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> sum=0;</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//this function changes the rating of player number 50 to be 2625</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> candidate;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (is_candidate_chess_strength(month,missing,0)==1)</P>\r\n<P>candidate=1600;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P>candidate=-1600;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>while</FONT></FONT><FONT size=2> ((candidate&gt;0.001)||(candidate&lt;-0.001))</P>\r\n<P>{</P>\r\n<P>is_candidate_chess_strength(month,missing,candidate);</P>\r\n<P>candidate=candidate/2.0;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>&nbsp;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> calc_strength_chess_metric_specific(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> month,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> missing,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> max_months,</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> big_dif,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> num_avg, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> num_weak,</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> value_weak,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> unrated,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> adding,</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> minimal_game_finished,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> reduction_per_game,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//used for step 5</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//impotant function for the prediction because it is used to calculate rating</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> k;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> diff;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> num;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> result,opponents,weight,opp_rating,avg_rating,performance_rating,return_rating;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> special_weight;</P>\r\n<P>result=0;</P>\r\n<P>opponents=0;</P>\r\n<P>opp_rating=0;</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//results of month+1,month+2,month+3,month+4,month+5 are missing from the data</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (k=1;k&lt;=100;k++)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((k&lt;=missing)||(k&gt;=missing+6))</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//we consider only results of these months to calculate rating at month number month</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((k&gt;month-max_months)&amp;&amp;(k&lt;month+max_months))</P>\r\n<P>{</P>\r\n<P>&nbsp;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num_opp[i][k][0]&gt;0)</P>\r\n<P>{</P>\r\n<P>diff=month-k;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (diff&lt;0)</P>\r\n<P>diff=k-month;</P>\r\n<P>weight=1-(1.0/(max_months))*diff;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (num=1;num&lt;=num_opp[i][k][0];num++)</P>\r\n<P>{</P>\r\n<P>opponents+=weight;</P>\r\n<P>result+=(num_result[i][k][num]*weight); </P>\r\n<P>opp_rating+=(strength[num_opp[i][k][num]][k]*weight);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num_color[i][k][num]==whitecolor)</P>\r\n<P>result-=0.03*weight;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P>result+=0.03*weight;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>&nbsp;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (opponents&gt;0)</P>\r\n<P>{</P>\r\n<P>avg_rating=opp_rating/opponents;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (opponents&lt;minimal_game_finished)</P>\r\n<P>value_weak-=(minimal_game_finished-opponents)*reduction_per_game;</P>\r\n<P>performance_rating=avg_rating+((result-opponents)/opponents)*big_dif;</P>\r\n<P>return_rating=(performance_rating*opponents)+(avg_rating*num_avg)+(value_weak*num_weak);</P>\r\n<P>return_rating=return_rating/(opponents+num_avg+num_weak);</P>\r\n<P>return_rating+=adding;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P>return_rating=unrated;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((month&gt;missing)&amp;&amp;(month&lt;=missing+5))</P>\r\n<P>return_rating+=((numgames[i][month]-numgames[i][missing])*1.2);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> return_rating;</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> add_opp(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> missing,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> month)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> k;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> num_oppon=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> num_oppon_past=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> opp_rating_past=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> num;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> opp_rating=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> past_rating=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (k=missing-12;k&lt;=missing;k++)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (k&gt;=0)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num_opp[i][k][0]&gt;0)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (num=1;num&lt;=num_opp[i][k][0];num++)</P>\r\n<P>{</P>\r\n<P>opp_rating_past+=strength[num_opp[i][k][num]][k];</P>\r\n<P>num_oppon_past+=1;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (k=missing+1;k&lt;=missing+5;k++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num_opp[i][k][0]&gt;0)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (num=1;num&lt;=num_opp[i][k][0];num++)</P>\r\n<P>{</P>\r\n<P>opp_rating+=strength[num_opp[i][k][num]][k];</P>\r\n<P>num_oppon+=1;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num_oppon&gt;0)</P>\r\n<P>opp_rating=opp_rating/num_oppon;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P>opp_rating=strength[i][month];</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num_oppon_past&gt;0)</P>\r\n<P>opp_rating_past=opp_rating_past/num_oppon_past;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P>opp_rating=strength[i][month];</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (opp_rating&gt;opp_rating_past+60)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> 12;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (opp_rating&lt;opp_rating_past-60)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> -12;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> (opp_rating-opp_rating_past)*0.2;</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> calc_strength_chess_metric(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> month,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> missing,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> max_months,</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> big_dif,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> num_avg, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> num_weak,</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> value_weak,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> unrated,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> adding,</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> minimal_game_finished,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> reduction_per_game)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//used for step 5</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> temp_rating[aboveidnumber];</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=1;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (isplayer[i]==1)</P>\r\n<P>temp_rating[i]=calc_strength_chess_metric_specific(month,missing,max_months,big_dif,num_avg,num_weak,value_weak,</P>\r\n<P>unrated,adding,minimal_game_finished,reduction_per_game,i);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=1;i&lt;aboveidnumber;i++)</P>\r\n<P>{</P>\r\n<P>strength[i][month]=temp_rating[i];</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=1;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((month&gt;missing)&amp;&amp;(month&lt;=missing+5))</P>\r\n<P>strength[i][month]+=add_opp(i,missing,month);</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> repeat_strength_estimate(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> k,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> max_months,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> big_dif,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> num_avg,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> num_weak,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> value_weak,</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> unrated,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> minimal_game_finished,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> reduction_per_game,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> adding)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 5 calculating the rating estimate when months k+1,...k+5 are missing k can be 0-100</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i,j;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (j=0;j&lt;=105;j++)</P>\r\n<P>strength[i][j]=2000;</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//k is the last month when result is not missing for the estimate</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;100;i++)</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//i is the number of iteration</P></FONT></FONT><FONT size=2>\r\n<P>{</P>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\" %d \"</FONT></FONT><FONT size=2>,i);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (j=0;j&lt;=105;j++)</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//j is the month that we calculate rating for it.</P></FONT></FONT><FONT size=2>\r\n<P>{</P>\r\n<P>calc_strength_chess_metric(j,k,max_months,big_dif,num_avg,num_weak,value_weak,unrated,adding,</P>\r\n<P>minimal_game_finished,reduction_per_game);</P>\r\n<P>fixplace50_chess_strength(j,k);</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> expected_number2(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> diff,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> max_diff)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> num=0.5+(diff/(2*max_diff));</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//25/850=1/34</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num&gt;0.970588)</P>\r\n<P>num=0.970588;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num&lt;0.1)</P>\r\n<P>num=0.1;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> num;</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> expectedwhitechess_result(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> white,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> black,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> month)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//this function predicts the result of white and black in specific month</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//I currently use the rating but it is going to be changed</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> whiterating=strength[white][month];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//first missing month is 101 </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//in case of predicting and something else in other cases</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> blackrating=strength[black][month];</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> bonus=(whiterating+blackrating-3100)/40.0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (bonus&gt;50)</P>\r\n<P>bonus=50;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> expected_number2(whiterating+bonus-blackrating,425);</P>\r\n<P>}</P>\r\n<P>&nbsp;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> calc_expected(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> monthx)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//monthx+1,...monthx+5 are missing and we calculate expected result </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//for every player based on this information</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> white,black,order,i,delay,start_check,j;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> expected;</P>\r\n<P>i=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; aboveidnumber; i++) </P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (j = monthx; j &lt; monthx+5; j++) </P>\r\n<P>expected_result[i][j] = 0;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>while</FONT></FONT><FONT size=2> (month[i]&lt;=monthx)</P>\r\n<P>i++;</P>\r\n<P>&nbsp;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>while</FONT></FONT><FONT size=2> ((i&lt;games_training)&amp;&amp;(month[i]&gt;monthx)&amp;&amp;(month[i]&lt;=monthx+5))</P>\r\n<P>{</P>\r\n<P>white = whiteplayer[i];</P>\r\n<P>black = blackplayer[i];</P>\r\n<P>order = month[i];</P>\r\n<P>expected=expect_result_game[i][order-monthx-1];</P>\r\n<P>expected_result[white][order]+=expected;</P>\r\n<P>expected_result[black][order]+=(1-expected);</P>\r\n<P>delay=order-monthx;</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//1-5</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (experienced_players[i][delay-1]==1)</P>\r\n<P>{</P>\r\n<P>expected_result_small[white][order][delay-1] += expected;</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//the expected results at month number order.</P></FONT></FONT><FONT size=2>\r\n<P>expected_result_small[black][order][delay-1] += (1 - expected);</P>\r\n<P>}</P>\r\n<P>i++;</P>\r\n<P>}</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> calc_error_result_small(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> monthx,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> delay)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> order=monthx+delay;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> err;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> RMSE=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=1;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (isplayer[i]==1)</P>\r\n<P>{</P>\r\n<P>err=observed_result_small[i][order][delay-1]-expected_result_small[i][order][delay-1];</P>\r\n<P>RMSE+=err*err;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> RMSE;</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> build_expected_result(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> monthx)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 6</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//we build expected result table for monthx+1,...monthx+5 based on the rating list</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//first step is to build the expected_result table for month+1,...month+5 </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//based on strength in the relevant month and maybe more parameters that I will add later</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> white,black,i;</P>\r\n<P>i=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>while</FONT></FONT><FONT size=2> (i&lt;games_training)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((month[i]&gt;=monthx+1)&amp;&amp;(month[i]&lt;=monthx+5))</P>\r\n<P>{</P>\r\n<P>white=whiteplayer[i];</P>\r\n<P>black=blackplayer[i];</P>\r\n<P>expect_result_game[i][month[i]-monthx-1]=expectedwhitechess_result(white,black,month[i]);</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//should be improved but this is an initial version </P></FONT></FONT><FONT size=2>\r\n<P>}</P>\r\n<P>i++;</P>\r\n<P>}</P>\r\n<P>calc_expected(monthx);</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> build_stupid_csv_prediction()</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* submission.csv */</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2> c;</P>\r\n<P>FILE *stream_prediction = fopen(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"submission119.csv\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"w+b\"</FONT></FONT><FONT size=2>);</P>\r\n<P>stream_test = fopen(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"test_data.csv\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"r+b\"</FONT></FONT><FONT size=2>);</P>\r\n<P>assert(stream_prediction);</P>\r\n<P>assert(stream_test);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (stream_test == NULL || stream_prediction == NULL)</P>\r\n<P>{</P>\r\n<P>puts(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"Usage error:\\nfiles submission.cs and test_data.csv are expected to be available in the current working directory.\\n\"</FONT></FONT><FONT size=2>);</P>\r\n<P>exit(EXIT_FAILURE);</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 1; i &lt; 53; i++) {</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, c);</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; games_test; i++) {</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, month_test[i]);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>','</FONT></FONT><FONT size=2>);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, whiteplayer_test[i]);</P>\r\n<P>assert(whiteplayer[games_training+i]==whiteplayer_test[i]);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>','</FONT></FONT><FONT size=2>);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, blackplayer_test[i]);</P>\r\n<P>assert(blackplayer[games_training+i]==blackplayer_test[i]);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>','</FONT></FONT><FONT size=2>);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%f\"</FONT></FONT><FONT size=2>, predicted[i]);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>'\\n'</FONT></FONT><FONT size=2>);</P>\r\n<P>} </P>\r\n<P>fclose(stream_test);</P>\r\n<P>fclose(stream_prediction);</P>\r\n<P>}</P>\r\n<P>&nbsp;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> predicting_chess_metrics(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> white_bonus,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> max_diff)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//425</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> white,black;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; games_test; i++) </P>\r\n<P>{</P>\r\n<P>white = whiteplayer_test[i];</P>\r\n<P>black = blackplayer_test[i];</P>\r\n<P>predicted[i]=expectedwhitechess_result(white,black,month_test[i]);</P>\r\n<P>}</P>\r\n<P>build_stupid_csv_prediction();</P>\r\n<P>&nbsp;</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> main(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>void</FONT></FONT><FONT size=2>)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i,j;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> sum = 0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> sum_result=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> error=0;</P>\r\n<P>read_test();</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 1</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((stream_training = fopen(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"training_data.csv\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"r+b\"</FONT></FONT><FONT size=2>)) == NULL) </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* C4996 */</P></FONT></FONT><FONT size=2>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"The file 'training_data.csv' was not opened\\n\"</FONT></FONT><FONT size=2>);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"The file 'training_data.csv' was opened\\n\"</FONT></FONT><FONT size=2>);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (stream_training) </P>\r\n<P>{</P>\r\n<P>read_training_data();</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 2 </P></FONT></FONT><FONT size=2>\r\n<P>fill_num_opp_array();</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 3</P></FONT></FONT><FONT size=2>\r\n<P>calc_observed();</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 4</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=90;i&lt;=100;i++)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//i should be a parameter</P></FONT></FONT><FONT size=2>\r\n<P>&nbsp;</P>\r\n<P>repeat_strength_estimate(i,81,310,5.9,2.2,2210,2285,15,12,39);</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 5</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//months i+1,i+2,i+3,i+4,i+5 are missing and we need to predict them</P></FONT></FONT><FONT size=2>\r\n<P>build_expected_result(i);</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 6 this function is going to build </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//expected result table based on strength estimate(months i+1,...i+5 missing)</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (j=1;j&lt;=5;j++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((i+j)&lt;=100)</P>\r\n<P>error+=calc_error_result_small(i,j);</P>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\" error=%f \"</FONT></FONT><FONT size=2>,error);</P>\r\n<P>&nbsp;</P>\r\n<P>}</P>\r\n<P>predicting_chess_metrics(45,425);</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//bonus for white and maximal difference</P></FONT></FONT><FONT size=2>\r\n<P>fclose(stream_training);</P>\r\n<P>}</P>\r\n<P>}</P></FONT>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1258,
      "author_name": "Uri Blass",
      "author_url": "",
      "post_date": "2010-11-20T04:38:53",
      "content": "<P><FONT face=Verdana>only one correction of the code<BR><BR>The original code had<BR><FONT size=2><FONT color=#0000ff>for</FONT> (i=0;i&lt;10;i++)</FONT><FONT color=#008000><FONT color=#008000 size=2>//i is the number of iteration<BR><BR></FONT></FONT><BR><BR>I changed it to 100 iterations in the code that I posted.<BR>100 iterations probably give better result than the result that I got but&nbsp;not good enough for the first place(my tests suggest small improvement in predicting of less than 0.1%)&nbsp;.&nbsp;<FONT color=#008000 size=2><FONT color=#008000 size=2></P></FONT></FONT></FONT>",
      "votes": 0,
      "replies": []
    }
  ],
  "comment_count": 5,
  "messages": [
    {
      "id": 15765,
      "postDate": "2012-10-17T02:24:11.857Z",
      "content": "<p>Thank you for sharing those very detailed steps. Your descriptions really made it easier for me to follow you. The amount of coding that went into that chess rating was crazy!</p>"
    },
    {
      "id": 1248,
      "postDate": "2010-11-20T04:38:53Z",
      "content": "<P>I calculated rating for every player in months 101-105 and after having the rating I have a simple formula to calculate the expected result only based on the rating and the color.<BR>The tricks that I used were mainly in calculating the rating but I will start explaining the simple part.<BR><BR>The first part was calculating the bonus for white<BR><BR>I had the following formula for this part:<BR>bonus=maximum((white_rating+black_rating-3100)/40.0,50)<BR><BR>Diff=white_rating+bonus-black_rating&nbsp; <BR><BR>Expected_result=0.5+Diff/850 <BR>When I changed it to be not more than <FONT size=2>0.970588 and not less than 0.1(practically it had a very small effect&nbsp;<BR>because&nbsp;the result was always bigger than 0.1 and there was only one case when I needed to reduce it to 0.970588)</P>\r\n<P></FONT><BR>Now we go to the hard part that is how to calculate the rating for every player.<BR>For this purpose I admit that I used the future to predict the past(but I have also prediction based on a different model in the top 10 when I did not use the future to predict the past).<BR><BR>I used a function that I called repeat_strength_estimate<BR>The function get the following parameters:<BR>1)k that is the last month that is not missing.<BR>For the prediction of months 101-105 k=100 but for testing my parameters I used k=90,91,92,...99<BR>2)max_months(practically get the value 81 and I admit that it is not a good name)<BR>The meaning of max_months=81 is practically that I&nbsp;do not use the first 20 months to predict month 101 and that I do not use the first 21 months to predict month 102 and generally <BR>I do not use the first&nbsp;m-81 months to predict month number m.<BR><BR>3)<FONT size=2>big_dif=310<BR>big_dif was used to calculate performance rating and for some reason I found that small values give better results<BR>in my tests so I used this small value<BR><BR><FONT size=2>My formula for performance rating was</P>\r\n<P>performance_rating=avg_rating+((result-opponents)/opponents)*big_dif;<BR><BR>the value of the division can be at most 1 and at least -1 because result is practically weighted half points and is something between 0 and twice the weight of the opponent.<BR><BR>opponents in this formula mean the number of weight opponents(when the weight is based on the distance in month from&nbsp;the month to predict)&nbsp;&nbsp;<BR>This formula means that even if a player lost all the games against the opponents then he still got performance rating that is only 310 elo weaker than the average of the opponents because the result of the division is always between -1 for losing all games and 1 for winning all games.<BR></FONT></FONT><BR>I guess that it was good because not all games are included so person who played against strong opponents probably performed practically better than his real score and it is not good for the real world when games are not missing.<BR><BR>4)num_avg=5.9 similiar to chess metrics(I added 5.9 faked opponents with average rating)<BR><BR>5)num_weak=2.2(added 2.2 faked weak opponents)<BR><BR>6)<FONT size=2>value_weak=2210(rating of the weak opponents like chess metrics<BR><BR>7)<FONT size=2>unrated=2285(I think that practically had no effect because players always&nbsp;have games in the last 80 months)</P></FONT>\r\n<P></FONT><BR>8)<FONT size=2>minimal_game_finished=15(I reduce rating to players with less than 15 weighted games similiar to chess metrics)<BR><BR>9)reduction_per_game=12(the number that I reduce for less of experience for player without many weight games)<BR><BR>10)adding=39(the number that I add to rating of players after every iteration)<BR><BR>repeat_strength_estimate basically did 10 iterations for evaluating the strength of every player in every month.<BR></FONT>The evaluation of&nbsp;the strengh was based on 2 steps when step 1 was the function that calculate strength that is similiar to chess metrics but there are important differences and step 2 was deciding that place 50 has rating 2625 in the rating list that is exactly the same as chess metrics.<BR><BR><FONT size=2></P>\r\n<P>calc_strength_chess_metric is the missing function to understand the algorithm and it basically got 11 parameters(all the 10 parameters that repeat_strength_estimate got and another parameter that is the month that we calculate&nbsp;estimate for it).<BR><BR>Note that&nbsp;the&nbsp;estimate for month 50 of player 1 when months 101-105 are missing is important because if player 2 played with player 1 at month 50 <BR>then it is going to influence the rating of player 2&nbsp; at month 101-105 that is used to calculate the expected result.<BR><BR>I use the word estimate and not rating because rating by definition assume that we do not have future results.<BR><BR>I had basically 2 steps in<BR>calc_strength_chess_metric<BR><BR>The first step was a loop that calculated the estimate for strength for every player in the relevant month.<BR>The second step is a&nbsp;step that I used only when I needed to predict the strength in the missing months and it is practically unfair trick but not something that is forbidden in the competition because I used the information about games and not about the results in the supposed missing months to&nbsp;calculate changes in the rating estimate in these months.<BR></FONT><BR>I did not finish to explain my algorithm&nbsp;and I plan also to send code later but now I need only to explain the 2 steps of calc_strength_chess_metric to explain my algorithm and I will do it later in another post(this part of the program is only slightly more than 100 lines of code in C).<BR></P>"
    },
    {
      "id": 1250,
      "postDate": "2010-11-20T04:38:53Z",
      "content": "<P><FONT face=Verdana>The first thing that I am going to explain is the first step in my calc_strength_chess_metric function.<BR><BR>it was a loop when I calculated the strength for every player so how did I calculate the strength?<BR><BR>I used a special function that got 12 parameters(the same&nbsp;11 parameters that calc_strength_chess_mertics got and the id of the player to calculate the strength of it that had the name i)<BR><BR>This function simply did a loop on all months from 1-100 at distance of at most 80 months from the month to calculate strength for it <BR>except the missing 5 months.<BR><BR>For every possible month number k&nbsp;that player i played in it<BR>I had a weight&nbsp;that is calculated as<BR><BR>1-|<FONT size=2>month-k|/81 when month is the month that I need to calculate strength for it and k is the month of playing of player i.<BR></FONT><FONT size=2><BR>Every game in this month is calculated as 1-|month-k|/81 games<BR>and I also calculated weight result by multiply&nbsp;the result by that number(result before multiplying is 2 for win of i and 1 for draw&nbsp;and 0 for loss)<BR><BR>For every game I calculated <BR>weighted result and weighted opponent rating and weighted number of opponents that is 1-|month-k|/81 for every game.<BR><BR>I reduced&nbsp;0.03*weight from the weighted result if a player played with the white pieces and added the same&nbsp;number if the player played with the black&nbsp;pieces.<BR>The opponent rating&nbsp;is simply the strength&nbsp;of the player(this strength is 2000 in the first iteration when we have no data about it).<BR><BR>After&nbsp;calculating opponents opp_rating and result I simply use chess metrics formula<BR><BR>after doing all of&nbsp;it I also add for the missing months activity bonus based on the number of games in the end of this function(1.2*numgames when numgames is&nbsp;the number of games&nbsp;in the missing month&nbsp;for example to calculate strength at month 103 assuming months 101-105 are missing <BR>I add 1.2*number of games in months 101-103<BR><BR>This explain the&nbsp;first step but there is also a second step for updating the rating based on&nbsp;opponents in the missing months <BR><FONT size=2>and I use the function add_opp to update them.</P>\r\n<P></FONT><BR><BR>The idea of add_opp is that I&nbsp;compare&nbsp;rating of opponents in the missing 5 months and rating of opponents in the last 12 months that we have and increase rating if I find that the opponents in the future are stronger.<BR><BR>People who are interested in the exact formula may read the function add_opp that I attach in this post(I attach all the code when I commented out part of the code that was about the cross data and is not relevant to the prediction and &nbsp;pushed it to the end).<BR><BR>Note that I did not do much optimization of parameters and I suspect that different parameters could give me the first place.<BR><BR>Note that in order to run the program succesfully you need to have the files&nbsp;of the test data and the&nbsp;training data at the same file&nbsp;as the exe file that is based on the code that I attach.<BR>&nbsp;</P></FONT></FONT>"
    },
    {
      "id": 1251,
      "postDate": "2010-11-20T04:38:53Z",
      "content": "For some reason I do not find the attachment in the post I did and I witll try another time.<BR><BR>Edit:<BR>I think that in the second time I did a mistake and try to attach the exe file but I see no attachement&nbsp;even in my first&nbsp;post when I tried to attach only&nbsp;the code<BR>so I will attach the code of the missing function directly(I practically used the last 13 months and not the last 12 months)<BR><BR><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT></P></SPAN><FONT color=#0000ff size=2>\r\n<P></FONT></P></SPAN>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> add_opp(</SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">int</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> i,</SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">int</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> missing,</SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">int</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> month)\r\n<P>{</P><FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">int</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> k;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">int</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> num_oppon=0;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">int</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> num_oppon_past=0;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">double</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> opp_rating_past=0;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">int</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> num;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">double</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> opp_rating=0;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">double</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> past_rating=0;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">for</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (k=missing-12;k&lt;=missing;k++)\r\n<P>{</P><FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">if</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (k&gt;=0)\r\n<P>{</P><FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">if</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (num_opp[i][k][0]&gt;0)<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">for</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (num=1;num&lt;=num_opp[i][k][0];num++)\r\n<P>{</P>\r\n<P>opp_rating_past+=strength[num_opp[i][k][num]][k];</P>\r\n<P>num_oppon_past+=1;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>}</P><FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">for</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (k=missing+1;k&lt;=missing+5;k++)<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">if</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (num_opp[i][k][0]&gt;0)<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">for</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (num=1;num&lt;=num_opp[i][k][0];num++)\r\n<P>{</P>\r\n<P>opp_rating+=strength[num_opp[i][k][num]][k];</P>\r\n<P>num_oppon+=1;</P>\r\n<P>}</P><FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">if</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (num_oppon&gt;0)\r\n<P>opp_rating=opp_rating/num_oppon;</P><FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">else</SPAN></SPAN></P><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \">\r\n<P>opp_rating=strength[i][month];</P><FONT size=2>\r\n<P></FONT></P></SPAN>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">if</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (num_oppon_past&gt;0)\r\n<P>opp_rating_past=opp_rating_past/num_oppon_past;</P><FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">else</SPAN></SPAN></P><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \">\r\n<P>opp_rating=strength[i][month];</P><FONT size=2>\r\n<P></FONT></P></SPAN>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">if</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (opp_rating&gt;opp_rating_past+60)<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">return</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> 12;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">if</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (opp_rating<OPP_RATING_PAST-60)< P> <FONT size=2>\r\n<P></FONT></P></SPAN>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">return</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> -12;<FONT size=2>\r\n<P></FONT></P></SPAN></P>\r\n<P><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \"><SPAN class=\"\" style=\"FONT-SIZE: x-small; COLOR: #0000ff; FONT-FAMILY: \">return</SPAN></SPAN><SPAN class=\"\" style=\"FONT-SIZE: x-small; FONT-FAMILY: \"> (opp_rating-opp_rating_past)*0.2;</P>\r\n<P>}<BR><BR>Edit:last comment: It is possible that I could get the first place only by doing more iterations(considering the small distance to the first place)&nbsp;and it may be interesting to check it.<BR><BR>Unfortunately<BR>I did not think about doing more iterations in the last moment.</P></SPAN>"
    },
    {
      "id": 1257,
      "postDate": "2010-11-20T04:38:53Z",
      "content": "<FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>I decided to post all the code that I have for my best prediction in this competition directly<BR>so everybody can run the code and verify the results<BR><BR>#include</FONT></FONT><FONT size=2> </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>&lt;stdio.h&gt;</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>#include</FONT></FONT><FONT size=2> </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>&lt;stdlib.h&gt;</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>#include</FONT></FONT><FONT size=2> </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>&lt;assert.h&gt;</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>#include</FONT></FONT><FONT size=2> </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>&lt;memory.h&gt;</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>#include</FONT></FONT><FONT size=2> </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>&lt;math.h&gt;</P></FONT></FONT><FONT size=2>\r\n<P>FILE *stream_training, *stream_test;</P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>\r\n<P>//stream_test step1 test data,stream_training step 2 training_data</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>const</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> games_training=65053;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>const</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> games_test=7809;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>const</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> total_games=73062;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>const</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> aboveidnumber=8632;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> isplayer2[aboveidnumber];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 1</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> month_test[games_test];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 1</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> month[total_games];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 1</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> whiteplayer[total_games];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 1</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> blackplayer[total_games];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 1</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> whiteplayer_test[games_test];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 1</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> blackplayer_test[games_test];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 1</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> isplayer[aboveidnumber];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 2</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> result[total_games];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 2</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>float</FONT></FONT><FONT size=2> read_result[total_games];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 2</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> num_opp[aboveidnumber][106][40];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//third field start with number of players to play at constant after step 3</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> result_player[aboveidnumber];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 3</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> num_color[aboveidnumber][106][40];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 3</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> num_result[aboveidnumber][106][40];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 3</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> numgames[aboveidnumber][106];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 3</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> connected[aboveidnumber];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 3</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> observed_result[aboveidnumber][106];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 4</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> observed_result_small[aboveidnumber][106][5];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 4</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> experienced_players[total_games][5];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 4 is used to calculate the expected result</P>\r\n<P>//and get 1 only if the relevant game is by 2 players with at least 48 games to be considered for RMSE </P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> expected_result_small[aboveidnumber][106][5];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//initiailized in step 3 and is the expected result for RMSE</P>\r\n<P>//(calculated at step 6</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> strength[aboveidnumber][106];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//strength is based on all the data constant after step 5 that repeats itself</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> expect_result_game[total_games][5];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//constant after step 6 and </P>\r\n<P>//used to calculate later the expected result and the expected_result_small tables</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> predicted[games_test];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//used only in the final step of the program to build the submission</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> expected_result[aboveidnumber][106];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//the expected result that include unexperienced players </P>\r\n<P>//initinalized in step 6 but I did not use it</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>const</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> whitecolor=0;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>const</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> blackcolor=1;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> read_test()</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 1 of the program that read the test data</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//for every game we have month white and black and it is also saved in the full data that include the training data</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2> c;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((stream_test = fopen(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"test_data.csv\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"r+b\"</FONT></FONT><FONT size=2>)) == NULL) {</P>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"The file 'test_data.csv' was not opened\\n\"</FONT></FONT><FONT size=2>);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2>;</P>\r\n<P>} </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"The file 'test_data.csv' was opened\\n\"</FONT></FONT><FONT size=2>);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (stream_test) {</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* start reading from stream */</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 1; i &lt; 53; i++) {</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; aboveidnumber; i++)</P>\r\n<P>isplayer2[i] = 0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; games_test; i++) {</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, &amp;month_test[i]);</P>\r\n<P>month[games_training+i]=month_test[i];</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, &amp;whiteplayer_test[i]);</P>\r\n<P>whiteplayer[games_training+i]=whiteplayer_test[i];</P>\r\n<P>isplayer2[whiteplayer_test[i]] = 1;</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, &amp;blackplayer_test[i]);</P>\r\n<P>blackplayer[games_training+i]=blackplayer_test[i];</P>\r\n<P>isplayer2[blackplayer_test[i]] = 1;</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c); </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* , */</P></FONT></FONT><FONT size=2>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c); </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* enter */</P></FONT></FONT><FONT size=2>\r\n<P>}</P>\r\n<P>fclose(stream_test);</P>\r\n<P>}</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> read_training_data()</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 2 read the training data for every game we have month white black and result </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2> c;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> sum_result=0;</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* start reading from stream */</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 1; i &lt; 53; i++) </P>\r\n<P>{</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, c);</P>\r\n<P>}</P>\r\n<P>memset(isplayer, 0, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>sizeof</FONT></FONT><FONT size=2>(isplayer));</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; games_training; i++) </P>\r\n<P>{</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, &amp;month[i]);</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, &amp;whiteplayer[i]);</P>\r\n<P>isplayer[whiteplayer[i]] = 1;</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, &amp;blackplayer[i]);</P>\r\n<P>isplayer[blackplayer[i]] = 1;</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%f\"</FONT></FONT><FONT size=2>, &amp;read_result[i]); </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* 0.5 */</P></FONT></FONT><FONT size=2>\r\n<P>result[i] = read_result[i];</P>\r\n<P>sum_result=sum_result+result[i];</P>\r\n<P>fscanf(stream_training, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c); </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* enter */</P></FONT></FONT><FONT size=2>\r\n<P>}</P>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"sum is %f \"</FONT></FONT><FONT size=2>,sum_result);</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> fill_num_opp_array()</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 3 building the basic arrays</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//the arrays are:1)num_opp[num_player][num_month][0]</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//means number of opponents of player with id num_player in num_month</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//num_opp[num_player][num_month][j] for j&gt;0 means num_player of opponent number j at the same month</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//num_color[num_player][num_month][j] for the same j&gt;0 gives the color that num_player played in game number j of </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//month num_month</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//num_result of the same parameters means the result that the player got in the relevant game when win is 2</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//draw is 1 and loss is 0</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//result_player[i] means the total half points that i got in the training games</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i,j,k,num,sum;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> white,black;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> month1;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> diff;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> weight;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (j=1;j&lt;=100;j++)</P>\r\n<P>num_opp[i][0][j]=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;aboveidnumber;i++)</P>\r\n<P>result_player[i]=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;games_training+games_test;i++)</P>\r\n<P>{</P>\r\n<P>month1=month[i];</P>\r\n<P>white=whiteplayer[i];</P>\r\n<P>black=blackplayer[i];</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (i&lt;games_training)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (result[i] == 1)</P>\r\n<P>result_player[white] += 2;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</FONT></FONT><FONT size=2> </P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (result[i] == 0)</P>\r\n<P>result_player[black] += 2;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</FONT></FONT><FONT size=2> </P>\r\n<P>{</P>\r\n<P>result_player[white]++;</P>\r\n<P>result_player[black]++;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>num_opp[white][month1][0]++;</P>\r\n<P>num_opp[black][month1][0]++;</P>\r\n<P>num_opp[white][month1][num_opp[white][month1][0]]=black;</P>\r\n<P>num_color[white][month1][num_opp[white][month1][0]]=whitecolor;</P>\r\n<P>num_opp[black][month1][num_opp[black][month1][0]]=white;</P>\r\n<P>num_color[black][month1][num_opp[black][month1][0]]=blackcolor;</P>\r\n<P>num_result[white][month1][num_opp[white][month1][0]]=1;</P>\r\n<P>num_result[black][month1][num_opp[black][month1][0]]=1;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (result[i] == 1)</P>\r\n<P>{</P>\r\n<P>num_result[white][month1][num_opp[white][month1][0]]=2;</P>\r\n<P>num_result[black][month1][num_opp[black][month1][0]]=0;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (result[i]==0)</P>\r\n<P>{</P>\r\n<P>num_result[white][month1][num_opp[white][month1][0]]=0;</P>\r\n<P>num_result[black][month1][num_opp[black][month1][0]]=2;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//initialization of arrays like numgames that is the number of games of player i after j months</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//expected_result that is the expected result of player i after j months </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//and obsereved_result that is the observed result of player i after j months</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//connected means that the player is connected to all the player and the default value 0 means not connected</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; aboveidnumber; i++) </P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (j = 0; j &lt; 106; j++) </P>\r\n<P>{</P>\r\n<P>numgames[i][j] = 0;</P>\r\n<P>expected_result[i][j] = 0;</P>\r\n<P>observed_result[i][j] = 0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (k=0;k&lt;=4;k++)</P>\r\n<P>{</P>\r\n<P>observed_result_small[i][j][k]=0;</P>\r\n<P>expected_result_small[i][j][k]=0;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>connected[i] = 0;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//1 is connected and every player who played with 1 or played with a connected player is connected</P></FONT></FONT><FONT size=2>\r\n<P>connected[1] = 1;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (j = 0; j &lt; 5; j++) </P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; games_training; i++) </P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (connected[whiteplayer[i]] == 1)</P>\r\n<P>connected[blackplayer[i]] = 1;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (connected[blackplayer[i]] == 1)</P>\r\n<P>connected[whiteplayer[i]] = 1;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>sum = 0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; aboveidnumber; i++)</P>\r\n<P>sum = sum + connected[i];</P>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"connected=%d\\n\"</FONT></FONT><FONT size=2>, sum);</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//updating the numagames data to be correct</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//we need also to update expected and observed data</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; games_training+games_test; i++) </P>\r\n<P>{</P>\r\n<P>j = month[i];</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>while</FONT></FONT><FONT size=2> (j &lt;= 105) </P>\r\n<P>{</P>\r\n<P>numgames[whiteplayer[i]][j]++;</P>\r\n<P>numgames[blackplayer[i]][j]++;</P>\r\n<P>j++;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//counting players in the test data</P></FONT></FONT><FONT size=2>\r\n<P>sum = 0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; aboveidnumber; i++) </P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (isplayer2[i] == 1) </P>\r\n<P>sum++;</P>\r\n<P>}</P>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"players in test are %d \"</FONT></FONT><FONT size=2>, sum);</P>\r\n<P>&nbsp;</P>\r\n<P>}</P>\r\n<P>&nbsp;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> calc_observed()</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 4 calculating the observed result for every player in every month</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//do it only one time we already initialized the observed array to 0 do the same for</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//observe_small</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i,white,black,order,delay,start_check;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> observed;</P>\r\n<P>i=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>while</FONT></FONT><FONT size=2> (i &lt; games_training) </P>\r\n<P>{</P>\r\n<P>white = whiteplayer[i];</P>\r\n<P>black = blackplayer[i];</P>\r\n<P>order = month[i];</P>\r\n<P>observed = result[i];</P>\r\n<P>observed_result[white][order] += observed;</P>\r\n<P>observed_result[black][order] += (1 - observed);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (delay=1;delay&lt;=5;delay++)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//we are at month number order we have results of month number order-delay and not results of the next 5 months</P></FONT></FONT><FONT size=2>\r\n<P>experienced_players[i][delay-1]=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (order&gt;delay)</P>\r\n<P>{</P>\r\n<P>start_check=order-delay-48;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (start_check&lt;0)</P>\r\n<P>start_check=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((numgames[white][order-delay]-numgames[white][start_check]&gt;=12)&amp;&amp;</P>\r\n<P>(numgames[black][order-delay]-numgames[black][start_check]&gt;=12))</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//player, number month of playing,delay in predicting minus 1</P></FONT></FONT><FONT size=2>\r\n<P>observed_result_small[white][order][delay-1] += observed;</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//the observed results at month number order.</P></FONT></FONT><FONT size=2>\r\n<P>observed_result_small[black][order][delay-1] += (1 - observed);</P>\r\n<P>experienced_players[i][delay-1]=1;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>i++;</P>\r\n<P>}</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> is_candidate_chess_strength(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> month,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> missing,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> candidate)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> sum=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> monthmin=month-48;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> monthmax=month;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (monthmin&lt;0)</P>\r\n<P>{</P>\r\n<P>monthmin=0;</P>\r\n<P>monthmax=48;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((isplayer[i]==1)&amp;&amp;(numgames[i][monthmax]-numgames[i][monthmin]&gt;=10))</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (strength[i][month]&gt;=2625-candidate)</P>\r\n<P>sum++;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((sum&lt;50)&amp;&amp;(candidate&gt;=0))</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//increasing by candidate is needed and done because number 50 is not more than </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>// 2625-candidate&lt;2625</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (isplayer[i]==1) </P>\r\n<P>strength[i][month]+=candidate;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> 1;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((sum&gt;=50)&amp;&amp;(candidate&lt;0))</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//reducing by -candidate is needed and done because </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//there are 50 players with at least 2625-candidate&gt;2625</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (isplayer[i]==1) </P>\r\n<P>strength[i][month]+=candidate;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> 0;</P>\r\n<P>&nbsp;</P>\r\n<P>}</P>\r\n<P>&nbsp;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> fixplace50_chess_strength(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> month,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> missing)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> sum=0;</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//this function changes the rating of player number 50 to be 2625</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> candidate;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (is_candidate_chess_strength(month,missing,0)==1)</P>\r\n<P>candidate=1600;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P>candidate=-1600;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>while</FONT></FONT><FONT size=2> ((candidate&gt;0.001)||(candidate&lt;-0.001))</P>\r\n<P>{</P>\r\n<P>is_candidate_chess_strength(month,missing,candidate);</P>\r\n<P>candidate=candidate/2.0;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>&nbsp;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> calc_strength_chess_metric_specific(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> month,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> missing,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> max_months,</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> big_dif,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> num_avg, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> num_weak,</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> value_weak,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> unrated,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> adding,</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> minimal_game_finished,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> reduction_per_game,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//used for step 5</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//impotant function for the prediction because it is used to calculate rating</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> k;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> diff;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> num;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> result,opponents,weight,opp_rating,avg_rating,performance_rating,return_rating;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> special_weight;</P>\r\n<P>result=0;</P>\r\n<P>opponents=0;</P>\r\n<P>opp_rating=0;</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//results of month+1,month+2,month+3,month+4,month+5 are missing from the data</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (k=1;k&lt;=100;k++)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((k&lt;=missing)||(k&gt;=missing+6))</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//we consider only results of these months to calculate rating at month number month</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((k&gt;month-max_months)&amp;&amp;(k&lt;month+max_months))</P>\r\n<P>{</P>\r\n<P>&nbsp;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num_opp[i][k][0]&gt;0)</P>\r\n<P>{</P>\r\n<P>diff=month-k;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (diff&lt;0)</P>\r\n<P>diff=k-month;</P>\r\n<P>weight=1-(1.0/(max_months))*diff;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (num=1;num&lt;=num_opp[i][k][0];num++)</P>\r\n<P>{</P>\r\n<P>opponents+=weight;</P>\r\n<P>result+=(num_result[i][k][num]*weight); </P>\r\n<P>opp_rating+=(strength[num_opp[i][k][num]][k]*weight);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num_color[i][k][num]==whitecolor)</P>\r\n<P>result-=0.03*weight;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P>result+=0.03*weight;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>&nbsp;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (opponents&gt;0)</P>\r\n<P>{</P>\r\n<P>avg_rating=opp_rating/opponents;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (opponents&lt;minimal_game_finished)</P>\r\n<P>value_weak-=(minimal_game_finished-opponents)*reduction_per_game;</P>\r\n<P>performance_rating=avg_rating+((result-opponents)/opponents)*big_dif;</P>\r\n<P>return_rating=(performance_rating*opponents)+(avg_rating*num_avg)+(value_weak*num_weak);</P>\r\n<P>return_rating=return_rating/(opponents+num_avg+num_weak);</P>\r\n<P>return_rating+=adding;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P>return_rating=unrated;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((month&gt;missing)&amp;&amp;(month&lt;=missing+5))</P>\r\n<P>return_rating+=((numgames[i][month]-numgames[i][missing])*1.2);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> return_rating;</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> add_opp(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> missing,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> month)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> k;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> num_oppon=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> num_oppon_past=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> opp_rating_past=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> num;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> opp_rating=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> past_rating=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (k=missing-12;k&lt;=missing;k++)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (k&gt;=0)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num_opp[i][k][0]&gt;0)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (num=1;num&lt;=num_opp[i][k][0];num++)</P>\r\n<P>{</P>\r\n<P>opp_rating_past+=strength[num_opp[i][k][num]][k];</P>\r\n<P>num_oppon_past+=1;</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (k=missing+1;k&lt;=missing+5;k++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num_opp[i][k][0]&gt;0)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (num=1;num&lt;=num_opp[i][k][0];num++)</P>\r\n<P>{</P>\r\n<P>opp_rating+=strength[num_opp[i][k][num]][k];</P>\r\n<P>num_oppon+=1;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num_oppon&gt;0)</P>\r\n<P>opp_rating=opp_rating/num_oppon;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P>opp_rating=strength[i][month];</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num_oppon_past&gt;0)</P>\r\n<P>opp_rating_past=opp_rating_past/num_oppon_past;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P>opp_rating=strength[i][month];</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (opp_rating&gt;opp_rating_past+60)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> 12;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (opp_rating&lt;opp_rating_past-60)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> -12;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> (opp_rating-opp_rating_past)*0.2;</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> calc_strength_chess_metric(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> month,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> missing,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> max_months,</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> big_dif,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> num_avg, </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> num_weak,</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> value_weak,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> unrated,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> adding,</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> minimal_game_finished,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> reduction_per_game)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//used for step 5</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> temp_rating[aboveidnumber];</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=1;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (isplayer[i]==1)</P>\r\n<P>temp_rating[i]=calc_strength_chess_metric_specific(month,missing,max_months,big_dif,num_avg,num_weak,value_weak,</P>\r\n<P>unrated,adding,minimal_game_finished,reduction_per_game,i);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=1;i&lt;aboveidnumber;i++)</P>\r\n<P>{</P>\r\n<P>strength[i][month]=temp_rating[i];</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=1;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((month&gt;missing)&amp;&amp;(month&lt;=missing+5))</P>\r\n<P>strength[i][month]+=add_opp(i,missing,month);</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> repeat_strength_estimate(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> k,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> max_months,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> big_dif,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> num_avg,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> num_weak,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> value_weak,</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> unrated,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> minimal_game_finished,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> reduction_per_game,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> adding)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 5 calculating the rating estimate when months k+1,...k+5 are missing k can be 0-100</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i,j;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (j=0;j&lt;=105;j++)</P>\r\n<P>strength[i][j]=2000;</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//k is the last month when result is not missing for the estimate</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=0;i&lt;100;i++)</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//i is the number of iteration</P></FONT></FONT><FONT size=2>\r\n<P>{</P>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\" %d \"</FONT></FONT><FONT size=2>,i);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (j=0;j&lt;=105;j++)</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//j is the month that we calculate rating for it.</P></FONT></FONT><FONT size=2>\r\n<P>{</P>\r\n<P>calc_strength_chess_metric(j,k,max_months,big_dif,num_avg,num_weak,value_weak,unrated,adding,</P>\r\n<P>minimal_game_finished,reduction_per_game);</P>\r\n<P>fixplace50_chess_strength(j,k);</P>\r\n<P>}</P>\r\n<P>}</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> expected_number2(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> diff,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> max_diff)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> num=0.5+(diff/(2*max_diff));</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//25/850=1/34</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num&gt;0.970588)</P>\r\n<P>num=0.970588;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (num&lt;0.1)</P>\r\n<P>num=0.1;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> num;</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> expectedwhitechess_result(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> white,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> black,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> month)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//this function predicts the result of white and black in specific month</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//I currently use the rating but it is going to be changed</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> whiterating=strength[white][month];</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//first missing month is 101 </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//in case of predicting and something else in other cases</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> blackrating=strength[black][month];</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> bonus=(whiterating+blackrating-3100)/40.0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (bonus&gt;50)</P>\r\n<P>bonus=50;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> expected_number2(whiterating+bonus-blackrating,425);</P>\r\n<P>}</P>\r\n<P>&nbsp;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> calc_expected(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> monthx)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//monthx+1,...monthx+5 are missing and we calculate expected result </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//for every player based on this information</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> white,black,order,i,delay,start_check,j;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> expected;</P>\r\n<P>i=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; aboveidnumber; i++) </P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (j = monthx; j &lt; monthx+5; j++) </P>\r\n<P>expected_result[i][j] = 0;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>while</FONT></FONT><FONT size=2> (month[i]&lt;=monthx)</P>\r\n<P>i++;</P>\r\n<P>&nbsp;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>while</FONT></FONT><FONT size=2> ((i&lt;games_training)&amp;&amp;(month[i]&gt;monthx)&amp;&amp;(month[i]&lt;=monthx+5))</P>\r\n<P>{</P>\r\n<P>white = whiteplayer[i];</P>\r\n<P>black = blackplayer[i];</P>\r\n<P>order = month[i];</P>\r\n<P>expected=expect_result_game[i][order-monthx-1];</P>\r\n<P>expected_result[white][order]+=expected;</P>\r\n<P>expected_result[black][order]+=(1-expected);</P>\r\n<P>delay=order-monthx;</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//1-5</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (experienced_players[i][delay-1]==1)</P>\r\n<P>{</P>\r\n<P>expected_result_small[white][order][delay-1] += expected;</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//the expected results at month number order.</P></FONT></FONT><FONT size=2>\r\n<P>expected_result_small[black][order][delay-1] += (1 - expected);</P>\r\n<P>}</P>\r\n<P>i++;</P>\r\n<P>}</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>double</FONT></FONT><FONT size=2> calc_error_result_small(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> monthx,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> delay)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> order=monthx+delay;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> err;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> RMSE=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=1;i&lt;aboveidnumber;i++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (isplayer[i]==1)</P>\r\n<P>{</P>\r\n<P>err=observed_result_small[i][order][delay-1]-expected_result_small[i][order][delay-1];</P>\r\n<P>RMSE+=err*err;</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> RMSE;</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> build_expected_result(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> monthx)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 6</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//we build expected result table for monthx+1,...monthx+5 based on the rating list</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//first step is to build the expected_result table for month+1,...month+5 </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//based on strength in the relevant month and maybe more parameters that I will add later</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> white,black,i;</P>\r\n<P>i=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>while</FONT></FONT><FONT size=2> (i&lt;games_training)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((month[i]&gt;=monthx+1)&amp;&amp;(month[i]&lt;=monthx+5))</P>\r\n<P>{</P>\r\n<P>white=whiteplayer[i];</P>\r\n<P>black=blackplayer[i];</P>\r\n<P>expect_result_game[i][month[i]-monthx-1]=expectedwhitechess_result(white,black,month[i]);</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//should be improved but this is an initial version </P></FONT></FONT><FONT size=2>\r\n<P>}</P>\r\n<P>i++;</P>\r\n<P>}</P>\r\n<P>calc_expected(monthx);</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> build_stupid_csv_prediction()</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* submission.csv */</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>char</FONT></FONT><FONT size=2> c;</P>\r\n<P>FILE *stream_prediction = fopen(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"submission119.csv\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"w+b\"</FONT></FONT><FONT size=2>);</P>\r\n<P>stream_test = fopen(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"test_data.csv\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"r+b\"</FONT></FONT><FONT size=2>);</P>\r\n<P>assert(stream_prediction);</P>\r\n<P>assert(stream_test);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (stream_test == NULL || stream_prediction == NULL)</P>\r\n<P>{</P>\r\n<P>puts(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"Usage error:\\nfiles submission.cs and test_data.csv are expected to be available in the current working directory.\\n\"</FONT></FONT><FONT size=2>);</P>\r\n<P>exit(EXIT_FAILURE);</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 1; i &lt; 53; i++) {</P>\r\n<P>fscanf(stream_test, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, &amp;c);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, c);</P>\r\n<P>}</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; games_test; i++) {</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, month_test[i]);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>','</FONT></FONT><FONT size=2>);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, whiteplayer_test[i]);</P>\r\n<P>assert(whiteplayer[games_training+i]==whiteplayer_test[i]);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>','</FONT></FONT><FONT size=2>);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%d\"</FONT></FONT><FONT size=2>, blackplayer_test[i]);</P>\r\n<P>assert(blackplayer[games_training+i]==blackplayer_test[i]);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>','</FONT></FONT><FONT size=2>);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%f\"</FONT></FONT><FONT size=2>, predicted[i]);</P>\r\n<P>fprintf(stream_prediction, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"%c\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>'\\n'</FONT></FONT><FONT size=2>);</P>\r\n<P>} </P>\r\n<P>fclose(stream_test);</P>\r\n<P>fclose(stream_prediction);</P>\r\n<P>}</P>\r\n<P>&nbsp;</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>void</FONT></FONT><FONT size=2> predicting_chess_metrics(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> white_bonus,</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> max_diff)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//425</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> white,black;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i = 0; i &lt; games_test; i++) </P>\r\n<P>{</P>\r\n<P>white = whiteplayer_test[i];</P>\r\n<P>black = blackplayer_test[i];</P>\r\n<P>predicted[i]=expectedwhitechess_result(white,black,month_test[i]);</P>\r\n<P>}</P>\r\n<P>build_stupid_csv_prediction();</P>\r\n<P>&nbsp;</P>\r\n<P>}</P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>\r\n<P>int</FONT></FONT><FONT size=2> main(</FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>void</FONT></FONT><FONT size=2>)</P>\r\n<P>{</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> i,j;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>int</FONT></FONT><FONT size=2> sum = 0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> sum_result=0;</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>double</FONT></FONT><FONT size=2> error=0;</P>\r\n<P>read_test();</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 1</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((stream_training = fopen(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"training_data.csv\"</FONT></FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"r+b\"</FONT></FONT><FONT size=2>)) == NULL) </FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>/* C4996 */</P></FONT></FONT><FONT size=2>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"The file 'training_data.csv' was not opened\\n\"</FONT></FONT><FONT size=2>);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>else</P></FONT></FONT><FONT size=2>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\"The file 'training_data.csv' was opened\\n\"</FONT></FONT><FONT size=2>);</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> (stream_training) </P>\r\n<P>{</P>\r\n<P>read_training_data();</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 2 </P></FONT></FONT><FONT size=2>\r\n<P>fill_num_opp_array();</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 3</P></FONT></FONT><FONT size=2>\r\n<P>calc_observed();</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 4</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (i=90;i&lt;=100;i++)</P>\r\n<P>{</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//i should be a parameter</P></FONT></FONT><FONT size=2>\r\n<P>&nbsp;</P>\r\n<P>repeat_strength_estimate(i,81,310,5.9,2.2,2210,2285,15,12,39);</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 5</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//months i+1,i+2,i+3,i+4,i+5 are missing and we need to predict them</P></FONT></FONT><FONT size=2>\r\n<P>build_expected_result(i);</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//step 6 this function is going to build </P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//expected result table based on strength estimate(months i+1,...i+5 missing)</P></FONT></FONT><FONT size=2>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>for</FONT></FONT><FONT size=2> (j=1;j&lt;=5;j++)</P>\r\n<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>if</FONT></FONT><FONT size=2> ((i+j)&lt;=100)</P>\r\n<P>error+=calc_error_result_small(i,j);</P>\r\n<P>printf(</FONT><FONT color=#a31515 size=2><FONT color=#a31515 size=2>\" error=%f \"</FONT></FONT><FONT size=2>,error);</P>\r\n<P>&nbsp;</P>\r\n<P>}</P>\r\n<P>predicting_chess_metrics(45,425);</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//bonus for white and maximal difference</P></FONT></FONT><FONT size=2>\r\n<P>fclose(stream_training);</P>\r\n<P>}</P>\r\n<P>}</P></FONT>"
    },
    {
      "id": 1258,
      "postDate": "2010-11-20T04:38:53Z",
      "content": "<P><FONT face=Verdana>only one correction of the code<BR><BR>The original code had<BR><FONT size=2><FONT color=#0000ff>for</FONT> (i=0;i&lt;10;i++)</FONT><FONT color=#008000><FONT color=#008000 size=2>//i is the number of iteration<BR><BR></FONT></FONT><BR><BR>I changed it to 100 iterations in the code that I posted.<BR>100 iterations probably give better result than the result that I got but&nbsp;not good enough for the first place(my tests suggest small improvement in predicting of less than 0.1%)&nbsp;.&nbsp;<FONT color=#008000 size=2><FONT color=#008000 size=2></P></FONT></FONT></FONT>"
    }
  ],
  "complete": true,
  "source": "live",
  "fetched_at": "2026-10-20T02:26:20Z",
  "competition_id": 2447,
  "competition_slug": "chess",
  "team_id": 994,
  "solution_url": "/competitions/chess/writeups/urib-6th-place-urib-by-uri-blass"
}