Command line tool to output round-robin pairings?

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

Jesse Gersenson
Posts: 593
Joined: Sat Aug 20, 2011 9:43 am

Command line tool to output round-robin pairings?

Post by Jesse Gersenson »

Is there a command line tool which will take a list of participants, a number of rounds, and output pairings?

For example:
./roundrobin rounds=3 players.txt

cat players.txt
engine1
engine2
engine3
engine4

output
1.1. engine1 engine2
1.2. engine2 engine1
1.3. engine3 engine4
1.4. engine4 engine3
2.1 ...
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Command line tool to output round-robin pairings?

Post by hgm »

Not that I know. But the algorithm is extremely simple. After you make arbitrary first-round pairings, for each next round you shift the left column on place down, and the right column, except the last player, one place up. The players that shift out of the range move to the position left open in the opposite column. On the odd boards the player in the left colum has white, on the odd board he has black. Except on the last board, where you alternate this every round (as there is a player that that always sits there). That's all.

If you play two games with reversed colors, you don't even have to worry about assigning colors, and you can assign the player in the left column always white in the first game.
User avatar
Ajedrecista
Posts: 1968
Joined: Wed Jul 13, 2011 9:04 pm
Location: Madrid, Spain.

Re: Command line tool to output Round Robin pairings?

Post by Ajedrecista »

Hello Jesse:
Jesse Gersenson wrote: Tue Oct 16, 2018 7:57 pm Is there a command line tool which will take a list of participants, a number of rounds, and output pairings?

For example:
./roundrobin rounds=3 players.txt

cat players.txt
engine1
engine2
engine3
engine4

output
1.1. engine1 engine2
1.2. engine2 engine1
1.3. engine3 engine4
1.4. engine4 engine3
2.1 ...
I wrote such a programme in Fortran 95 some years ago, but it does not work exactly like you want. I used something called Schurig algorithm for schedule the pairings, that are presented on Berger's tables. (Link in Spanish).

I can not attach it in this post for some reason:

Code: Select all

ERROR
__________________________________________________
File too large: Round_Robin_pairings_generator.rar
Although the size of the RAR file is only 611 KB. A 7-Zip compression (565 KB) gives the same error.

So I will explain its use, just in case there is some interest and maybe at weekend (no warranty at all) try to get your desired format and upload it somewhere. I am not sure if I have the skills for doing that, since I am not a programmer.

After double clicking the executable, the programme would look like:

Code: Select all

Round_Robin_pairings_generator, ® 2012-2013.

Write down the number of players of the Round Robin tournament (up to 80):

Code: Select all

Round_Robin_pairings_generator, ® 2012-2013.

Write down the number of players of the Round Robin tournament (up to 80):

8

Write down the clock rate of the CPU (in GHz), only for timing the elapsed time
of the calculations:

The clock rate is not important at all (just write a positive number). I used that weird thing for benchmark timings and I finally left it there because I thought nobody else than me would use the programme. Then the programme runs:

Code: Select all

Round_Robin_pairings_generator, ® 2012-2013.

Write down the number of players of the Round Robin tournament (up to 80):

8

Write down the clock rate of the CPU (in GHz), only for timing the elapsed time
of the calculations:

3

End of the implementation of Schurig algorithm.

Approximated generation time:   15 microseconds.

