xwords/xwords4/tests/xwgame.pl

83 lines
1.8 KiB
Perl
Raw Normal View History

2005-03-25 04:19:03 +01:00
#!/usr/bin/perl
# Play a relay game. Params are CookieName and device count.
use strict;
my $xwdir = "../linux/linux";
2005-09-14 07:12:07 +02:00
my @cookies = ( "COOKIE" );
2005-03-25 04:19:03 +01:00
my $nPlayers = 2;
my $port = 10999;
my $dict = "~/personal/dicts/SOWPODS2to15.xwd";
my $quit = "";
2005-09-14 07:12:07 +02:00
my $gettingCookies = 0;
2005-03-25 04:19:03 +01:00
my @names = (
"Fred",
"Barney",
"Wilma",
"Betty",
);
while ( my $param = shift( @ARGV ) ) {
print STDERR "param $param\n";
if ( $param =~ m|-C| ) {
2005-09-14 07:12:07 +02:00
$cookies[0] = shift( @ARGV );
$gettingCookies = 1;
2005-03-25 04:19:03 +01:00
next;
} elsif ( $param =~ m|-nplayers| ) {
$nPlayers = shift( @ARGV );
} elsif ( $param =~ m|-dict| ) {
$dict = shift( @ARGV );
} elsif ( $param =~ m|-port| ) {
$port = shift( @ARGV );
} elsif ( $param =~ m|-quit| ) {
$quit = " -q ";
2005-09-14 07:12:07 +02:00
} elsif ( $gettingCookies ) {
push @cookies, $param;
next;
2005-03-25 04:19:03 +01:00
} else {
usage();
exit 1;
}
2005-09-14 07:12:07 +02:00
$gettingCookies = 0;
2005-03-25 04:19:03 +01:00
}
2005-09-14 07:12:07 +02:00
foreach my $cookie (@cookies) {
my $cmdBase = "cd $xwdir && ./xwords -d $dict -C $cookie $quit -p $port";
print "$cmdBase\n";
2005-03-25 04:19:03 +01:00
2005-09-14 07:12:07 +02:00
for ( my $p = 0; $p < $nPlayers; ++$p ) {
print STDERR "p = $p\n";
my $cmd = $cmdBase;
if ( $p == 0 ) { # server case
$cmd .= " -s ";
for ( my $i = 1; $i < $nPlayers; ++$i ) {
$cmd .= " -N ";
}
2005-03-25 04:19:03 +01:00
}
2005-09-14 07:12:07 +02:00
$cmd .= " -r $names[$p]";
2005-03-25 04:19:03 +01:00
2005-09-14 07:12:07 +02:00
my $pid = fork;
print STDERR "fork => $pid.\n";
if ( $pid ) {
# parent; give child chance to get ahead
# sleep 1;
} else {
exec "$cmd 2>/dev/null &";
last;
}
}
}
2005-03-25 04:19:03 +01:00
2005-05-01 19:38:31 +02:00
sub usage()
{
print STDERR <<EOF
usage : $0 [-nplayers n] [-dict dname] [-port pnum] [-quit]
EOF
}