print "\n";
}
for my $unit (grep { $_->[3] } reading_sort(@units)) {
- say "$unit->[2] at $unit->[0],$unit->[1] ($unit->[3])"
+ say "# $unit->[2] at ($unit->[1]+$unit->[0]j) $unit->[3]"
}
}
sub move($unit) {
my %target_sq;
- for my $enemy (grep { $_->[2] ne $unit->[2] } @units) {
+ for my $enemy (grep { $_->[2] ne $unit->[2] && $_->[3] > 0 } @units) {
for my $sq (neigh_squares($enemy, '.')) {
if (!$target_sq{$sq->[0],$sq->[1]}++) {
# say "target square $sq->[0],$sq->[1]";
@reachable = reading_sort(@reachable);
my $target = $reachable[0];
- # say "moving to $target->[0],$target->[1] via $target->[2],$target->[3]";
+ say "moving to $target->[0],$target->[1] via $target->[2],$target->[3]";
$map[$unit->[1]][$unit->[0]] = '.';
$map[$unit->[1] = $target->[3]][$unit->[0] = $target->[2]] = $unit->[2];
}
return 1;
}
-my $elf_hp = 4;
+my $elf_hp = 12;
$elf_hp++ while !battle($elf_hp);
-# There is a bug out there - on the real puzzle input it returned
-# remaining hp lower by three, which means there had to be one less Goblin
-# attack somewhere.