/* Program to produce a set of round robin pairing tables. Written by Warren Porter 06/15/94 07:20 am <- 6 <- 2 <- 7 <- 3 10 B W 1 W B W B ^ bye | B W B W | board V -> 5 -> 9 -> 4 -> 8 Note players are placed at every other location in a clockwise rotation but will move counterclockwise between every round. */ #include typedef struct { int pw,pb; } dtab; typedef struct { int bd_no, dir; char color; } ptab; main (int argc, char *argv[]) { int x1, max_board, rot_dir, dir, board_no, rd_no, no_players, i, min=4,max=24; ptab p[37]; dtab d[20]; if (argc == 2) max=min=atoi(argv[1]); else if (argc == 3) { min=atoi(argv[1]); max=atoi(argv[2]); } if (min % 2) min++; if (max % 2) max++; if (min < 4) { fprintf(stderr,"Min too low %i, substituting 4\a\n",min); if (max == min) max=min = 4; else min=4; } if (max > 38) { fprintf(stderr,"Max too high %i, substituting 38\a\n",max); if (max == min) max=min = 38; else max=38; } for (no_players = min; no_players <= max; no_players +=2) { max_board = no_players / 2; board_no = p[0].bd_no = 1; p[0].color = 'w'; p[0].dir = 1; /* Player 1's color and direction 1st rd */ rot_dir = 2; /* Where program will seat next player */ dir = -1; printf("\n\nPairings for %i or %i players\n\nRD", no_players - 1, no_players); x1 = max_board * 3 - 2; for (i=2;i <= x1;i++) putchar(' '); printf("PAIRINGS\n"); /* Next routine initially places the players for the 1st round (except for 1, placed "by hand" earlier). To initially fill the circuit, players are seated in order in every other position. "dir" tells the player where to move for the next round and "rot_dir" tells the program where to put the next player initially. When it initially says to put someone outside the range of permissible boards, "rot_dir" is changed along with other corrections. */ for (x1 = 2;x1 < no_players;x1++) { if (x1 <= max_board) p[x1 - 1].color = 'b'; else p[x1 - 1].color = 'w'; board_no += rot_dir; p[x1 - 1].dir = dir; p[x1 - 1].bd_no = board_no; if (!board_no) { board_no = p[x1 - 1].bd_no = 2; dir = p[x1 - 1].dir = -1; rot_dir = 2; } else if (board_no == max_board) { p[x1 - 1].dir = -1; board_no++; rot_dir = -2; dir = 1; } else if (board_no > max_board) { board_no = p[x1 - 1].bd_no = max_board; rot_dir = -2; dir = 1; p[x1 - 1].dir = 0; } } /* Initially builds the display table from the player table. */ for (rd_no = 1; rd_no < no_players; rd_no++) { printf("\n%2d",rd_no); for (x1 = 1; x1 < no_players;x1++) { board_no = p[x1 - 1].bd_no; if (board_no != 1) /* Normal boards */ if (p[x1 - 1].color == 'w') d[board_no - 1].pw = x1; else d[board_no - 1].pb = x1; else /* Bye board */ if (x1 > max_board) { d[0].pb = x1; d[0].pw = no_players; } else { d[0].pb = no_players; d[0].pw = x1; } } /* Print the pairings for this round */ for (x1 = 0;x1 < max_board;x1++) printf(" %2d:%-2d",d[x1].pw,d[x1].pb); /* If another round follows, ask the players to move */ if ((no_players - rd_no) > 1) for (x1 = 1;x1 < no_players;x1++) { p[x1 - 1].bd_no += p[x1 - 1].dir; if (p[x1 - 1].bd_no != 1) if (p[x1 - 1].color == 'w') p[x1 - 1].color = 'b'; else p[x1 - 1].color = 'w'; else dir = p[x1 - 1].dir = 1; if (!p[x1 - 1].dir) dir=p[x1 - 1].dir=-1; else if (p[x1 - 1].bd_no == max_board) dir=p[x1 - 1].dir= 0; } } } printf("\n"); }