#!/usr/bin/perl

# Copyright (C) 2005 John J. Chew, III <jjchew@math.utoronto.ca>
# All Rights Reserved

package TSH::Command::SWiss;

use strict;
use warnings;

use TSH::PairingCommand;

our (@ISA) = qw(TSH::PairingCommand);

=pod

=head1 NAME

TSH::Command::SWiss - implement the C<tsh> SWiss command

=head1 SYNOPSIS

  my $command = new TSH::Command::SWiss;
  my $argsp = $command->ArgumentTypes();
  my $helptext = $command->Help();
  my (@names) = $command->Names();
  $command->Run($tournament, @parsed_arguments);
  
=head1 ABSTRACT

TSH::Command::SWiss is a subclass of TSH::Command.

=cut

=head1 DESCRIPTION

=over 4

=cut

sub initialise ($$$$);
sub new ($);
sub Run ($$@);

=item $parserp->initialise()

Used internally to (re)initialise the object.

=cut

sub initialise ($$$$) {
  my $this = shift;
  my $path = shift;
  my $namesp = shift;
  my $argtypesp = shift;

  $this->{'help'} = <<'EOF';
Use the SWiss command to manually add a round of swiss pairings
to a division, specifying the maximum number of allowable repeats,
and the round on whose standings the pairings are to be based.
This command was deprecated because the quality of its pairings
was significantly inferior to those generated by NewSwiss.
In the current version of tsh, SWiss and NewSwiss are synonymous,
and use the new Swiss-pairing algorithm.
For a still better algorithm, try ChewPair.
EOF
  $this->{'names'} = [qw(sw swiss)];
  $this->{'argtypes'} = [qw(Repeats BasedOnRound Division)];
# print "names=@$namesp argtypes=@$argtypesp\n";

  return $this;
  }

sub new ($) { return TSH::Utility::new(@_); }

=item $command->Run($tournament, @parsed_args)

Should run the command in the context of the given
tournament with the specified parsed arguments.

=cut

sub Run ($$@) { 
  my $this = shift;
  my $tournament = shift;
  my ($repeats, $sr, $dp) = @_;
  my $sr0 = $sr-1;
# $tournament->TellUser('edeprec', 'NewSwiss');
  my $setupp = $this->SetupForPairings(
    'division' => $dp, 'source0' => $sr0, 'repeats' => $repeats) || return 0;
  if ($dp->PairSwiss($setupp)) { $this->TidyAfterPairing($dp); }
  else { $tournament->TellUser('epfail'); }
  }

=back

=cut

=head1 BUGS

None known

=cut

1;