The pairings (Berger's tables) have been saved into two files:

     Single_Round_Robin.txt
     Double_Round_Robin.txt

Thanks for using Round_Robin_pairings_generator. Press Enter to exit.
I only planned a single round robin (like Wijk and Zee or Aeroflot) and a double round robin (like Linares). The output is:

Code: Select all

Pairings (using the Schurig algorithm) in a single Round Robin tournament with  8 different players.
 
Number of games in this tournament:   28 games.
 
---------
 
ROUND  1:
 
 1- 8
 2- 7
 3- 6
 4- 5
 
---------
 
ROUND  2:
 
 8- 5
 6- 4
 7- 3
 1- 2
 
---------
 
ROUND  3:
 
 2- 8
 3- 1
 4- 7
 5- 6
 
---------
 
ROUND  4:
 
 8- 6
 7- 5
 1- 4
 2- 3
 
---------
 
ROUND  5:
 
 3- 8
 4- 2
 5- 1
 6- 7
 
---------
 
ROUND  6:
 
 8- 7
 1- 6
 2- 5
 3- 4
 
---------
 
ROUND  7:
 
 4- 8
 5- 3
 6- 2
 7- 1
 
---------
 
End of Berger's tables for a single Round Robin tournament.
 
Thanks for using Round_Robin_pairings_generator.

Code: Select all

Pairings (using the Schurig algorithm) in a double Round Robin tournament with  8 different players.
 
Number of games in this tournament:   56 games.
 
----------
 
ROUND   1:
 
 1- 8
 2- 7
 3- 6
 4- 5
 
----------
 
ROUND   2:
 
 8- 5
 6- 4
 7- 3
 1- 2
 
----------
 
ROUND   3:
 
 2- 8
 3- 1
 4- 7
 5- 6
 
----------
 
ROUND   4:
 
 8- 6
 7- 5
 1- 4
 2- 3
 
----------
 
ROUND   5:
 
 3- 8
 4- 2
 5- 1
 6- 7
 
----------
 
ROUND   6:
 
 8- 7
 1- 6
 2- 5
 3- 4
 
----------
 
ROUND   7:
 
 4- 8
 5- 3
 6- 2
 7- 1
 
----------
 
ROUND   8:
 
 8- 1
 7- 2
 6- 3
 5- 4
 
----------
 
ROUND   9:
 
 5- 8
 4- 6
 3- 7
 2- 1
 
----------
 
ROUND  10:
 
 8- 2
 1- 3
 7- 4
 6- 5
 
----------
 
ROUND  11:
 
 6- 8
 5- 7
 4- 1
 3- 2
 
----------
 
ROUND  12:
 
 8- 3
 2- 4
 1- 5
 7- 6
 
----------
 
ROUND  13:
 
 7- 8
 6- 1
 5- 2
 4- 3
 
----------
 
ROUND  14:
 
 8- 4
 3- 5
 2- 6
 1- 7
 
----------
 
End of Berger's tables for a double Round Robin tournament.
 
Thanks for using Round_Robin_pairings_generator.
It also supports an odd number of players: a fictitious player is added, which in reality means a bye. For example, a single round robin with 5 players:

Code: Select all

Pairings (using the Schurig algorithm) in a single Round Robin tournament with  5 different players.
 
Number of games in this tournament:   10 games.
 
--------------------
 
ROUND  1:
 
Player  1 has a bye.
 2- 5
 3- 4
 
--------------------
 
ROUND  2:
 
Player  4 has a bye.
 5- 3
 1- 2
 
--------------------
 
ROUND  3:
 
Player  2 has a bye.
 3- 1
 4- 5
 
--------------------
 
ROUND  4:
 
Player  5 has a bye.
 1- 4
 2- 3
 
--------------------
 
ROUND  5:
 
Player  3 has a bye.
 4- 2
 5- 1
 
--------------------
 
End of Berger's tables for a single Round Robin tournament.
 
Thanks for using Round_Robin_pairings_generator.
If you want n rounds (n > 2), I would suggest (n/2)*(double round robin) for n even and [floor(n/2)]*(double round robin) + (single round robin) for n odd.

The limit of 80 participants is hardcoded but it can be raised to any value. Since it is open source, changes in format can be done, including reading a file of names, then writing them in Berger's tables; and raise the number of rounds. The algorithm itself is fine AFAIK although the way it is coded is a nightmare, I know it. Any feedback is welcome.

Regards from Spain.

Ajedrecista.
Colin-G
Posts: 191
Joined: Mon Oct 31, 2016 6:30 pm
Location: England

Re: Command line tool to output round-robin pairings?

Post by Colin-G »

I wrote a tcl/tk program some years ago to produce a tournament list for Xboard.

Code: Select all

#!/usr/bin/wish -f
# This file creates tournament list for 12 engines - 132 games total
	set file "matchList"
	set fd [open $file "w"]
	set game 1 ; set k 1
	set W1 1 ; set W2 11 ; set W3 3 ; set W4 9 ; set W5 5 ; set W6 7
	set B1 12 ; set B2 2 ; set B3 10 ; set B4 4 ; set B5 8 ; set B6 6
	for {set i 11} {$i} {incr i -1} {
		puts $fd $game ; set game [expr $game + 1 ]
		puts $fd "W$W1 vs B$B1"
		puts $fd $game ; set game [expr $game + 1 ]
		puts $fd "W$W2 vs B$B2"
		puts $fd $game ; set game [expr $game + 1 ]
		puts $fd "W$W3 vs B$B3"
		puts $fd $game ; set game [expr $game + 1 ]
		puts $fd "W$W4 vs B$B4"
		puts $fd $game ; set game [expr $game + 1 ]
		puts $fd "W$W5 vs B$B5"
		puts $fd $game ; set game [expr $game + 1 ]
		puts $fd "W$W6 vs B$B6"
		set k [expr $k + 1 ]
		if {$W1 == 1} {set W1 $k} else {set W1 1}
		if {$B1 == 1} {set B1 $k} else {set B1 1}
		set W2 [expr $W2 + 1 ] ; if {$W2 == 13} {set W2 2}
		set W3 [expr $W3 + 1 ] ; if {$W3 == 13} {set W3 2}
		set W4 [expr $W4 + 1 ] ; if {$W4 == 13} {set W4 2}
		set W5 [expr $W5 + 1 ] ; if {$W5 == 13} {set W5 2}
		set W6 [expr $W6 + 1 ] ; if {$W6 == 13} {set W6 2}
		set B2 [expr $B2 + 1 ] ; if {$B2 == 13} {set B2 2}
		set B3 [expr $B3 + 1 ] ; if {$B3 == 13} {set B3 2}
		set B4 [expr $B4 + 1 ] ; if {$B4 == 13} {set B4 2}
		set B5 [expr $B5 + 1 ] ; if {$B5 == 13} {set B5 2}
		set B6 [expr $B6 + 1 ] ; if {$B6 == 13} {set B6 2}
	}
	close $fd
exit
It produces a file with a list of 66 matches which together with the Xboard parameter "-mg 2" gives the required 132 games for a 12 engine all play all tournament.

Code: Select all

1
W1 vs B12
2
W11 vs B2
3
W3 vs B10
4
W9 vs B4
5
W5 vs B8
6
W7 vs B6
7
W2 vs B1
8
W12 vs B3
9
W4 vs B11
10
W10 vs B5
11
W6 vs B9
12
W8 vs B7
13
W1 vs B3
14
W2 vs B4
15
W5 vs B12
16
W11 vs B6
17
W7 vs B10
18
W9 vs B8
19
W4 vs B1
20
W3 vs B5
21
W6 vs B2
22
W12 vs B7
23
W8 vs B11
24
W10 vs B9
25
W1 vs B5
26
W4 vs B6
27
W7 vs B3
28
W2 vs B8
29
W9 vs B12
30
W11 vs B10
31
W6 vs B1
32
W5 vs B7
33
W8 vs B4
34
W3 vs B9
35
W10 vs B2
36
W12 vs B11
37
W1 vs B7
38
W6 vs B8
39
W9 vs B5
40
W4 vs B10
41
W11 vs B3
42
W2 vs B12
43
W8 vs B1
44
W7 vs B9
45
W10 vs B6
46
W5 vs B11
47
W12 vs B4
48
W3 vs B2
49
W1 vs B9
50
W8 vs B10
51
W11 vs B7
52
W6 vs B12
53
W2 vs B5
54
W4 vs B3
55
W10 vs B1
56
W9 vs B11
57
W12 vs B8
58
W7 vs B2
59
W3 vs B6
60
W5 vs B4
61
W1 vs B11
62
W10 vs B12
63
W2 vs B9
64
W8 vs B3
65
W4 vs B7
66
W6 vs B5
Using a text editor on the file to change all "W" and "B" to "Engine" gives
1
Engine1 vs Engine12
2
Engine11 vs Engine2
3
Engine3 vs Engine10
4
Engine9 vs Engine4
5
Engine5 vs Engine8
6
Engine7 vs Engine6
7
Engine2 vs Engine1
8
Engine12 vs Engine3
etc.
Jesse Gersenson
Posts: 593
Joined: Sat Aug 20, 2011 9:43 am

Re: Command line tool to output round-robin pairings?

Post by Jesse Gersenson »

Tweaked a script I found online and came up with this:

Code: Select all

<?php


echo "\n\n USAGE: php roundrobin.php [# of rounds]";
echo "\n DESCRIPTION: Outputs round robin pairings for chess.\n\n ";

$players = [1,2,3,4,5,6,7,8,9,10,11,12];
//$players = ['engineA','engineB','engineC','engineD'];
$counter=0;
$setrounds=$argv[1];

for ($x = 0; $x < $setrounds; $x++) {

$n = count($players);
	for ($r = 0; $r < $n - 1; $r++) {
	//for ($r = 0; $r < 1; $r++) {
	    for ($i = 0; $i < $n / 2; $i++) {
	$counter++;
		$rounds[$r][] = [$players[$i], $players[$n-1 - $i]];
	echo "\n$counter " . $players[$i] . ' -- ' . $players[$n-1 - $i];

	$counter++;
	echo "\n$counter " . $players[$n-1 - $i] . ' -- ' . $players[$i] ;
	    //    $rounds[$r][] = [$players[$n-1 - $i], $players[$i]];
	    }
	    // Perform round-robin shift, keeping first player in its spot:
	    $players[] = array_splice($players, 1, 1)[0];
	}
	// shift once more to put array in its original sequence:
	$players[] = array_splice($players, 1, 1)[0];
	//print_r($rounds);

}
echo "\n";
echo "\n";
Jesse Gersenson
Posts: 593
Joined: Sat Aug 20, 2011 9:43 am

Re: Command line tool to output round-robin pairings?

Post by Jesse Gersenson »

more practical way to get players array:
$players=file('players.txt',FILE_IGNORE_NEW_LINES);

cat players.txt
engine1
engine2
engine3
engine4
Jesse Gersenson
Posts: 593
Joined: Sat Aug 20, 2011 9:43 am

Re: Command line tool to output round-robin pairings?

Post by Jesse Gersenson »