added dart red/blue
authorrealraum <realraum@realraum.at>
Mon, 12 Dec 2011 21:45:42 +0000 (21:45 +0000)
committerrealraum <realraum@realraum.at>
Mon, 12 Dec 2011 21:45:42 +0000 (21:45 +0000)
dart/Dart.pm
dart/dart-red-x01.pl
dart/plot.py [new file with mode: 0755]
dart/start-dart.sh

index 7adec4a..3e5dbca 100644 (file)
@@ -24,6 +24,12 @@ sub new
   return $self;
 }
 
+sub trace_shoot
+{
+  my $self=shift;
+  my ($property)=@_;
+  push @{$self->{trace_shoot}},$property;
+}
 
 sub get_color
 {
@@ -46,6 +52,7 @@ sub init
   $self->{current_player}=0;
   $self->{player_count}=@{$self->{player}};
   $self->{active_player_count}=$self->{player_count};
+  $self->{trace_shoot_data}={};
   $self->callback('init');
 }
 
@@ -122,12 +129,34 @@ sub shoot
   {
     $self->{current_shoot}={mult=>$mult,number=>$number};
     $self->{current_shoot_count}++;
-    return $self->callback('shoot',$mult,$number);
+    my $result = $self->callback('shoot',$mult,$number);
+    for my $trace_prop ( @{$self->{trace_shoot}})
+    {
+      push @{$self->{trace_shoot_data}{$self->{current_player}}},$self->get_current_player()->{$trace_prop};
+    }
+    return $result;
   } else {
     return 0;
   }
 }
 
+sub plot_trace_shoot
+{
+  my $self=shift;
+  my $datastr;
+  for my $player_num (keys %{$self->{trace_shoot_data}})
+  {
+    $datastr.=$self->get_player($player_num)->{name}.':';
+    $datastr.= join ',',@{$self->{trace_shoot_data}{$player_num}};
+    $datastr.="\n";
+  }
+  chomp $datastr;
+  my $plotter;
+  open($plotter,"|./plot.py") or return;
+  print $plotter $datastr;
+  close $plotter;
+}
+
 sub shout_last_shoot
 {
   my $self=shift;
index 78c3a9e..af4491c 100755 (executable)
@@ -13,8 +13,10 @@ my $dart = new Dart(player_names=>\@player,
                       next_player=>\&next_player,
                       before_shoot=>\&print_score,
                       init=>\&init,
+                      end_game=>\&Dart::plot_trace_shoot,
                     }
                   );
+$dart->trace_shoot('score');
 exit $dart->run();
 
 ### ===============================
@@ -22,7 +24,6 @@ exit $dart->run();
 sub init
 {
   my $self=shift;
-
   for my $player_idx (0..($self->{player_count}-1))
   {
     $self->get_player($player_idx)->{score} = $maxScore;
diff --git a/dart/plot.py b/dart/plot.py
new file mode 100755 (executable)
index 0000000..d427488
--- /dev/null
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+
+import fileinput
+import numpy
+import pylab
+labels=[];
+for line in fileinput.input():
+  (label,foo,datastr)=line.partition(":")
+  labels.append(label)
+  data = numpy.array(datastr.split(","))
+  pylab.plot(range(len(data)),data,label=label)
+  pylab.hold(True)
+
+pylab.legend()
+pylab.show()
+          
index 3d5471f..e73380c 100755 (executable)
@@ -24,6 +24,7 @@ signal_handler()
 stty -echo
 ssh dart killall ttyread 2>&1
 ssh dart ttyread /dev/ttyDart  >$FIFO &
+cd $MYPATH
 $MYPATH/eet $FIFO | perl -I $MYPATH $MYPATH/dart-$mode.pl $* | $MYPATH/../dart-sounds/src/dart-sounds $MYPATH/../dart-sounds/media > /dev/null
 rm -rf $FIFO_D