Ask HN: Help me design better object relationship for a simulation
There's a bit more to it like people just loitering around waiting for flights or browsing the duty free etc.
I have modelled all of this the simplest way possible:
0 - It's done in Python
1 - I have an object called "Grid" which is basically a 2d array with a bunch of methods to add and remove elements at specific positions and to print it self so I can visualise it. Think of it as 2d map. It also deals with the "GameLoop" asking for every passenger for a next position every loop and "moving them".
2 - I have another object called "Passenger" which is a bit more interesting: ..2a Passenger can be given a X,Y destination and it'll use a pathfinding algorithm to decide how to reach X,Y (avoiding walls, other Passengers et) ..2b Passengers have a method that returns the "next move" based on whether the next item on its path is "blocked" or not, if it is it'll wait for it to be unblocked. As multiple passengers start walking across the map, they may be in each other's way so one might have to wait for a "round".
My main question is todo with "modelling correctness":
1 - Intuitively I need to insert Passenger objects into the Grid object. 2 - For Passengers to move they currently need a reference back to the Grid object in order to "see what's around them" and to define the Path using pathfinding.
Should the Passengers have a reference back to Grid? Should methods called in the Passenger be allowed to mutate the Grid?
I guess my question is: Should object dependency be unidirectional...?