X-Git-Url: https://git.realraum.at/?a=blobdiff_plain;f=dart%2FDart.pm;h=51f3554a205336ec38ce7cf76cb84918154628f4;hb=3c56468dcf725e2b51076295f16601f8f025922e;hp=ebb36bb1831a904d6b1818a05c89f67b5ff72fe5;hpb=fd324a0bfe9ee3b2a2b0ddcb89b39986071b6215;p=svn42.git diff --git a/dart/Dart.pm b/dart/Dart.pm index ebb36bb..51f3554 100644 --- a/dart/Dart.pm +++ b/dart/Dart.pm @@ -24,6 +24,24 @@ sub new return $self; } +sub trace_shoot +{ + my $self=shift; + my ($property)=@_; + push @{$self->{trace_shoot}},$property; +} + +sub get_color +{ + my $self=shift; + my ($mul,$zahl)=@_; + my @zahlen = qw/20 1 18 4 13 6 10 15 2 17 3 19 7 16 8 11 14 9 12 5 25/; + my $counter=0; + $counter++ while($zahl != shift @zahlen and @zahlen); + $mul=0 if $mul >1; + my $result = ($counter+$mul )%2; + return $result; +} sub init { @@ -34,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'); } @@ -71,6 +90,7 @@ sub run $self->{sound_out_fh}=$sound_out_fh; push @history, Clone::clone($self); + print "\033[2J"; $self->callback('before_shoot'); #while ( my $shoot_data = <$data_in_fh>) while ( my $shoot_data = ) @@ -81,6 +101,7 @@ sub run if ($mult =~/^\d$/) { die "Unexpected input" if not $number=~/^\d+$/; + next if not $self->{current_shoot_count} < $self->{max_shoots_per_player}; $self->shoot($mult,$number); } elsif ($mult eq 'btn') { $self->next_player(); @@ -92,8 +113,12 @@ sub run $self->reset_game(); } elsif ($mult eq 'quit') { return; + } else { + # shitty input + next; } push @history, Clone::clone($self); + print "\033[2J"; $self->callback('before_shoot'); } } @@ -106,12 +131,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; @@ -209,7 +256,8 @@ sub win if ($self->{active_player_count}==1) { $self->next_player(); - $self->lose(); + $self->shout('lose'); + $self->deactivate_current_player($self->{player_count}-$self->{active_player_count}+1); } } @@ -221,7 +269,8 @@ sub lose if ($self->{active_player_count}==1) { $self->next_player(); - $self->win(); + $self->shout('win'); + $self->deactivate_current_player($self->{active_player_count}); } }