Example client: Track agent_id in the state

This commit is contained in:
Petr Baudis 2011-12-26 21:59:12 +01:00
parent 5148607134
commit 2e42c268f1

View file

@ -41,6 +41,7 @@ my $remote_port;
# The example agent uses $state to hold its state structure. It is # The example agent uses $state to hold its state structure. It is
# a HASHREF with the following fields: # a HASHREF with the following fields:
# { # {
# agent_id => NUMBER (agent id)
# tick => NUMBER (current tick id) # tick => NUMBER (current tick id)
# energy => NUMBER (current energy) # energy => NUMBER (current energy)
# visual => [ # visual => [
@ -84,6 +85,10 @@ sub tick($$) {
print "[ii] bred $id ($g)\n"; print "[ii] bred $id ($g)\n";
system("screen ./$0 $remote_port $id $g"); 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') { } elsif ($type eq 'tick') {
$value =~ /^\d+$/ or die "[ee] type tick wrong value ($value)\n"; $value =~ /^\d+$/ or die "[ee] type tick wrong value ($value)\n";
$state->{tick} = $value; $state->{tick} = $value;
@ -287,7 +292,7 @@ my $state = { gender => $gender };
while (1) { while (1) {
tick($socket, $state); tick($socket, $state);
# Debug print # Debug print
print $state->{energy} . "\n"; print $state->{agent_id} . " " .$state->{energy} . "\n";
print "visual [", join('], [', @{$state->{visual}}), "]\n"; print "visual [", join('], [', @{$state->{visual}}), "]\n";
# The following could be written more succintly, but it is here # The following could be written more succintly, but it is here
# to show possible iteration over pheromones: # to show possible iteration over pheromones: