Apostolique / Agar.io-bot

The aim of the project is to create a bot that can play Agar.io
MIT License
1.15k stars 1.92k forks source link

New evading algorithm #7

Closed Thunderkill closed 9 years ago

Thunderkill commented 9 years ago

A nice new evading algorithm could be easily done like this: Have a "Spike ball" around the player, when any threat intersects a line of the spiky ball: render that line(direction) unusable and use the other lines as free areas to go.

Demonstration: The red lines are intersected by threats, means we can't go that direction. Green lines are not intersected, we can evade to this direction Blue line is the invisible wall, if a line intersects this: it's a no-go. http://puu.sh/hL6NZ/7f7b94a697.png image

You could play around with the length of the lines to make it evade from further away.

Sorry for the crappy paint skills, hopefully you still get the point.

ghost commented 9 years ago

One thing I'd like is to have a reflex within miliseconds after a threat splits to split itself away. Nice concept.

Thunderkill commented 9 years ago

That would require quite complex math to split to the right direction depending how fast and from what angle the enemy is coming from (when splitting) but it is certainly doable.

Apostolique commented 9 years ago

That's a pretty interesting concept. I believe you can base the length of the lines according to the biggest enemy around. Also, the amount of lines to use can probably be determined by the density of the enemies in the area.

Apostolique commented 9 years ago

Looks like the algorithm is quite simple: http://mathworld.wolfram.com/Circle-LineIntersection.html

Apostolique commented 9 years ago

I thought of a way to enhance this algorithm. Angle Elimination

Essentially, you mark the angle intervals in which the enemies are present. Then you merge the intervals that overlap each others. Once merged, invert those intervals. The new interval is one which contains no enemy.

Based on how close you are from the borders, you can also add them as bad intervals.

phadeb commented 9 years ago

Yes, I find it a very good idea, worth implementing.

There should be an advanced "evade" function that detects these kind of escape patterns.

Also, it could be weighed, example : Cell A moving from X1 to X15, then radius angles that are close to those from X1 to X15 are easier for a human player to change course / split , and radius angles that go from x1 to x-15 (kind of a u-turn) are harder for a human player to change course and must be deemed more profitable for a split/escape/avoid.

This function could also integrate the "Team" mode and would be particularly amazing.

babon commented 9 years ago

:D http://youtube.com/watch?v=CxJtvcz0-Wg

cj81499 commented 9 years ago

This is a really good idea. I hope this gets implemented.

EDIT: I'd rather have it be scared like that than get eaten all the time.

Apostolique commented 9 years ago

I've coded a pretty good part of the algorithm, next part will be to make it more stable. The further away an enemy is, the less influence it should have over the evading process. This next part will also include data persistence. Right now, every frame, everything gets reevaluated. This means that when an enemy leaves the visible area, the bot completely forgets about them. I'll need to store everything in an intermediate array and update everything between each server message. This will also make it possible to compute the direction of everything which can help optimize everything even more.

ABraith commented 9 years ago

For persistence, it may be a good idea to have your array store food locations, enemy locations and sizes. You could then have values in the array decay slowly if not updated, and base decisions on where to move off averages of everything in the array. Even when running from enemies the bot should probably try and chase nearby food too somehow (maybe something like a 'fear' value deciding how much priority to give to chasing/running)

Apostolique commented 9 years ago

For practical purposes, I can't separate food, enemy, etc when keeping the data for longer otherwise there would be a lot of book keeping to do. It's a lot faster to just group everything together and operate on the cloned version. You can then remove stuff from that list when they are supposed to be removed and are also in vision. If they aren't in vision, time them out after a time.

The eating will be smoother than that. Right now in the beta, it simply follows the white line. Later, it will pick food based on how well they are located compared to the white line. It will be a trade off between food value, distance and how safe it is to go get it.