@Override
	public void process(SimEvent event) {
		NodeReachedEvent _event = (NodeReachedEvent) event;
		this.setPosition(_event.getPosition()); //Sets the actual position to the one provided by the event.
		System.out.println(getName() + "@" + getEngine().getCurrentTime() + ": reached node (" + getPosition().getX() + "," + getPosition().getY() + ")");
		getLog().addNode(getPosition(), getEngine().getCurrentTime()); // Save the reached Node to the log.
		
		if(getLabyrinth().isEndpoint(getPosition())){
			System.out.println(getName() + ": finished");
			getEngine().stop();
		}
		else{
		
			switch(_mode){
			case search:
				if(getLabyrinth().isWallAhead(getPosition(), getDirection())){ // The agent found a wall
					this._mode = eMode.follow;
					System.out.println(getName() + "@" + getEngine().getCurrentTime() + ": entered follow mode");
					int _newDirection = getDirection();
					do{ //The agent turns left until the wall is to it's right.
						_newDirection -= 90;
						if(_newDirection < 0){
							_newDirection += 360;
						}
					}
					while(getLabyrinth().isWallAhead(getPosition(), _newDirection));					
					setDirection(_newDirection);
					
					NodeReachedEvent _newEvent = new NodeReachedEvent(getLabyrinth().getNodeAhead(getPosition(), getDirection()), getEngine().getCurrentTime() + getTicksPerLength(), 1, this);
					getEngine().insertEvent(_newEvent);
				}
				else{ // The agent travels forward
					NodeReachedEvent _newEvent = new NodeReachedEvent(getLabyrinth().getNodeAhead(getPosition(), getDirection()), getEngine().getCurrentTime() + getTicksPerLength(), 1, this);
					getEngine().insertEvent(_newEvent);
				}
				break;
			case follow:
				if(getLabyrinth().isWallAhead(getPosition(), (getDirection()+90))){ // The agent has a wall to it's right
					int _newDirection = getDirection();
					while(getLabyrinth().isWallAhead(getPosition(), _newDirection)){ // The agent turns left, if it has a wall in front.
						_newDirection -= 90;
						if(_newDirection < 0){
							_newDirection += 360;
						}
					}
					setDirection(_newDirection);
					
					NodeReachedEvent _newEvent = new NodeReachedEvent(getLabyrinth().getNodeAhead(getPosition(), getDirection()), getEngine().getCurrentTime() + getTicksPerLength(), 1, this);
					getEngine().insertEvent(_newEvent);
				}
				else{ // The Agent has no wall to it's right. So it has to turn right to follow it.
					setDirection(getDirection() + 90);
					NodeReachedEvent _newEvent = new NodeReachedEvent(getLabyrinth().getNodeAhead(getPosition(), getDirection()), getEngine().getCurrentTime() + getTicksPerLength(), 1, this);
					getEngine().insertEvent(_newEvent);
				}
				break;
			}			
			
		}
		
	}