From 52738a9c3bc2b9bbd0729d8ba1dcb1b970681e67 Mon Sep 17 00:00:00 2001 From: realraum Date: Mon, 12 Dec 2011 21:45:42 +0000 Subject: [PATCH] added dart red/blue --- dart/Dart.pm | 31 ++++++++++++++++++++++++++++++- dart/dart-red-x01.pl | 3 ++- dart/plot.py | 16 ++++++++++++++++ dart/start-dart.sh | 1 + 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100755 dart/plot.py diff --git a/dart/Dart.pm b/dart/Dart.pm index 7adec4a..3e5dbca 100644 --- a/dart/Dart.pm +++ b/dart/Dart.pm @@ -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; diff --git a/dart/dart-red-x01.pl b/dart/dart-red-x01.pl index 78c3a9e..af4491c 100755 --- a/dart/dart-red-x01.pl +++ b/dart/dart-red-x01.pl @@ -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 index 0000000..d427488 --- /dev/null +++ b/dart/plot.py @@ -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() + diff --git a/dart/start-dart.sh b/dart/start-dart.sh index 3d5471f..e73380c 100755 --- a/dart/start-dart.sh +++ b/dart/start-dart.sh @@ -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 -- 1.7.10.4