village-sim
- 1 Devlogs
- 12 Total hours
I am building a fun and cool graphical people simulation. I simulate how multiple people with varies interests compete for shared resources, as in an economy.
I am building a fun and cool graphical people simulation. I simulate how multiple people with varies interests compete for shared resources, as in an economy.
Hello guys! I have started this little side project for two reasons. The first is that I want to take some time off to code without any help from AI. The second is that I have had a long-term interest in economics that I am only now beginning to acting on. Town Hall is an extremely simple economic simulation. The world I am modeling is one where everyone knows everything, there is only one kind of resource, people die if their resource count is 0 and people have full control over their resources and can invest them however they want (basically extreme capitalism). The scenario has some resemblance to real life but is exaggerated in some areas and extremely simplified.
The two biggest questions are:
What actions can an individual take?
AND:
How does an individual decide what action to do?
I have not fully answered the first question yet but for now I have added in these different options to serve as placeholders:
I am not super happy with these options and it is just something I came up with after a moment of thinking, it WILL change later.
The answer to the second question is that we are going to let the individuals “think” using neural networks. We can have as many inputs as we want and randomized weights and biases that determine the behavior. The output neurons will translate into some action. Pretty simple stuff. Since entities die when they have no resources and the amounts of resources are finite the neural networks that are better at gathering resources will be those that survive over time. Later on I might make new brains inherit some weights and biases from their parents as well to strengthen this dynamic.
The complexity here is that I want this to run on the GPU so that we can run big simulations without having to wait for several minutes. This means that I have to find some library that can do computational work on the GPU. I also have to store the neural networks in a GPU-friendly way so that I can easily send all of them in one batch. A few months ago I vibecoded a Vulkan matrix multiplier (GEMM) that works pretty well so I decided to use that.
Now the big challenge was to find a way of storing the weights and biases of the different networks in a convenient way. I decided on having a struct called BrainPool (yeah I don’t love that naming lol) that holds all the weights and all of the biases of every single brain of the entities in two different vectors as well as two vectors that store the offsets for the entities in the weights and biases vectors. The last part means that the EntityId that all entities contain can be used to look up the associated brain’s weights and biases. This part took some time to figure out and I also had to do some research as well which also took time.
Thanks for reading this far! This is all very early in development and hopefully I will have a basic version of it working in the next devlog. I am thinking of making this more graphical in the future. If you have any suggestions for improvements or functionality I would appreciate it if you wrote it in a comment. Have a good rest of your day!