improved multi cricket
authorrealraum <realraum@realraum.at>
Sat, 2 Jul 2011 20:41:30 +0000 (20:41 +0000)
committerrealraum <realraum@realraum.at>
Sat, 2 Jul 2011 20:41:30 +0000 (20:41 +0000)
dart/dart-fullcricket.pl
dart/dart-soundonly.pl
dart/start-dart.sh

index 1bb4049..fc20658 100755 (executable)
@@ -1,14 +1,20 @@
 #!/usr/bin/perl
 use strict;
-use POSIX;
-use Term::Cap;
+#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 $termios = new POSIX::Termios;
+#$termios->getattr;
+#my $term = Term::Cap->Tgetent( { OSPEED => $termios->getospeed } );
 
+sub gueltig{
+    my ($zahl,$mult) = @_;
+    return $zahl<6 || $zahl>20;
+  };
 
 
+$|=1;
+
 # Extract the entry of the terminal type
 
 # clear
@@ -21,61 +27,77 @@ my %score;
 my $current_player=1;
 while ( my $schuss = <STDIN>)
 {
-  print $schuss;
-       my ($mult,$zahl) = split /\s+/, $schuss;
-   
+  #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}++;
-                       } else {
-                               for my $playernum (1..$numplayer)
-                               {
-                                       if ($score{$playernum}{$zahl}<3)
-                                       {
-                                               $score{$playernum}{0}+=$zahl;
-                                               print "score\n";
-                                       }
-                               }
-                       }
-               }
-       } else {
+    {
+
+      if ($score{$current_player}{$zahl}<3)
+      {
+        $score{$current_player}{$zahl}++;
+        $self_scored;
+      } else {
+        $scho++;
+        for my $playernum (1..$numplayer)
+        {
+          if ($score{$playernum}{$zahl}<3)
+          {
+            $score{$playernum}{0}+=$zahl;
+            $scored++;
+          }
+        }
+      }
+    }
+    print $schuss if ($scored || $scho || $self_scored);
+    print "scored\n" if $scored;
+    print "scho\n" if $scho;
+  } elsif ($mult eq 'btn') {
+    print $schuss;
     $current_player++;
     $round++ if $current_player > $numplayer;
     $current_player=1 if $current_player > $numplayer;
-       }
-       print_score($schuss);
+    # print "player\n";
+    print $player[$current_player-1]."\n";
+  }
+  print_score($schuss);
 }
 
 
 
 sub print_score
 {
- my ($schuss) =@_;
+  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 "\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;
-                                                                                               printf STDERR ("%2d %s    ",$zahl, '#' x $score{$playernum}{$zahl}. '-' x (3-$score{$playernum}{$zahl}));
-                                                               }
-                                                               print STDERR "\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)
+    {
+      next if not gueltig($i);
+      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});
-                               }
+    printf STDERR ("%3d\t", $score{$playernum}{0});
+  }
 }
index 83c2d85..a9950bb 100755 (executable)
@@ -13,13 +13,20 @@ sub main
                
     my ($mult,$zahl)=split /\s+/,$schuss or next;
 
-    if ($mult==2)
-    {
+    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";
-    } elsif ($mult eq "btn") {
-      print "player\n";
+    } 
+    if (not $zahl =~ m/\d+/)
+    {
+      print STDERR "Unexpected input $zahl\n";
       next;
     }
     ($zahl) = $zahl =~ m/(\d+)/;
index 006d0a1..49960b1 100755 (executable)
@@ -6,6 +6,7 @@ if [ -z "$1" ]; then
 fi
 
 mode=$1
+shift
 
 ssh dart stty -F /dev/ttyDart 57600
-ssh dart cat /dev/ttyDart | ./dart-$mode.pl | ../dart-sounds/src/dart-sounds ../dart-sounds/media
+ssh dart cat /dev/ttyDart | ./dart-$mode.pl $* | ./dart-soundonly.pl | ../dart-sounds/src/dart-sounds ../dart-sounds/media > /dev/null