From 2e42c268f168f9dd75c4267e18487051ff058f8e Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Mon, 26 Dec 2011 21:59:12 +0100 Subject: [PATCH] Example client: Track agent_id in the state --- client/example.pl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/example.pl b/client/example.pl index d6962ed..3637a33 100755 --- a/client/example.pl +++ b/client/example.pl @@ -41,6 +41,7 @@ my $remote_port; # The example agent uses $state to hold its state structure. It is # a HASHREF with the following fields: # { +# agent_id => NUMBER (agent id) # tick => NUMBER (current tick id) # energy => NUMBER (current energy) # visual => [ @@ -84,6 +85,10 @@ sub tick($$) { print "[ii] bred $id ($g)\n"; system("screen ./$0 $remote_port $id $g"); + } elsif ($type eq 'agent_id') { + $value =~ /^\d+$/ or die "[ee] type agent_id wrong value ($value)\n"; + $state->{agent_id} = $value; + } elsif ($type eq 'tick') { $value =~ /^\d+$/ or die "[ee] type tick wrong value ($value)\n"; $state->{tick} = $value; @@ -287,7 +292,7 @@ my $state = { gender => $gender }; while (1) { tick($socket, $state); # Debug print - print $state->{energy} . "\n"; + print $state->{agent_id} . " " .$state->{energy} . "\n"; print "visual [", join('], [', @{$state->{visual}}), "]\n"; # The following could be written more succintly, but it is here # to show possible iteration over pheromones: