diff --git a/dec/ANIMAL.BAS b/dec/ANIMAL.BAS new file mode 100644 index 0000000..86b7e85 --- /dev/null +++ b/dec/ANIMAL.BAS @@ -0,0 +1,68 @@ +100 &"PLAY 'GUESS THE ANIMAL' WITH RSTS +150 &"THINK OF AN ANIMAL AND THE COMPUTER WILL TRY TO GUESS IT...":& +500 DIM A$(200) +525 F$="ANIMAL.GME" + :ON ERROR GOTO 700 +550 OPEN F$ FOR INPUT AS FILE 1% + :INPUT #1%,N% + :INPUT #1,A$(I%) FOR I%=1%TO N% + :CLOSE 1% + :A$(0%)=NUM$(N%) + :ON ERROR GOTO 0 + :GOTO 1300 +700 ON ERROR GOTO 1050 + :F$="$"+F$ + :RESUME 550 +1050 READ A$(I%) FOR I%=0% TO 3% +1100 DATA "4","\QDOES IT SWIM\Y2\N3","\AFISH","ABIRD" +1300 INPUT "ARE YOU THINKING OF AN ANIMAL";Z9$ + :GOTO 1350 IF LEFT(Z9$,1%)="Y" + :GOTO 1300 IF LEFT(Z9$,1%)="N" +1310 IF Z9$="SAVE" THEN + OPEN "ANIMAL.GME" FOR OUTPUT AS FILE 1% + :PRINT #1%,A$(I%) FOR I%=0% TO VAL(A$(0%)) + :PRINT #1,CHR$(26%) + :CLOSE 1% + :GOTO 1300 +1320 IF Z9$="LIST" THEN + PRINT "ANIMALS I ALREAD KNOW ARE:" + :PRINT RIGHT(A$(I%),3%), IF INSTR(1%,A$(I%),"\A") FOR I%=1% TO 200% + :PRINT + :GOTO 1300 +1350 K%=1% +1400 K%=FNA%(A$(K%)) + :GOTO 3000 IF LEN(A$(K%))=0% + :GOTO 1400 IF LEFT(A$(K%),2%)="\Q" + :PRINT "IS IT A "RIGHT(A$(K%),3%); + :INPUT Z7$ + :Z7$=LEFT(Z7$,1%) +1450 IF Z7$="Y" THEN + PRINT "WHY NOT TRY ANOTHER ANIMAL" + :GOTO 1300 +2000 INPUT THE ANIMAL YOU WERE THINKING OF WAS A";Z9$ +2050 PRINT "PLEASE TYPE IN A QUESTION THAT WOULD DISTINGUISH A " + Z9$ " FROM A "RIGHT(A$(K%),3%) + :INPUT Z8$ +2100 PRINT "FOR A "Z9$" THE ANSWER WOULD BE"; + :INPUT Z7$ + :Z7$=LEFT(Z7$,1%) + :IF Z7$="Y" THEN Z6$="N" + ELSE IF Z7$="N" THEN Z6$="Y" + ELSE PRINT "PLEASE ANSWER 'YES' OR 'NO'" + : GOTO 2100 +2200 Z1%=VAL(A$(0%)) + :A$(0%)=NUM$(Z1%+2%) + :A$(Z1%)=A$(K%) + :A$(Z1%+1%)='\A'+Z9$ + :A$(K%)="\Q"+Z8$+"\"+Z7$+NUM$(Z1%+1%)+"\"+Z6$+NUM$(Z1%)+"\" +2300 GOTO 1300 +3000 DEF FNA%(Q$) + :PRINT MID(Q$,3%,INSTR(3%,Q$,"\")-3%); + :INPUT Z9$ + :Z9$=LEFT(Z9$,1%) + :Z9$="N" IF Z9$<>"Y" + :Z1%=INSTR(3%,Q$,"\"+Z9$)+2% + :Z2%=INSTR(Z1%,Q$,"\") + :FNA$=VAL(MID(Q$,Z1%,Z2%-Z1%)) + :FNEND +9999 END diff --git a/dec/HEX.BAS b/dec/HEX.BAS new file mode 100644 index 0000000..9b52862 --- /dev/null +++ b/dec/HEX.BAS @@ -0,0 +1,80 @@ +1 ! BY JEFF DALTON, CLASS OF '74, NORTHFIELD MOUNT HERMON SCHOOL +2 ! THIS PROGRAM PLAYS THE GAME 'HEXAPAWN' BY A METHOD OUTLINED IN + 'MATHEMATICAL GAMES' IN MARCH 1962 SCIENTIFIC AMERICAN. +3 ! THE PROGRAM LEARNS BY ELIMINATION OF BAD MOVES. ALL POSITIONS + ENCOUNTERED BY THE PROGRAM AND THE ACCEPTABLE MOVES FROM THEM + ARE STORED IN P$(I%) +4 ! WHEN THE PROGRAM ENCOUNTERS AN UNFAMILIAR POSITION, THE POSITION + AND ALL LEGAL MOVES FROM IT ARE ADDED TO THE LIST. +5 ! IF THE PROGRAM LOSES A GAME, IT ERASES THE MOVE THAT LED TO DEFEAT. + IF IT HITS A POSITION FROM WHICH ALL MOVES HAVE BEEN DELETED + ( THEY ALL LED TO DEFEAT ), IT ERASES THE MOVE THAT GOT + IT HERE AND RESIGNS. +10 INPUT "INSTRUCTIONS"; C$: IF LEFT(C$,1%)<>"Y" THEN 110 +20 &: &,"THIS PROGRAM PLAYS THE GAME OF HEXAPAWN.":& +"HEXAPAWN IS PLAYED WITH CHESS PAWNS ON A 3 BY 3 BOARD. THE PAWNS ARE":& +"MOVED AS IN CHESS - ONE SPACE FORWARD TO AN EMPTY SPACE OR ONE SPACE" +30 &"FORWARD AND DIAGONALLY TO CAPTURE AN OPPOSING MAN.":&:&CHR$(9%); +"O THE BOARD, YOUR PAWNS ARE 'O', THE COMPUTER'S PAWNS ARE '*'":& +"AND EMPTY SQUARES ARE '-'. TO ENTER A MOVE, TYPE THE NUMBER OF THE" +40 &"SQUARE YOU WILL MOVE FROM FOLLOWED BY THE NUMBER OF THE SQUARE":& +"YOU WILL MOVE TO. (THE NUMBERS ARE SEPARATED BY A COMMA.)":& +50 &" THE PROGRAM STARTS A SERIS OF GAMES KNOWING ONLY WHEN THE":& +"GAME IS WON (A DRAW IS IMPOSSIBLE) AND HOW TO MOVE. IT HAS NO":& +"STRATEGY AT FIRST AND JUST MOVES RANDOMLY. HOWEVER, IT LEARNS" +60 &"FROM EACH GAME. THUS, DEFEATING IT BECOMES MORE AND MORE":& +"DIFFICULT. ALSO, TO HELP OFFSET YOUR INITIAL ADVANTAGE, YOU WILL":& +"NOT BE TOLD HOW TO WIN THE GAME BUT MUST LEARN THIS BY PLAYING":& +100 DEF FNC$(X$,X%,Y$)=LEFT(X$,X%-1%)+Y$+RIGHT(X$,X%+LEN(Y$)) +105 DEF FNN$(X%): X$=NUM$(X%): FNN$=MID(X$,2%,LEN(X$)-2%): FNEND +110 DIM P$(50%): RANDOMIZE: Q%=0%: + PRINT "SINCE I'M A GOOD SPORT, YOU'LL ALWAYS GO FIRST +120 P%=0%: P$="***---OOO": &: &"NUMBERING:": + &"123": &"456": &"789": & +190 D%=-1%: Q$="O": GOSUB 2000: IF M$="" THEN + PRINT "YOU CAN'T MOVE. I WIN.": GOTO 510 +200 &: &"BOARD:": &LEFT(P$,3%): &MID(P$,4%,3%): &RIGHT(P$,7%): & +210 INPUT "WHAT IS YOUR MOVE"; A%,B%: + IF INSTR(1%,M$,FNN$(A%)+FNN$(B%))=0% THEN + PRINT "ILLEGAL MOVE.": GOTO 210 +230 P$=FNC$(FNC$(P$,A%,"-"),B%,"O"): + IF INSTR(1%,P$,"*")=0% OR INSTR(1%,P$,"O")<4% THEN + PRINT "YOU WIN.": GOTO 500 +300 P%=P%+2% ! COMPUTER'S MOVE +310 FOR C%=1% TO Q%: C$=P$(C%): IF VAL(LEFT(C$,1%))=P% AND + MID(C$,2%,9%)=P$ THEN M$=RIGHT(C$,11%) GOTO 400 +320 NEXT C%: Q$="*": D%=1%: GOSUB 2000: C%=Q%: + IF M$="" THEN PRINT "I CAN'T MOVE, YOU WIN.": GOTO 500 +400 IF M$="" THEN PRINT "I RESIGN.": GOTO 500 +410 K$=LEFT(M$,2%): M$=RIGHT(M$,3%): + IF RND>.33333333 AND M$<>"" THEN 410 +420 K%=C%: A%=VAL(LEFT(K$,1%)): B%=VAL(RIGHT(K$,2%)): + P$=FNC$(FNC$(P$,A%,"-"),B%,"*") +430 IF INSTR(1%,P$,"O")=0% OR INSTR(7%,P$,"*") THEN + PRINT "I WIN!": GOTO 510 +440 PRINT "I MOVE FROM" A% "TO" B%: GOTO 190 +500 W2%=W2%+1%: I%=INSTR(11%,P$(K%),K$): + P$(K%)=LEFT(P$(K%),I%-1%)+RIGHT(P$(K%),I%+2%) IF I%: GOTO 520 +510 W1%=W1%+1% +520 &: &"BOARD:": &LEFT(P$,3%): &MID(P$,4%,3%): &RIGHT(P$,7%): &: + & "I HAVE WON" W1% "AND YOU HAVE WON" W2% "OF" W1%+W2% "GAMES" +530 INPUT "ANOTHER GAME"; C$: IF C$="NO" THEN 9999 ELSE 120 +900 ! DATA**= <- OF MOVE IN GAME> + IN , -=BLANK, *=COMPUTER'S PAWN, O=PLAYERS'S PAWN + IS <- MOVE FROM><- MOVE TO> +2000 M$="" +2010 FOR J%=1% TO 9%: IF MID(P$,J%,1%)<>Q$ THEN 2050 +2015 T%=J%+D%*3%: IF T%<1% OR T%>9% THEN 2025 +2020 IF MID(P$,T%,1%)="-" THEN + M$=M$+FNN$(J%)+FNN$(T%) +2025 T%=J%+D%*2%: IF T%<1% OR T%>9% OR + (D%=1% AND (J%=1% OR J%=4% OR J%=7%)) OR + (D%=-1% AND (J%=3% OR J%=6% OR J%=9%)) THEN 2035 +2030 IF INSTR(1%,Q$+"-",MID(P$,T%,1%))=0% THEN + M$=M$+FNN$(J%)+FNN$(T%) +2035 T%=J%+D%*4%: IF T%<1% OR T%>9% OR J%=3% OR J%=7% THEN 2050 +2040 IF INSTR(1%,Q$+"-", MID(P$,T%,1%))=0% THEN + M$=M$+FNN$(J%)+FNN$(T%) +2050 NEXT J%: IF D%=1% AND M$<>"" THEN Q%=Q%+1%: P$(Q%)=FNN$(P%)+P$+M$ +2060 RETURN +9999 END