#!/usr/bin/perl

my $PI = atan2(0, -1);
my $N = shift || usage();

my $R = 0.5;

my $even = $N % 2 == 0;
my $r = $even ? $N-1 : $N;
my @X = map $R*cos(($PI/2-2*$PI*$_)/$N), 1 .. $r;
my @Y = map $R*sin(($PI/2-2*$PI*$_)/$N), 1 .. $r;
if ($even) {
  push @X, 0;
  push @Y, 0;
}
my @XX = map $_ * 1.2, @X;
my @YY = map $_ * 1.2, @Y;

@L = ('A' .. 'Z');

for my $D (1 .. $N) {
  open F, ">", "tourn-$N-$D.pic" or die $!;
  print F ".PS\n";
  print F "dotrad = 0.02\n";
  for my $i (1 .. $N) {
    print F "D$i: circle rad dotrad filled 1 at ($X[$i-1], $Y[$i-1])\n";
    my $L = ($i + $D) % $N;
    my $up = $i == $N ? qq{""} : qq{};
    print F qq{"$L[$L]" $up at ($XX[$i-1], $YY[$i-1])\n};
  }

  print F "linethick = 1\n";
  for my $a (1 .. $r) {
    my $b = $r - ($a-1);
    if ($a < $b) {
      print F "  line from D$a to D$b\n";
    } elsif ($a == $b && $even) {
      print F "  line from D$a to D$N\n";
    }
  }
  print F ".PE\n";
  close F;
}
