Politrecohttp://www.politreco.com/2012-10-16T19:54:00-03:00Analyzing chess.com tournaments2012-10-16T19:54:00-03:00Lucas De Marchitag:www.politreco.com,2012-10-16:2012/10/16/analyzing-chess-com-tournaments/<p>This year at ProFUSION we started to create chess tournaments to play
using chess.com so we have fun not only coding but playing this game.
However it’s even more fun when we put both together: chess and code :-)!</p>
<p>During the second tournament we realized chess.com was missing a nice
feature: to allow participants to predict who would be the champion
based on the current championship status and future results. To show the
current state, Chess.com presents us with a table like this:</p>
<p><a href="http://www.politreco.com/wp-content/uploads/2012/10/pairings.jpg"><img alt="" src="http://www.politreco.com/wp-content/uploads/2012/10/pairings.jpg" title="pairings" /></a></p>
<p>Not the missing games with a “_”. What we would like is to predict who
can still win the tournament based on these missing games. One trick
here is how to calculate the tie break, but it’s really straightforward
to implement once we understand the formula:</p>
<p><a href="http://www.politreco.com/wp-content/uploads/2012/10/formula.jpg"><img alt="" src="http://www.politreco.com/wp-content/uploads/2012/10/formula.jpg" title="formula" /></a></p>
<p>So, for each sum up the result of each game multiplied by the current
score of the opponent (“opp” in the formula above) the game was played against.</p>
<p>With that in mind I wrote a small tool, ccs, to allow you to predict the
next results:</p>
<div class="highlight"><pre><span class="nv">$ </span>./ccs.py data/example2.html
css> state
Number of players: 8
1. 2. 3. 4. 5. 6. 7. 8. <span class="p">|</span> Score <span class="p">|</span> Tie Break
-------------------------------------------------------------------------------------------------------
1. demarchi X <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">0</span> <span class="m">1</span> <span class="m">0</span> <span class="m">0</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="p">|</span> <span class="m">10</span> <span class="p">|</span> 54
2. ulissesf <span class="m">0</span> <span class="m">0</span> X <span class="m">1</span> <span class="m">1</span> <span class="m">0</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="p">|</span> <span class="m">10</span> <span class="p">|</span> 52
3. lfelipe <span class="m">1</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> X <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">0</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="p">|</span> <span class="m">10</span> <span class="p">|</span> 52
4. hdante <span class="m">1</span> <span class="m">0</span> <span class="m">0</span> <span class="m">1</span> <span class="m">0</span> <span class="m">0</span> X <span class="m">1</span> <span class="m">0</span> <span class="m">0</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="p">|</span> <span class="m">8</span> <span class="p">|</span> 38
5. Gastal <span class="m">1</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">1</span> <span class="m">0</span> X <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="p">|</span> <span class="m">8</span> <span class="p">|</span> 34
6. marinatwp <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">1</span> <span class="m">0</span> <span class="m">0</span> <span class="m">1</span> <span class="m">0</span> <span class="m">0</span> X <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="p">|</span> <span class="m">6</span> <span class="p">|</span> 22
7. yanwm <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> X <span class="m">1</span> <span class="m">1</span> <span class="p">|</span> <span class="m">2</span> <span class="p">|</span> 0
8. antognolli <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> X <span class="p">|</span> <span class="m">0</span> <span class="p">|</span> 0
ccs> push <span class="nv">1x5</span><span class="o">=</span>1
Simulation added: demarchi beats Gastal
Number of players: 8
1. 2. 3. 4. 5. 6. 7. 8. <span class="p">|</span> Score <span class="p">|</span> Tie Break
-------------------------------------------------------------------------------------------------------
1. demarchi X <span class="m">1</span> <span class="m">0</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">0</span> <span class="m">0</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="p">|</span> <span class="m">11</span> <span class="p">|</span> 62
2. lfelipe <span class="m">1</span> <span class="m">0</span> X <span class="m">0</span> <span class="m">0</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">0</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="p">|</span> <span class="m">10</span> <span class="p">|</span> 53
3. ulissesf <span class="m">0</span> <span class="m">0</span> <span class="m">1</span> <span class="m">1</span> X <span class="m">0</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="p">|</span> <span class="m">10</span> <span class="p">|</span> 52
4. hdante <span class="m">1</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">1</span> X <span class="m">1</span> <span class="m">0</span> <span class="m">0</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="p">|</span> <span class="m">8</span> <span class="p">|</span> 39
5. Gastal <span class="m">1</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">1</span> <span class="m">0</span> X <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="p">|</span> <span class="m">8</span> <span class="p">|</span> 35
6. marinatwp <span class="m">0</span> <span class="m">0</span> <span class="m">1</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">1</span> <span class="m">0</span> <span class="m">0</span> X <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="m">1</span> <span class="p">|</span> <span class="m">6</span> <span class="p">|</span> 22
7. yanwm <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> X <span class="m">1</span> <span class="m">1</span> <span class="p">|</span> <span class="m">2</span> <span class="p">|</span> 0
8. antognolli <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> <span class="m">0</span> X <span class="p">|</span> <span class="m">0</span> <span class="p">|</span> 0
ccs>
</pre></div>
<p>Ccs parses the pairings table created by chess.com (given you saved it
somewhere and passed as argument to the tool) and then gives you a
“ccs> ” prompt, waiting for commands. Type ‘help’ to see the list of
available commands. Basically it allows you to <strong>a.</strong> see the current
state of the game (‘state’ command) and <strong>b.</strong> push and pop result
simulations (sigh! ‘push’ and ‘pop’ commands).</p>
<p>A nice feature that I’d like to introduce soon is to export to a big svg
with all the state transitions, marking leaf nodes when there’s a
champion. I’m also releasing the source as open source, so anybody
wanting to help can implement it :-). Code is available on my github:
<a href="https://github.com/lucasdemarchi/ccs">https://github.com/lucasdemarchi/ccs</a>. <span class="caps">GPL</span>-2 as usual.</p>
<p>What can we predict in the example above?</p>
<ol>
<li>No matter the pending games, gastal can not win anymore, since he
will reach at most 54 as tie break, leaving lfelipe with 56. That
also implies lfelipe would be the champion if gastal wins all his
pending games;</li>
<li>If demarchi wins his last game he wins the tournament, with score=11
and tie-break=62. If ulissesf also wins, he will have the same
score, but his tie-break will be 60, pushing demarchi’s tie-break
to 64.</li>
<li>If ulissesf wins and demarchi loses, ulissesf is the champion.</li>
</ol>
<p>Since I am demarchi on the table above, now what I have to do is either
win the last game or convince Gastal to give up his pending games :-).</p>