10 REM >Sentenc 20 REM by Steven Flintham 30 REM 40 REM Friday 15th April 1994 50 REM Saturday 16th April 1994 60 REM 70 REM This is a completely new version and is based entirely on 80 REM 'phrase substitution' 90 : 100 MODE 7:width%=39 110 PROCinit 120 REPEAT 130 PROCgenerate_sentence 140 UNTIL FALSE 150 END 160 : 170 DEF PROCinit 180 LOCAL read%,clear% 190 DIM template$(100),component$(800,3),variable%(26),match%(5):REM CHANGED FROM 2000 TO 800 BY CJR 200 FOR clear%=1 TO 26:variable%(clear%)=0:NEXT 210 PRINT "Please wait, reading templates..." 220 RESTORE 1410:num_templates%=0 230 REPEAT 240 num_templates%=num_templates%+1 250 READ template$(num_templates%) 260 UNTIL template$(num_templates%)="ZZZ" 270 num_templates%=num_templates%-1 280 PRINT "Please wait, reading components..." 290 RESTORE 1460:num_components%=0 300 REPEAT 310 num_components%=num_components%+1 320 FOR read%=1 TO 3 330 READ component$(num_components%,read%) 340 NEXT 350 UNTIL component$(num_components%,1)="ZZZ" 360 num_components%=num_components%-1 370 PRINT "Please wait, sorting components..." 380 PROCsort_components 390 CLS 400 ENDPROC 410 : 420 DEF PROCsort_components 430 LOCAL outer%,inner%,first$,second$ 440 IF num_components%=1 THEN ENDPROC 450 FOR outer%=1 TO num_components%-1 460 FOR inner%=outer%+1 TO num_components% 470 IF component$(outer%,1)>component$(inner%,1) THEN PROCswap(outer%,inner%) 480 NEXT 490 NEXT 500 ENDPROC 510 : 520 DEF PROCswap(outer%,inner%) 530 LOCAL temp$,sub% 540 FOR sub%=1 TO 3 550 temp$=component$(outer%,sub%):component$(outer%,sub%)=component$(inner%,sub%):component$(inner%,sub%)=temp$ 560 NEXT 570 ENDPROC 580 : 590 DEF FNS="Sentenc" 600 : 610 DEF PROCgenerate_sentence 620 LOCAL sentence$ 630 IF num_templates%=1 THEN sentence$=FNsubstitute(template$(1)) ELSE sentence$=FNsubstitute(template$(RND(num_templates%))) 640 PROCpretty_print(sentence$) 650 ENDPROC 660 : 670 DEF FNsubstitute(line$) 680 LOCAL left$,right$,mid$ 690 IF INSTR(line$,"<")=0 THEN =line$ 700 left$=LEFT$(line$,INSTR(line$,"<")-1) 710 right$=MID$(line$,INSTR(line$,">")+1) 720 mid$=MID$(line$,INSTR(line$,"<")+1,INSTR(line$,">")-INSTR(line$,"<")-1) 730 line$=left$+FNhandle_subst_comp(mid$)+right$ 740 =FNsubstitute(line$) 750 : 760 DEF FNhandle_subst_comp(subst$) 770 LOCAL match%,return$,var_num% 780 match%=FNfind_subst(subst$) 790 IF match%=0 THEN PRINT "Substitution component '";subst$;"' not recognised.":END 800 IF component$(match%,2)="" THEN return$=FNget_at_random(component$(match%,3)) 810 IF LEN(component$(match%,2))>=3 THEN var_num%=ASC(LEFT$(component$(match%,2),1))-64:variable%(var_num%)=VAL(MID$(component$(match%,2),3)):return$=FNget_at_random(component$(match%,3)) 820 IF LEN(component$(match%,2))=1 THEN var_num%=ASC(component$(match%,2))-64:return$=FNget_item(component$(match%,3),variable%(var_num%)) 830 =return$ 840 : 850 DEF FNfind_subst(subst$) 860 LOCAL lower%,upper%,pos%,match%,clear%,match_num% 870 lower%=1 880 upper%=num_components% 890 match%=FALSE 900 REPEAT 910 pos%=(upper%-lower%)/2+lower% 920 IF component$(pos%,1)=subst$ THEN upper%=pos%:lower%=pos%:match%=TRUE 930 IF component$(pos%,1)>subst$ THEN upper%=pos% 940 IF component$(pos%,1)subst$:pos%=pos%+1 990 FOR clear%=1 TO 5:match%(clear%)=0:NEXT:match_num%=0 1000 REPEAT 1010 IF component$(pos%,1)=subst$ THEN match_num%=match_num%+1:match%(match_num%)=pos% 1020 pos%=pos%+1 1030 UNTIL pos%>num_components% OR component$(pos%,1)<>subst$ 1040 IF match_num%=0 THEN =0 1050 IF match_num%=1 THEN =match%(1) 1060 =match%(RND(match_num%)) 1070 : 1080 DEF FNget_at_random(list$) 1090 LOCAL num_in_list% 1100 num_in_list%=FNnum_in_list(list$) 1110 IF num_in_list%=1 THEN =FNget_item(list$,1) ELSE =FNget_item(list$,RND(num_in_list%)) 1120 : 1130 DEF FNnum_in_list(list$) 1140 LOCAL count%,offset% 1150 IF INSTR(list$,"~")=0 THEN =1 1160 count%=0:offset%=1 1170 REPEAT 1180 count%=count%+1 1190 offset%=INSTR(list$,"~",offset%)+1 1200 UNTIL offset%=1 1210 =count% 1220 : 1230 DEF FNget_item(list$,pos%) 1240 LOCAL skip% 1250 IF INSTR(list$,"~")=0 THEN =list$ 1260 IF pos%=1 THEN =LEFT$(list$,INSTR(list$,"~")-1) 1270 FOR skip%=1 TO pos%-1 1280 list$=MID$(list$,INSTR(list$,"~")+1) 1290 NEXT 1300 IF INSTR(list$,"~")=0 THEN =list$ 1310 =LEFT$(list$,INSTR(list$,"~")-1) 1320 : 1330 DEF PROCpretty_print(T$) 1340 LOCAL A% 1350 REPEAT 1360 IF LEN(T$) ." 1420 DATA "If there was one thing , it was ." 1430 DATA ZZZ 1440 : 1450 REM Components 1460 DATA "Person",,"~" 1470 DATA "Man","S=1","He~Steven~Fred~Chris~Michael" 1480 DATA "Woman","S=2","She~Helen~Lindsey~Caroline" 1490 DATA "person",,"~" 1500 DATA "man","S=1","he~Steven~Fred~Chris~Michael" 1510 DATA "woman","S=2","she~Helen~Lindsey~Caroline" 1520 DATA "his/her","S","his~her" 1530 DATA "he/she","S","he~she" 1540 : 1550 DATA "enjoyed",,"enjoyed~liked~loved" 1560 DATA "did not like",,"did not like~hated~could not stand" 1570 : 1580 DATA "enjoyable thing",,"reading the latest edition of 8BS~going to work~writing <(brilliant )>programs to send in to 8BS~the mindless tedium of backing up collection of discs" 1590 DATA "enjoyable thing",,"programming computer~sleeping late at weekends~laughing at people who said that 8-bit BBC was outdated" 1600 DATA "unpleasant thing",,"backing up discs~talking to people who owned Amigas~power failures just as the latest version of program was being saved" 1610 : 1620 DATA "(brilliant )",,"~brilliant ~great ~novel " 1630 : 1640 DATA ZZZ,ZZZ,ZZZ