Sorry for the slightly demented wording of this question, but I'm very new to agent-oriented thinking (are these 'patterns'?) and only slightly less new to java, and I'm struggling with what feels like a very basic problem.
I'm doing a lot of this 'intuitively' (i.e. blindly) rather than trying to understand someone else's code - partly because I struggle to understand code that's 'above my level', but also because I hope doing it 'my way' will help me appreciate the right way later.
Basically, I'm modelling an agent (a robot vacuum) in an environment (a House). A House contains a collection (HashMap) of Rooms. A House has a method getRoom(int key)
that returns a Room matching the given key. The Agent has a State, which at this point keeps track of a room ID (which is also the key in the House), which is the room the robot is 'in' for the purposes of navigating the world; a State also describes whether or not the room is known to be dirty. When the agent is constructed, it's initialised with an ID (It must be created 'in a room'), but it is not given the dirty/clean status of the Room. I want the agent to check for dirt - this would involve invoking the getRoom()
method in House. However, with the Java I've learned so far, I don't know how to do this. I know I could access that method by creating a House inside java, or by making the method static, but those won't work - the agent needs to know about the SPECIFIC house that is in memory, the one that has been initialised with Rooms.
tl;dr: How can an Agent object obtain a reference to an object that is stored in a HashMap inside another Environment object?
P.S here is my imagined model for the 'higher level' perspective enabled by this approach: I kind of intuitively wanted the Agent to be wholly responsible for its own precepts and behaviours, so that the code higher up would look more like:
agent.percieve() //agent checks the room it thinks its in for dirt and exits
if (agent.gotDirt()) agent.clean() //agent activates its cleaning device if it found dirt in this room
if (agent.gotDirt() == false) agent.move() //agent picks an exit and leaves the room