I Coded an ANT COLONY in Python… You Won’t Believe How They Behave!

preview_player
Показать описание
If you enjoyed the video, please leave a like, subscribe and comment to help me grow my channel! :))

I created a repository since some of you are asking for the code. Sorry if the code is messy ;)

Music tracks:
Cinematic by Aylex
Royalty Free Music for Video (Safe)

Pure Dream by Kashia
Background Music for Videos (Free)

Yellow Flower by Kashia
Background Music for Videos (Free)

Deep Sadness by Kashia
Free Background Music for Videos

Beloved by Kashia
No Copyright Vlog Music for Videos

Not Too Far by Another Kid & MohRiz
Free No Copyright Music Download

Timestamps:
00:00 - Intro
00:36 - Ants
01:13 - First Version of Code
01:35 - First Simulation
01:50 - Ant Behavior Explanation
02:06 - Introducing Pheromones
02:26 - Pheromone Code
02:38 - Following Pheromones
03:06 - Second Simulation (With Pheromones)
03:26 - Improving Code
03:36 - Third Simulation (Pheromones Working Better)
03:50 - Further Changes to Code
04:05 - Fourth Simulation (Much Better Pheromones)
04:20 - Optimizing Code
04:40 - Minor Improvements
05:22 - Spatial Partitioning Explanation
05:50 - Implementing Spatial Partitioning
06:40 - Trying Out Spatial Partitioning
07:12 - Spatial Partitioning Almost Working
07:28 - Fixing Minor Bug
07:38 - Spatial Partitioning Finally Working
07:53 - Some Cool Simulations
08:50 - Performance Comparison Between Versions - 100 Ants
09:30 - Performance Comparison Between Versions - 250 Ants
10:30 - Performance Comparison Between Versions - 500 Ants
11:13 - Final Simulation (The End)
Рекомендации по теме
Комментарии
Автор

You can make ants more realistic. They should go back home and stay there some time when they have low energy. Also add more types of pheromones, enemies or fights with other colonies.

okolenmi
Автор

I like how the first bug you met was a pheromone loop of death. It's kinda realistic.

Resursator
Автор

I love your way of presenting, and also that you show not just the success, but also the strugle you had with all the different problems and steps! Thats what programming is mostly about. Also very clean code, readable, necessities documented and well organized. Good work! Like every feedback, there is a "but"... The computation time and the fps... I'd highly recommend, especially when it comes down to visualising, using different python libraries which are already solving for that, such as numba, taichi, etc... There are a lot of different libraries out there optimized for not just matrix, but also tensor optimizations. If you wanna know more, I once made a good "speedcomparison" of all libraries and different implementations, demonstrated on the mandelbrot set (not released yet). Let me know, and I will share the sourcecode with you. Long story short: Keep up the good work :)

oli
Автор

0:02 ant colonies when humans aren't looking:

LangSphere
Автор

There's another fairly easy metric to implement. That's food levels in the any nest - ant pheromones change from building to scavenging when the food gets low. Also builders could allow more ants to live in the colony.

Hope you open source this, I'd love to have a play, I love ants, they're truly fascinating.

Gee
Автор

Ran your code through Claude and it enhanced it quite a bit. Nice work and very interesting.

jeffwads
Автор

I hate it when my ant simulation is full of bugs.

bit_pineapple
Автор

This is cool man. Keep it up, I enjoyed the video. Honestly shocked you aren't a bigger channel.

minatimanil
Автор

I love the project. It is very fundamental intelligence research / engagement with its concepts.
The only nitpick I have with the video was the jump in volumes. Your voice was very quiet and then the bass hit :D
But anyway, keep up the good work!

eventHorizonROstock
Автор

that was a great video, ants are great, and so is coding

i'm currently learning python actually, and i already know a bit, so i'll look into this to learn more about how to make great things like it

Bee-eautiful
Автор

Recommend making the cells larger relative to the ant detection radius. Say 9 squares covering the circle

charlesloeffler
Автор

You can rewrite ant logic to compute shader, which can potentially increase the performance to handle millions of them, also, i don't know whether kd tree or octtree can increase performance in comparison to grid, but it worth trying. In regard to ant simulation, maybe adding rival ants or other creatures can create interesting patterns.

rumble_bird
Автор

Neat. I never gave it much thought before, but can Python do a multiway tree? If so, I'd add a time component and sort by that along one tree. Add the lifespan to the starting timestamp to get the ending timestamp and sort by that, removing from both trees at the end of a particle's lifespan.

anon_y_mousse
Автор

Thank you so much for a well made and thought provoking video. I've mostly been thinking about the fewest numbers of phermones and fewest number of "rules" over the ants' behavior. One question, how do ants know where the nest is? I'm not sure they have individual awareness, other than "that direction smells like exploration, that direction smells like food, that direction smells like combat".
Just food for thought. Again, thanks.

dfunited
Автор

very nice, maybe try multiple types of pheromones? i dunno you did something pretty cool

maximeduchalet
Автор

Fascinating but I think you had an ant colony living in your microphone...

michaeldeloatch
Автор

it needs terrain and obstacles!
ants could also drop food
and of course there will need to be epic battles against other colonies ;)

marcelbricman
Автор

Already spent hours providing enough food to the ants using my mouse-buttons and mouse-wheels, a pleassure to watch ;-)
Interesting that in your first iterations the ants seem to leave a (blue) trail, appearing as lines - where in the later iterations (and when using your code on Guthub) they leave blue dots, have you noticed it as well?

rechtfrage
Автор

Nice project!
If you want any kind of feedback (or constructive criticism) on the video itself I think you should try to modulate your narrating a bit more. As in put some emphasis on some words here and there instead of just sounding so flat. I expect you're reading from a script, and that's the reason your voice never changes much.

cybermanne
Автор

Choosing the right algorithms and optimizations is always important but I wouldnt use python. If you want to go for speed and in this case simulating hundreds or thousand of ants you probably should go with zig. The only way python could be remotely close is by using numpy I think it was which uses C code behind making it fast.

Using zig with sfml for rendering would be a good way and probably a huge improvement, could be also interesting of comparing the speed to python but watch out for the rendering since that can make a difference aswell. I would write the logic code separate from the rendering code so running the simulation without any rendering can be a good way of measuring the performance.

Alternatively using c++ will give you similar performance but in my opinion it's easier than zig but memory safety is not enforced 👉👈

requestfx
welcome to shbcf.ru