From 83bbb3012549f1cd256fd900e57c2d99523614f1 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sat, 3 Dec 2011 19:31:53 +0100 Subject: [PATCH] client/example: Prefer diagonal moves; some extra comments --- client/example.pl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/client/example.pl b/client/example.pl index 2de5908..ab72aff 100755 --- a/client/example.pl +++ b/client/example.pl @@ -63,14 +63,19 @@ sub tick($) { sub take_action($%) { my ($socket, %state) = @_; + # FIXME: We use a common direction choice for both move_dir + # and attack_dir, but in fact the agent can do both actions + # in a single tick and they can be in different directions. + # Relative x,y coordinates for each movement/attack direction. my @dirs = ([0, -1], [1, -1], [1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1]); # Move/attack desires for each direction. - my @move = ((0, 0, 0), (0, 0, 0), (0, 0, 0)); + # We prefer moves in the diagonal direction. + my @move = ((1, 0, 1), (0, 0, 0), (1, 0, 1)); my @attack = ((0, 0, 0), (0, 0, 0), (0, 0, 0)); - # dirindex($x) returns @move, $attack index for given @dirs item. + # dirindex($x) returns @move, @attack index for given @dirs item. sub dirindex { my ($dir) = @_; $dir->[0]+1 + 3*($dir->[1]+1) } # Relative x,y coordinates for each visual input, in order. @@ -79,8 +84,9 @@ sub take_action($%) { [0, -2], [1, -2], [2, -2], [2, -1], [2, 0], [2, 1], [2, 2], [1, 2], [0, 2], [-1, 2], [-2, 2], [-2, 1], [-2, 0], [-2, -1], [-2, -2], [-1, -2], ); - # Default direction in case of nothing interesting in the vicinity. my $max = $dirs[1]; + # Default direction in case of nothing interesting in the vicinity + # is [1, -1]. for my $i (0..$#{$state{visual}}) { my ($type, $agent) = split(//, $state{visual}->[$i]);