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 :-)!
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:
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:
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.
With that in mind I wrote a small tool, ccs, to allow you to predict the
next results:
$ ./ccs.py data/example2.html
css> state
Number of players: 8
1. 2. 3. 4. 5. 6. 7. 8. | Score | Tie Break
-------------------------------------------------------------------------------------------------------
1. demarchi X 1 1 1 0 1 0 0 1 1 1 1 1 1 | 10 | 54
2. ulissesf 0 0 X 1 1 0 1 1 1 1 1 1 1 1 | 10 | 52
3. lfelipe 1 0 0 0 X 1 1 1 1 1 0 1 1 1 1 | 10 | 52
4. hdante 1 0 0 1 0 0 X 1 0 0 1 1 1 1 1 | 8 | 38
5. Gastal 1 0 0 0 1 0 X 1 1 1 1 1 1 | 8 | 34
6. marinatwp 0 0 0 0 1 0 0 1 0 0 X 1 1 1 1 | 6 | 22
7. yanwm 0 0 0 0 0 0 0 0 0 0 0 0 X 1 1 | 2 | 0
8. antognolli 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X | 0 | 0
ccs> push 1x5=1
Simulation added: demarchi beats Gastal
Number of players: 8
1. 2. 3. 4. 5. 6. 7. 8. | Score | Tie Break
-------------------------------------------------------------------------------------------------------
1. demarchi X 1 0 1 1 1 0 0 1 1 1 1 1 1 1 | 11 | 62
2. lfelipe 1 0 X 0 0 1 1 1 1 1 0 1 1 1 1 | 10 | 53
3. ulissesf 0 0 1 1 X 0 1 1 1 1 1 1 1 1 | 10 | 52
4. hdante 1 0 0 0 0 1 X 1 0 0 1 1 1 1 1 | 8 | 39
5. Gastal 1 0 0 0 0 1 0 X 1 1 1 1 1 1 | 8 | 35
6. marinatwp 0 0 1 0 0 0 0 1 0 0 X 1 1 1 1 | 6 | 22
7. yanwm 0 0 0 0 0 0 0 0 0 0 0 0 X 1 1 | 2 | 0
8. antognolli 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X | 0 | 0
ccs>
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 a. see the current
state of the game (‘state’ command) and b. push and pop result
simulations (sigh! ‘push’ and ‘pop’ commands).
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:
https://github.com/lucasdemarchi/ccs. GPL-2 as usual.
What can we predict in the example above?
- 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;
- 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.
- If ulissesf wins and demarchi loses, ulissesf is the champion.
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 :-).