<s> class Environment ( object ) : <EOL> def __init__ ( self , agents , initial_state ) : <EOL> self . agents = agents <EOL> self . initial_state = initial_state <EOL> self . state = initial_state <EOL> def run ( self , steps = <NUM_LIT> , viewer = None ) : <EOL> self . state = self . initial_state <EOL> for step in xrange ( steps ) : <EOL> if self . is_completed ( self . state ) : <EOL> return <EOL> self . step ( viewer = viewer ) <EOL> def step ( self , viewer = None ) : <EOL> "<STR_LIT>" <EOL> if not self . is_completed ( self . state ) : <EOL> for agent in self . agents : <EOL> action = agent . program ( self . percept ( agent , self . state ) ) <EOL> next_state = self . do_action ( self . state , action , agent ) <EOL> if viewer : <EOL> viewer . event ( self . state , action , next_state , agent ) <EOL> self . state = next_state <EOL> if self . is_completed ( self . state ) : <EOL> return <EOL> def do_action ( self , state , action , agent ) : <EOL> "<STR_LIT>" <EOL> raise NotImplementedError ( ) <EOL> def is_completed ( self , state ) : <EOL> "<STR_LIT>" <EOL> return False <EOL> def percept ( self , agent , state ) : <EOL> "<STR_LIT>" <EOL> return self . state <EOL> class RLEnvironment ( Environment ) : <EOL> def __init__ ( self , agents , initial_state ) : <EOL> super ( RLEnvironment , self ) . __init__ ( agents , initial_state ) <EOL> def step ( self , viewer = None ) : <EOL> super ( RLEnvironment , self ) . step ( viewer ) <EOL> for agent in self . agents : <EOL> agent . set_reward ( self . reward ( self . state , agent ) , self . is_completed ( self . state ) ) <EOL> def reward ( self , state , agent ) : <EOL> raise NotImplementedError ( ) </s>
