mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +02:00
Example client: Track agent_id in the state
This commit is contained in:
parent
5148607134
commit
2e42c268f1
1 changed files with 6 additions and 1 deletions
|
@ -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:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue