	SUBROUTINE SEARCH
	COMMON IB(10,10),IA(8,2),IC(8,2),NA,IS1,IS2,CHAR,CLEAR
	LOGICAL*1 CLEAR(6)
	LOGICAL*1 CHAR,POS(4),A1,ALPHA,IB,ID,ISA(32,2)
	DIMENSION LOC(2),ID(10,10)
	ALPHA=' '
	POS(1)="33
	POS(2)="131
	POS(3)=54
	POS(4)="40
	J=0
	DO 3 I=1,NA
	IF(IA(I,1).EQ.0.OR.IA(I,2).EQ.0) J=1
3	CONTINUE
	IF(J.EQ.0) GOTO 8
	WRITE(5,4)
4	FORMAT(/////' *** WARNING: STARS NOT HIDDEN ***'/)
6	CALL CLOSE(5)
	RETURN
8	CHAR='a'
	WRITE(5,2) POS
2	FORMAT(X,4A1,/////' ***   SEARCH MODE   ***'//
     C' In this mode the objective is to find the stars already'/
     C' hidden.  The board will be displayed and you will be'/
     C' asked for a ray entry point.'//
     C' You will be given your current score after each ray is'/
     C' entered.  The results of each ray will be displayed at the'/
     C' board edge.'//
     C' You also have the opportunity to place star-markers on the'/
     C' board where you believe the stars are hidden.  When you exit'/
     C' the search mode these star-markers will be compared with the'/
     C' actual star locations to see if you have a matching pattern'/
     C' or one that appears the same to the rays.'//
     C' To exit the search mode and compare stars, enter E.  To redraw'/
     C' the screen without affecting the search, enter CNTRL-Z.'/
     C' To SAVE the current game for later use, enter S.  To place'/
     C' star-markers, enter #.')
	READ(5,5,END=6) ANS
5	FORMAT(A1)
	NSTP=-1  ! NUMBER OF STOPS
411	NSTP=NSTP+1
10	CALL BOARD
	I=0
	CALL DSTARS(NA,IC,I)
	DO 40 J=2,9
	I=J
	ALPHA=IB(1,I)
	IF(ALPHA.GT.32) CALL DBOARD(1,I,ALPHA)
	ALPHA=IB(10,I)
	IF(ALPHA.GT.32) CALL DBOARD(10,I,ALPHA)
	ALPHA=IB(I,1)
	IF(ALPHA.GT.32) CALL DBOARD(I,1,ALPHA)
	ALPHA=IB(I,10)
	IF(ALPHA.GT.32) CALL DBOARD(I,10,ALPHA)
40	CONTINUE
	ALPHA=32
	POS(3)="40
	POS(4)="40
	WRITE(5,11) POS,POS
11	FORMAT(X,4A1,20(30X/),X,4A1,
     C' * SEARCH MODE *'/' Enter R for rays, # to place'/
     C' star-markers, S to save game,'/' E to exit.  CNTRL-Z'/
     C' will redraw screen.',$)
15	CALL CLOSE(5)
	CALL GETNUM(A1,M)
17	IF(A1.EQ.'C') GOTO 10
	IF(A1.EQ.'E'.OR.A1.EQ.'e') GOTO 300
	IF(A1.EQ.'S'.OR.A1.EQ.'s') GOTO 50
	IF(A1.EQ.'R'.OR.A1.EQ.'r') GOTO 100
	IF(A1.EQ.'#') GOTO 200
	TYPE *,'Select R, E, S or #.'
	GOTO 15
50	I=1
	CALL USAVE(I)
	A1='E'
	IF(I.GE.0) A1='C'
	GOTO 17
100	POS(3)=38
	POS(4)="40
	WRITE(5,101) POS,POS
101	FORMAT(X,4A1,15(30X/),X,4A1,' * RAY ENTRY *')
102	POS(3)=41
	WRITE(5,103) POS,POS
103	FORMAT(X,4A1,5(30X/),X,4A1)
	IF(ALPHA.EQ.'H') WRITE(5,104) M
	IF(ALPHA.EQ.'R') WRITE(5,105) M
	IF(ALPHA.GE.'a'.AND.ALPHA.LE.'z') WRITE(5,106) M,ALPHA
	ALPHA=' '
	ISCOR=0
	DO 120 I=2,9
	IF(IB(I,1).GE.'A'.AND.IB(I,1).LE.'z') ISCOR=ISCOR+1
	IF(IB(I,10).GE.'A'.AND.IB(I,10).LE.'z') ISCOR=ISCOR+1
	IF(IB(1,I).GE.'A'.AND.IB(1,I).LE.'z') ISCOR=ISCOR+1
	IF(IB(10,I).GE.'A'.AND.IB(10,I).LE.'z') ISCOR=ISCOR+1
120	CONTINUE
	WRITE(5,107) ISCOR
104	FORMAT('+',I2,': HIT (ray absorbed)')
105	FORMAT('+',I2,': REFLECTION')
106	FORMAT('+',I2,': MISS/DEFLECTION (',A1,')')
107	FORMAT(' (current score is',I3,')'/,' Entry point: ',$)
	CALL GETNUM(A1,M)
	IF(M.EQ.0) GOTO 17
	N=1
	CALL MOVE(M,N,ALPHA,IB)
	GOTO 102
200	POS(3)=38
	POS(4)="40
	WRITE(5,201) POS,POS
201	FORMAT(X,4A1,15(30X/),X,4A1,'* STAR MARKERS *'/'  #   location')
	DO 202 I=1,NA
	POS(3)=41+I
	WRITE(5,203) POS,I,IC(I,1)-1,34-IC(I,2)
202	CONTINUE
203	FORMAT(X,4A1,I2,2I5)
205	POS(3)=50
	WRITE(5,204) POS,POS
204	FORMAT(X,4A1,4(30X/),X,4A1,' Star-marker number: ',$)
	CALL GETNUM(A1,M)
	IF(M.EQ.0) GOTO 17
	IF(M.GT.NA) GOTO 205
209	WRITE(5,207) POS,POS,M
207	FORMAT(X,4A1,4(30X/),X,4A1,' Location of #',I1,': ',$)
	READ(5,208,ERR=15,END=15) LOC
208	FORMAT(2I4)
	IX=0
	IY=0
	IR=0
	DO 210 I=1,2
	IF(LOC(I).LT.9.AND.LOC(I).GT.0) IX=LOC(I)
	IF(LOC(I).GT.16.AND.LOC(I).LT.25) IX=25-LOC(I)
	IF(LOC(I).GT.8.AND.LOC(I).LT.17) IY=LOC(I)-8+40
	IF(LOC(I).GT.24.AND.LOC(I).LT.33) IY=33-LOC(I)+40
210	CONTINUE
	IF(IX.EQ.0.OR.IY.EQ.0) IR=1
	IF(IR.EQ.1) GOTO 230
	IY=IY-40
	DO 211 I=1,NA
	IF(I.EQ.M) GOTO 211
	IF(IX+1.EQ.IC(I,1).AND.IY+1.EQ.IC(I,2)) GOTO 205
211	CONTINUE
230	POS(3)=M+41
	POS(4)="40
	WRITE(5,203) POS,M,IX,33-IY
	ALPHA='-'
	IX1=IC(M,1)
	IY1=IC(M,2)
	IF(IX1.NE.0) CALL DBOARD(IX1,IY1,ALPHA)
	IF(IR.EQ.1) GOTO 231
	ALPHA='#'
	CALL DBOARD(IX+1,IY+1,ALPHA)
	IC(M,1)=IX+1
	IC(M,2)=IY+1
	GOTO 205
231	IC(M,1)=0
	IC(M,2)=0
	GOTO 205
C 
C	EXIT AND SCORE
300	POS(3)="40
	POS(4)="40
	WRITE(5,301) POS,POS,ISCOR
301	FORMAT(X,4A1,22(30X/),X,4A1,'* SCORING *'/
     C' Current score:',I3)
	NMISS=NA
	DO 302 I=1,NA
	DO 302 J=1,NA
	IF(IA(I,1).EQ.IC(J,1).AND.IA(I,2).EQ.IC(J,2)) NMISS=NMISS-1
302	CONTINUE
	IF(NMISS.GT.0) GOTO 305
	WRITE(5,303) ISCOR
303	FORMAT(' Congratulations.  You'/' Have found all the'/
     C' stars, giving you a'/' total score of',I3)
	GOTO 399
C	*/# MISMATCH; CHECK IF PATTERN FEASIBLE:
305	POS(3)=35
	POS(4)="40
	JILL=1
350	DO 330 I=1,10
	DO 330 J=1,10
	ID(I,J)=' '
330	CONTINUE
	DO 331 I=1,NA
	IF(JILL.EQ.1) ID(IC(I,1),IC(I,2))='*'
	IF(JILL.EQ.2) ID(IA(I,1),IA(I,2))='*'
331	CONTINUE
	CHAR='a'
	DO 306 J=1,32
	I=J
	N=3
	CALL MOVE(I,N,ALPHA,ID)
	ISA(I,JILL)=ALPHA
306	CONTINUE
	IF(JILL.EQ.2) GOTO 351
	JILL=2
	GOTO 350
351	DO 352 I=1,32
	IF(ISA(I,1).NE.ISA(I,2)) GOTO 307
352	CONTINUE
	CALL DSTARS(NA,IA,JILL)
	WRITE(5,308) POS,ISCOR
308	FORMAT(X,4A1,' Your # pattern doesn''t match'/
     C' with the * pattern, but no'/' rays can detect the'/
     C' difference.  You have found an'/' alternative pattern for'/
     C' an ambiguous pattern.  The *'/' locations are indicated'/
     C' by ''( )''.'//' TOTAL SCORE:',I3)
	GOTO 399
307	SS="0
	IF(NMISS.NE.1) SS='s'
	WRITE(5,310) POS,NMISS,SS,NA
310	FORMAT(X,4A1,' You have missed',I2/' star',A1,' out of',I3/
     C' Do you wish to see the'/' correct * pattern now ?',$)
	READ(5,5,END=6) ANS
	IF(ANS.EQ.'Y'.OR.ANS.EQ.'y') CALL DSTARS(NA,IA,JILL)
410	WRITE(5,315) ISCOR+NSTP*5+NMISS*5, ISCOR,NMISS
315	FORMAT(//' TOTAL SCORE:',I3/' [',I2,' + (',I2,' x 5)]')
	IF(NSTP.GT.0) WRITE(5,397) NSTP*5,NSTP
397	FORMAT(' PLUS',I3,' PENALTY POINTS,'/
     C' FOR SCORING',I2,' EXTRA TIMES.')
	IF(ANS.EQ.'N'.OR.ANS.EQ.'n') GOTO 411  ! CONTINUE GAME
399	DO 398 I=1,10
	DO 398 J=1,10
	IB(I,J)=' '
398	CONTINUE
	DO 401 I=1,8
	IC(I,1)=0
	IC(I,2)=0
401	CONTINUE
	READ(5,5,END=6) ANS
	GOTO 6   !  RETURN
	END
