Ant war! by nikor
Welcome to Ant war!
The idea was to make a programming game in the style of zachtronics games.
This is how far i got on the journey that is the lack of scope control :)
| Link | http://nikor.dk:5000/ |
| Original URL | https://ldjam.com/events/ludum-dare/56/ant-war |
Ratings
| Overall | 664th | 3.429⭐ | 23🧑⚖️ |
| Fun | 636th | 3.286⭐ | 23🧑⚖️ |
| Innovation | 19th | 4.286⭐ | 23🧑⚖️ |
| Theme | 298th | 3.952⭐ | 23🧑⚖️ |
| Graphics | 964th | 1.929⭐ | 23🧑⚖️ |
| Audio | 680th | 1.2⭐ | 17🧑⚖️ |
| Humor | 685th | 2.763⭐ | 21🧑⚖️ |
| Mood | 962th | 2.875⭐ | 22🧑⚖️ |
| Given | 10🗳️ | 20🗨️ |
Great Job!
But the jump from level 5 to Free Play feels huge. First I thought, I'm clever and just transition through the level like this:
```
(mind, sense) => {
if (mind == undefined) {
mind = ["up", 0];
for (var i = 0; i < sense.stop.friends.length; i++) {
sense.stop.friends[i] = ["up", (i+1) * 2]; }
}
let dir = mind[0];
if (mind[1] > 0) {
mind[1] -= 1;
return [dir, true, mind];
}
if (dir == "up") {
dir = "right";
} else {
dir = "up";
mind[1] = 1;
}
mind[0] = dir;
return [dir, true, mind];
}
```
But that doesn't work, because you actually need to pickup food and bring it back to the base to increase your ant army!
So after lots of trial and error, I managed to come up with this:
```
(mind, sense) => {
if (mind == undefined) {
mind = [false, 0, 0];
for (var i = 0; i < sense.stop.friends.length; i++) {
if (sense.stop.friends[i] == undefined) { sense.stop.friends[i] = [false, 0, 0]; } }
}
let dir = '';
if (mind[0] == true) {
if (mind[1] == 0 && mind[2] == 0) {
mind[0] = false;
} else if (mind[1] > 0) {
dir = 'left';
mind[1] -= 1;
} else if (mind[1] < 0) {
dir = 'right';
mind[1] += 1;
} else if (mind[2] > 0) {
dir = 'down';
mind[2] -= 1;
} else if (mind[2] < 0) {
dir = 'up';
mind[2] += 1;
}
}
if (dir == '') {
if (sense.up.enemies > 0) {
dir = 'up';
mind[2] += 1;
} else if (sense.down.enemies > 0) {
dir = 'down';
mind[2] -= 1;
} else if (sense.left.enemies > 0) {
dir = 'left';
mind[1] -= 1;
} else if (sense.right.enemies > 0) {
dir = 'right';
mind[1] += 1;
} else if (sense.up.food > 0) {
dir = 'up';
mind[0] = true;
mind[2] += 1;
} else if (sense.down.food > 0) {
dir = 'down';
mind[0] = true;
mind[2] -= 1;
} else if (sense.left.food > 0) {
dir = 'left';
mind[0] = true;
mind[1] -= 1;
} else if (sense.right.food > 0) {
dir = 'right';
mind[0] = true;
mind[1] += 1;
} else {
let rnd = Math.random();
if (rnd < 0.25) {
dir = 'up';
mind[2] += 1;
} else if (rnd < 0.5) {
dir = 'right';
mind[1] += 1;
} else if (rnd < 0.75) {
dir = 'down';
mind[2] -= 1;
} else {
dir = 'left';
mind[1] -= 1;
}
}
}
return [dir, true, mind];
}
```
The mind store 3 components in an array:
* mind[0] is a bool, which says if the ant currently has food
* mind[1] contains the x-offset to base (right of base is positive)
* mind[2] contains the y-offset to base (up of base is positive)
As soon as the ant finds some food it will return to the base immediately.
It takes ages to run the simulation, but I think, that the algorithm should work quite well in the long run. Here's how my army looks like after 5 minutes in "mostly random" mode:

But maybe there are other tricks to optimize it?
Anyway... Had lots of fun!