added template, removed crap crap crap
authorrealraum <realraum@realraum.at>
Tue, 5 Jul 2011 22:45:41 +0000 (22:45 +0000)
committerrealraum <realraum@realraum.at>
Tue, 5 Jul 2011 22:45:41 +0000 (22:45 +0000)
dart/dart-dummy.pl [deleted file]
dart/dart-fullcricket.pl [deleted file]
dart/dart-nochecricket.pl [deleted file]
dart/dart-soundonly.pl [deleted file]
dart/dart-template.pl [new file with mode: 0644]

diff --git a/dart/dart-dummy.pl b/dart/dart-dummy.pl
deleted file mode 100755 (executable)
index 5743114..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/usr/bin/perl
-$|=1;
-while(<>)
-{
-  print
-}
diff --git a/dart/dart-fullcricket.pl b/dart/dart-fullcricket.pl
deleted file mode 100755 (executable)
index 1823624..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-#!/usr/bin/perl
-use strict;
-#use POSIX;
-#use Term::Cap;
-# General terminal line I/O
-#my $termios = new POSIX::Termios;
-#$termios->getattr;
-#my $term = Term::Cap->Tgetent( { OSPEED => $termios->getospeed } );
-my $sieb=1;
-my @prim = qw / 2 3 5 7 11 13 17 19 /;
-
-sub gueltig{
-    my ($zahl,$mult) = @_;
-    return $zahl>1;
-  };
-
-
-$|=1;
-
-# Extract the entry of the terminal type
-
-# clear
-
-my (@player) = @ARGV;
-
-my $numplayer = @player;
-my $round =0;
-my %score;
-my $current_player=1;
-while ( my $schuss = <STDIN>)
-{
-  #print STDERR $schuss;
-  my ($mult,$zahl) = split /\s+/, $schuss;
-
-  if ($mult =~/^\d$/)
-  {
-    if (not gueltig($zahl,$mult))
-    {
-      print "miss\n";
-      next;
-    }
-    my ($scho,$scored,$self_scored);
-    while($mult--)
-    {
-
-      if ($score{$current_player}{$zahl}<3)
-      {
-        $score{$current_player}{$zahl}++;
-        $self_scored++;
-        if ($sieb && ($score{$current_player}{$zahl} == 3))
-        {
-          for my $count (2..21)
-          {
-            $count = 25 if $count ==21;
-            if ( ($count % $zahl) == 0)
-            {
-              $score{$current_player}{$count} = 3;
-            }
-          }
-        }
-      } else {
-        $scho++;
-        for my $playernum (1..$numplayer)
-        {
-          if ($score{$playernum}{$zahl}<3)
-          {
-            $score{$playernum}{0}+=$zahl;
-            $scored++;
-          }
-        }
-      }
-    }
-    print $schuss if ($scored || $self_scored);
-    print "scored\n" if $scored;
-    print "scho\n" if $scho && not $scored;
-  } elsif ($mult eq 'btn') {
-    print $schuss;
-    $current_player++;
-    $round++ if $current_player > $numplayer;
-    $current_player=1 if $current_player > $numplayer;
-    # print "player\n";
-    print $player[$current_player-1]."\n";
-  }
-  print_score($schuss);
-}
-
-
-
-sub print_score
-{
-  my ($schuss) =@_;
-# $term->Tputs('cl', 1, <STDERR>);
-  printf STDERR "\n\n";
-  printf STDERR "$schuss Runde\t$round\n\n";
-  for my $playernum (1..$numplayer)
-  {
-
-    printf STDERR "%s\t", ($playernum == $current_player)?"(".$player[$playernum-1].")":$player[$playernum-1];
-  }
-  print STDERR "\n";
-  for my $i (1..21)
-  {
-    for my $playernum (1..$numplayer)
-    {
-      my $zahl = $i>20?25:$i;
-      next if not gueltig($zahl);
-      printf STDERR ("%2d %s    ",$zahl, '#' x $score{$playernum}{$zahl}. '-' x (3-$score{$playernum}{$zahl}));
-    }
-    print STDERR "\n";
-  }
-  for my $playernum (1..$numplayer)
-  {
-
-    printf STDERR ("%3d\t", $score{$playernum}{0});
-  }
-}
diff --git a/dart/dart-nochecricket.pl b/dart/dart-nochecricket.pl
deleted file mode 100755 (executable)
index 5e8b897..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use POSIX;
-use Term::Cap;
-# General terminal line I/O
-my $termios = new POSIX::Termios;
-$termios->getattr;
-my $term = Term::Cap->Tgetent( { OSPEED => $termios->getospeed } );
-
-
-
-# Extract the entry of the terminal type
-
-# clear
-
-my (@player) = @ARGV;
-
-my $numplayer = @player;
-my $round =0;
-my %score;
-my $unlock=6;
-my $unlock_mult=1;
-my $current_player=1;
-my $last_shot=6;
-my $last_shot_mult=1;
-while ( my $schuss = <STDIN>)
-{
-  print $schuss;
-       my ($mult,$zahl) = split /\s+/, $schuss;
-   
-  if ($mult =~/^\d$/)
-       {
- $last_shot=$zahl;
- $last_shot_mult=$mult;
-               if ($unlock == $zahl && $unlock_mult== $mult)
-               {
-                       $unlock =0;
-                       $unlock_mult=0;
-               }
-         if($zahl >14 && $zahl <21 && ! $unlock)
-               {
-                       while($mult--)
-                       {
-                               if ($score{$current_player}{$zahl}<3)
-                               {
-                                       $score{$current_player}{$zahl}++;
-                               } else {
-                                       for my $playernum (1..$numplayer)
-                                       {
-                                               if ($score{$playernum}{$zahl}<3)
-                                               {
-                                                       $score{$playernum}{0}+=$zahl;
-                                                       print "score\n";
-                                               }
-                                       }
-                               }
-                       }
-               }
-       } else {
-    $current_player++;
-    $round++ if $current_player > $numplayer;
-    $current_player=1 if $current_player > $numplayer;
-               if (!$unlock)
-               {
-                 $unlock=$last_shot;
-                 $unlock_mult=$last_shot_mult;
-                       }
-       }
-       print_score($schuss);
-}
-
-
-
-sub print_score
-{
- my ($schuss) =@_;
-# $term->Tputs('cl', 1, <STDERR>);
- printf STDERR "\n\n";
- printf STDERR "$schuss $unlock_mult x $unlock Runde\t$round\n\n";
-                               for my $playernum (1..$numplayer)
-                               {
-
-                                                               printf STDERR "%s\t", ($playernum == $current_player)?"(".$player[$playernum-1].")":$player[$playernum-1];
-                               }
-                               print STDERR "\n";
-                               for my $i (15..20)
-                               {
-                                                               for my $playernum (1..$numplayer)
-                                                               {
-                                                                                               my $zahl = $i>20?25:$i;
-                                                                                               printf STDERR ("%2d %s    ",$zahl, '#' x $score{$playernum}{$zahl}. '-' x (3-$score{$playernum}{$zahl}));
-                                                               }
-                                                               print STDERR "\n";
-                               }
-                               for my $playernum (1..$numplayer)
-                               {
-
-                                                               printf STDERR ("%3d\t", $score{$playernum}{0});
-                               }
-}
diff --git a/dart/dart-soundonly.pl b/dart/dart-soundonly.pl
deleted file mode 100755 (executable)
index a9950bb..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/usr/bin/perl -T -w
-use strict;
-$ENV{PATH}='';
-$| = 1;
-&main();
-exit 0;
-
-sub main
-{
-  while (my $schuss = <STDIN>)
-  {
-    chomp $schuss;
-               
-    my ($mult,$zahl)=split /\s+/,$schuss or next;
-
-    if ($mult eq "btn") {
-      print "player\n";
-      next;
-    } elsif (not $mult =~ /^\d+$/) {
-      print "$mult\n";
-      next;
-    } elsif ($mult==2) {
-      print "double\n";
-    } elsif ($mult==3) {
-      print "triple\n";
-    } 
-    if (not $zahl =~ m/\d+/)
-    {
-      print STDERR "Unexpected input $zahl\n";
-      next;
-    }
-    ($zahl) = $zahl =~ m/(\d+)/;
-    if ($zahl >0 && $zahl < 21)
-    {
-      print $zahl . "\n";
-    } else {
-      print "bull\n";
-    }
-  } 
-}
-
diff --git a/dart/dart-template.pl b/dart/dart-template.pl
new file mode 100644 (file)
index 0000000..f6a3e26
--- /dev/null
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+use strict;
+use Dart;
+
+$|=1;
+my (@player) = @ARGV;
+
+my $dart = new Dart(player_names=>\@player, 
+                    callbacks => {
+                      shoot=>\&shoot,   
+                      next_player=>\&next_player,
+                      before_shoot=>\&print_score,
+                      init=>\&init,
+                    }
+                  );
+exit $dart->run();
+
+### ===============================
+
+sub init
+{
+  my $self=shift;
+  # TODO
+}
+
+sub win_condition
+{
+  my ($self) = @_;
+  # TODO
+  return 0;
+}
+
+sub shoot
+{
+  my $self=shift;
+  my ($mult,$zahl)=@_;
+  # $self->get_current_player()->{score} = {} if not $self->get_current_player()->{score}; 
+
+  # if (not gueltig($zahl,$mult))
+  # {
+  #   $self->shout("miss");
+  #   return;
+  # }
+
+  # $self->shout_last_shoot() if ($scored || $self_scored);
+  # $self->shout("scored") if $scored;
+  # $self->shout("scho") if $scho && not $scored;
+  # $self->win() if &win_condition($self);
+}
+
+sub next_player
+{
+  my $self=shift;
+
+  # TODO
+}
+
+sub print_score
+{
+  my ($self)=@_;
+  printf STDERR "\n\n";
+  printf STDERR "Runde\t%d\n\n",$self->{round};
+  for my $player_idx (0..($self->{player_count}-1))
+  {
+    printf STDERR "%s\t", ($player_idx == $self->{current_player})?"(".$self->get_player($player_idx)->{name}.")":$self->get_player($player_idx)->{name};
+  }
+  print STDERR "\n";
+  
+  # TODO
+}