I’ve covered a fair bit of simulations of people in news stories and recently read a chapter on people simulations in ‘ The Magic Machine: A Handbook of Computer Sorcery‘ and thought it was time to try a simple simulation.
This source code simulates 3 groups at a party. One group has a personal comfort zone of 1 foot, one group a zone of two feet and one a zone of three feet. Each group is a different color. The people start in random locations. As the party progresses and people move about they try to keep other people at their personal comfort zone. Each person moves to the square nearest himself that maximizes the comfort zone for himself. If that is not possible the person moves to a random spot ( mingles ).
If you deduct happiness from a person when they are crowded or lonely they move more than if no happiness points are deducted. They mingle more, deducting no points the crowd is more likely to form groups.
The code is heavily commented and should be easy to follow, source code is in Java.