Table of Contents
I wanted to give Object-Oriented Programming a go on my own before taking the course this coming semester. Independent Study Period was the perfect opportunity to do that and get credit for it as well. I decided to implement an Agent based Sugarscape in Python to get some OOP experience.
I covered some topics of Sugarscape and some topics of OOP throughout this ISP and got to make some design choices on my own for the first time.
Sugarscape topics covered:
-
The Environment (The Sugarscape)
- Resource Distribution
- Resource Regeneration
-
Agents
- Searching, Moving, Eating
- Reproducing
OOP topics covered:
- Classes - Created classes for the environment, agents, and grid cells.
- Objects - Agents and cells were treated as objects.
- Encapsulation - Cell and Agent information is limited to its own class unless needed.
- Inheritance - A special Agent that can reproduce inherited from the Agent class.
- Polymorphism - The special Agent inherits the ability to update from Agent parent class but has unique updates as well.
The current state of my Sugarscape is basic. Although the Sugarscape content is basic, I got to learn and practice many OOP topics during this ISP. There are some issues with changing the grid dimensions. The way I scale the agent sprites doesn't work for higher grid dimensions.
Environment:
- Map
- Cell
- Current Sugar
- Maximum Sugar
- Regen Rate
- Current Agent
Agents:
- Agent
- Look
- Move
- Eat
- Die
- Reproductive Agent
- Everything Agent does
- Reproduce
In the future I there is plenty to add for Sugarscape. Alongside Sugarscape content I could add graphs and such to visualize population state for Agents. Sugarscape can end up being a decently sized project and I barely scratched the surface of it. I should also give Agents and Cells less information to better follow the OOP practice of encapsulation.
- Python3
- PyGame module
To run the program enter python3 sugarscape.py into the terminal.
Some properties of the simulation can be modified in the settings.py file:
- Grid Width/Height
- Window Resolution
- Number of Agents and Reproductive Agents
- Simulation Speed (FPS)


