From 60989d7588afa53e0e4913c61e1e6f6b4f3f7707 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Fri, 23 Dec 2011 18:48:29 +0100 Subject: [PATCH] Example client: Implement fleeing --- client/example.pl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/client/example.pl b/client/example.pl index 8a868b1..dea7f2d 100755 --- a/client/example.pl +++ b/client/example.pl @@ -21,7 +21,7 @@ $/ = "\r\n"; # The example agent does most of its decision making in the # take_action() subroutine. Its policy is to (in this order): # -# * Attack any other agents encountered. +# * Attack any other agents encountered (unless low on energy). # * Eat flowers if in immediate vicinity. # * Roam around semi-aimlessly, trying to look for food. # @@ -124,6 +124,9 @@ sub take_action($$) { # Default direction in case of nothing interesting in the vicinity # is [1, -1]. + # In the case of shortage of resources, prefer fleeing to fighting. + my $flee = ($state->{energy} < 10000); + # Examine our neighborhood and adjust preference for each direction # based on what we sense. for my $i (0..$#{$state->{visual}}) { @@ -148,8 +151,12 @@ sub take_action($$) { if ($agent eq 'A') { # Agent - $move[dirindex($dir)] += 7; - $attack[dirindex($dir)] += 1; + if (not $flee) { + $move[dirindex($dir)] += 7; + $attack[dirindex($dir)] += 1; + } else { + $move[dirindex($dir)] -= 7; + } } if ($move[dirindex($dir)] > $move[dirindex($max)] or