# world as an agent -- MUST BE MADE THREAD SAFE!
# is not satisfied as long as there are changes,
# that agents can make .. so should not quit
# as long as there are agents left. how to do that?
# agents must be in a world. so check for backlinks here
# .. if no way to do that, make the agents register?

import agents
import threading

class World(agents.agent):
	agents=[]
	items=[]
	places=[]
	changes=0

        def __init__(self, world):
                threading.Thread.__init__(self)
		# as the only exception, the world agent is not in any world

	def observe(self):
		if not self.agents: self.satisfied=1
		
	def run(self):
		while not self.satisfied:
			self.observe()
			if self.changes:	#act if others have..
				self.act()

	def exists(self, item):
		d=[]
		for c in self.items:  	# check whether this type exists
			if isinstance(c, item): d.append(c)

		return d	# the list of instances of the type

	def add(self, item):	#for adding items (non-reasoning objects)
		self.items.append(item)     #how about these's actions,
		self.changes=self.changes+1 # e.g. the ticks of a clock?
					    # ah world renders of course

	def delete(self, item):
		self.items.remove(item)
		self.changes=self.changes+1

	def register(self, agent):	#for reasoning agents to register
		self.agents.append(agent)

	def retire(self, agent):	#whan a reasoning agent quits
		self.agents.remove(agent)

#superclass for everything, i.e. all items that can exist in the world
class item:
	def create(self, world): # items can be created i.e. added to world
		world.add(self)

#class place:
#	location=[x,y,z]
