	SUBROUTINE AUTO(ID)
C	ROUTINE TO HANDLE AUTOMATED CRAWLERS.
C----------------------standard common block----------------------------
C 
	COMMON ICR(8,12),IPARM(10),IS1,IS2,NT,ICU(10,10,10,2),CLEAR(8)
	COMMON MARKER(4,3,3)
	LOGICAL*1 ICU,CLEAR
C 
C-----------------------------------------------------------------------
	LOGICAL*1 ARR(6)
	DIMENSION IRA(6)
	LUN=ICR(ID,8)
	IWT=0  ! ASSUME NOT TRACKING ANYONE.
	WRITE(LUN,1)
	IF(ICR(ID,1).NE.3) GOTO 50  ! LOST IF OUT OF CUBE
	I0=ICR(ID,10)
	J0=ICR(ID,11)
	K0=ICR(ID,12)
	IE=ICU(I0,J0,K0,2) ! GET CUBE ENERGY
	ICU(I0,J0,K0,2)=0 ! ZERO CUBE ENERGY
	ICR(ID,9)=ICR(ID,9)+IE  ! STORE ENRGY FROM CUBE SPACE
C 
1	FORMAT(' [under cube control]')
	ND=0   ! CLEAR SCREEN ON FIRST CALL TO PSCAN ONLY....
2	IF(ICR(ID,1).EQ.0) GOTO 60  ! DEATH !
	CALL PSCAN(ID,ARR,IRA,ND)
	IF(IPARM(1).NE.0) GOTO 200
	ICE=ICU(I0,J0,K0,2)+IE  ! GET CURRENT CUBE AREA ENERGY
	WRITE(LUN,11) ICR(ID,9),IE,ICE,"33,CLEAR(ID)
11	FORMAT(
     C' | ENERGY LEVEL  |  ',I3,'  |',I3,'/',I3,' units absorbed |'/
     C' +-------+-------+-------+-------+-------+-------+',2A1)
	IE=0
C 
C 
C	CHECK IF ANY FEASIBLE MOVES:
200	DO 40 I=1,6
	IF(IRA(I).GT.1) GOTO 41   !  CAN MOVE IN THAT DIRECTION
	IF(ARR(I).EQ.'[') GOTO 41 ! DOORWAY...
40	CONTINUE
C	NO MORE MOVES, ATTEMPT RANDOM JUMP:
	IF(IE.LT.5) GOTO 4
	CALL JUMP(ID)
	GOTO 2
C 
41	IF(ICR(ID,9).LT.3) GOTO 4  ! ENERGY TOO LOW
C 
C	CHECK IF ANY CRAWLERS ON SCANNER, TARGET ON CLOSEST ONE
	IX=25
	IZ=0
	IW=0
	ITRACK=0
	DO 52 I=1,6
	IF(ARR(I).GT.'8'.OR.ARR(I).LT.'1') GOTO 52
	IY=ARR(I)-48
	IF(ICR(IY,1).NE.1) GOTO 52
	IF(IRA(I).GE.IX) GOTO 52
	IX=IRA(I)
	IZ=I
	IW=IY
52	CONTINUE
	IF(IZ.EQ.0) GOTO 55
	IF(IPARM(1).EQ.0) WRITE(LUN,53) IW
	IF(IWT.NE.IW) WRITE(ICR(IW,8),54) IW,ID
	IWT=IW ! PREVENT WARNING MORE THAN ONCE PER TURN
C	(UNLESS TRACKING A DIFFERENT CRAWLER)
	ITRACK=1
53	FORMAT(' tracking crawler',I2)
54	FORMAT(' warning crawler',I2,' --'/
     C10X,' scanners report crawler',I2,' is tracking you')
C	IZ IS DIRECTION TO CRAWLER (1,2,3,4,5,6)
	IF(IZ.EQ.1) GOTO 55  ! ALREADY FACING IT
	IF(IZ.EQ.2) CALL ROTATE('L',ID)
	IF(IZ.EQ.4) CALL ROTATE('R',ID)
	IF(IZ.EQ.5) CALL ROTATE('U',ID)
	IF(IZ.EQ.6) CALL ROTATE('D',ID)
	IF(IZ.NE.3) GOTO 2
	CALL ROTATE('L',ID)
	CALL ROTATE('L',ID)
	GOTO 2
55	IS=-5  ! FLAG TO MOVE
C	GIVE SOME CHANCE OF TURNING FROM A STRAIGHT LINE WITHOUT
C	HAVING TO HIT AN OBSTACLE FIRST:
	IF(RAN(IS1,IS2).LT..970) CALL MOVE(ID,IS)
	IF(IS.GT.0) GOTO 2
	X=RAN(IS1,IS2)
	A='L'
	IF(X.GT..25) A='R'
	IF(X.GT..50) A='U'
	IF(X.GT..75) A='D'
	CALL ROTATE(A,ID)
	GOTO 2
50	IF(IPARM(1).EQ.0) WRITE(5,51)
51	FORMAT(' .....crawler is lost outside the cube.....'/)
	ICR(ID,1)=0  ! DEATH
	GOTO 60
4	IF(IPARM(1).EQ.0) WRITE(LUN,5)
5	FORMAT(' crawler energy too low to continue')
60	RETURN
	END
