implemented agent state in a function called sensor scan