[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pbmserv-dev] constraining the game launcher
On Thu, Sep 26, 2002 at 05:46:20AM +0200, Claude Chaunier wrote:
> Hi Richard. What code do you use to launch the LoA tournament
> with the list of players Dave Dyers provides? I'm thinking
> of adding a few lines to reject choices of colors that were
> already made last year - we would provide the list of
> unwanted color combinations.
The code itself... (src/pool.c)
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
main(int argc,char **argv)
{
char *pool;
char cmd[1024];
int i,j;
int doboth=0;
int gametype=1;
int first=3;
srand(time(NULL));
if (argc < 5) {
fprintf(stderr,"usage: %s [-d] GameType pool user1 user2 [ ... userN ]\n",argv[0]);
exit(0);
}
if (!strcmp(argv[1],"-d")) {
gametype=2;
first=4;
doboth=1;
}
pool = argv[first-1];
for (i=first ; i<argc ; i++) {
char *tmp;
for (tmp = argv[i],j=0 ; tmp[j] ; j++) {
if (tmp[j] >= 'A' && tmp[j] <= 'Z') {
tmp[j] = (tmp[j] - 'A') + 'z';
}
}
for (j=i+1 ; j<argc ; j++) {
if (doboth || ((i+j)%2 == 1))
CreateGame(pool,argv+first,i-first+1,j-first+1,argc-first);
if (doboth || ((i+j)%2 == 0))
CreateGame(pool,argv+first,j-first+1,i-first+1,argc-first);
}
sprintf(cmd,"echo %s:%s:0:0 >>/home/PBM/pbmserv/standings/%s",pool,argv[i],argv[gametype]);
system(cmd);
}
}
CreateGame(char *pool,char **argv,int w,int b,int n)
{
char fn[256];
char cmd[256];
struct stat st;
char roll[4];
int seed = rand();
int d1=rand()%6,d2=rand()%6;
while (d1 == d2) {
d1=rand()%6,d2=rand()%6;
}
sprintf(roll,"%d %d",d1+1,d2+1);
if (n<10) {
printf("%s%d%d\t%s\t%s\n",pool,w,b,argv[w-1],argv[b-1]);
sprintf(cmd,"sed -e 's/%%1%%/%s/' -e 's/%%2%%/%s/' -e 's/%%roll%%/%s/' -e 's/%%seed%%/%d/' .example > %s%d%d",
argv[w-1],argv[b-1],roll,seed,pool,w,b);
sprintf(fn,"%s%d%d",pool,w,b);
}
else {
printf("%s%02d%02d\t%s\t%s\n",pool,w,b,argv[w-1],argv[b-1]);
sprintf(cmd,"sed -e 's/%%1%%/%s/' -e 's/%%2%%/%s/' -e 's/%%roll%%/%s/' -e 's/%%seed%%/%d/' .example > %s%02d%02d",
argv[w-1],argv[b-1],roll,seed,pool,w,b);
sprintf(fn,"%s%02d%02d",pool,w,b);
}
if (stat(fn,&st) != 0) {
system(cmd);
}
}
--
/ \__ | Richard Rognlie / Sendmail Ninja / Gamerz.NET Lackey
\__/ \ | http://www.gamerz.net/rrognlie/ <rrognlie@gamerz.net>
/ \__/ | No trees were killed in the sending of this message.
\__/ | However, a great many instructions were executed.