mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +02:00
client/example: Prefer diagonal moves; some extra comments
This commit is contained in:
parent
ca7dbc3962
commit
83bbb30125
1 changed files with 9 additions and 3 deletions
|
@ -63,14 +63,19 @@ sub tick($) {
|
||||||
sub take_action($%) {
|
sub take_action($%) {
|
||||||
my ($socket, %state) = @_;
|
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.
|
# 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]);
|
my @dirs = ([0, -1], [1, -1], [1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1]);
|
||||||
|
|
||||||
# Move/attack desires for each direction.
|
# 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));
|
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) }
|
sub dirindex { my ($dir) = @_; $dir->[0]+1 + 3*($dir->[1]+1) }
|
||||||
|
|
||||||
# Relative x,y coordinates for each visual input, in order.
|
# 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],
|
[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];
|
my $max = $dirs[1];
|
||||||
|
# Default direction in case of nothing interesting in the vicinity
|
||||||
|
# is [1, -1].
|
||||||
|
|
||||||
for my $i (0..$#{$state{visual}}) {
|
for my $i (0..$#{$state{visual}}) {
|
||||||
my ($type, $agent) = split(//, $state{visual}->[$i]);
|
my ($type, $agent) = split(//, $state{visual}->[$i]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue