'=========================================================================== ' Subject: ANIMAL GAME Date: 7/07/93 (03:00) ' Author: Jim Little Code: QB, QBasic, PDS ' Keys: ANIMAL,GAME Packet: GAMES.ABC '=========================================================================== 'ANIMAL.BAS 'by Jim Little 'This code is not copyrighted. However, if you use this code without major ' modifications, please give me credit. 'This code implements an old "Intelligence Imitating" algorithm I first ' saw on the Apple II. Undoubtably, the routine goes back farther than ' that. I've never seen it on the IBM, though, and thought it may be of ' interest. 'This was thrown together at 3:00 AM.. please excuse the poor design. 'What does it do? Run it and find out! DECLARE SUB Intro () DECLARE SUB Main () DECLARE SUB GetChoice (choice%) DECLARE SUB InitializeData () TYPE animal yes AS INTEGER no AS INTEGER animal AS STRING * 80 END TYPE CONST cAssign = 1 CONST cRetrieve = 2 CONST False = 0 CONST True = NOT False Intro DO: K$ = INKEY$: LOOP UNTIL LEN(K$) DO UNTIL K$ = CHR$(27) VIEW PRINT 5 TO 25 Main VIEW PRINT 1 TO 25 Intro DO: K$ = INKEY$: LOOP UNTIL LEN(K$) LOOP DEFSNG A-Z SUB GetChoice (choice%) 'gets a y/n response from the user and returns it as -1 (for y) or 0 (for n) LOCATE , , 1 DO K$ = INKEY$ LOOP WHILE UCASE$(K$) <> "Y" AND UCASE$(K$) <> "N" choice% = (UCASE$(K$) = "Y") PRINT K$; LOCATE , , 0 END SUB SUB InitializeData 'initializes file #1 to include one question and two animals. DIM animal AS animal 'the question/animals animal.animal = "Does your animal swim a lot?" animal.yes = 2 animal.no = 3 PUT #1, 1, animal animal.animal = "goldfish" animal.yes = -1 animal.no = -1 PUT #1, 2, animal animal.animal = "cat" animal.yes = -1 animal.no = -1 PUT #1, 3, animal END SUB SUB Intro CLS PRINT TAB(37); "Animal" PRINT TAB(34); "by Jim Little" PRINT PRINT PRINT "Think of an animal, and I will attempt to guess it. As you play, I will" PRINT "learn more animals. Eventually, I will know every common animal." PRINT PRINT "Press any key when you've thought of an animal, or ESC to quit." END SUB SUB Main 'This is the main program driver. DIM animalnum& 'animal/question being checked/asked DIM animal AS animal DIM usersanimal$ 'the user's animal/question DIM companimal$ 'the computer's animal/question DIM newanimal AS animal 'new animal being added to data DIM choice% 'yes or no response from user (yes is -1, no is 0) DIM records& 'number of records in ANIMAL.DAT OPEN "ANIMAL.DAT" FOR RANDOM AS #1 LEN = LEN(animal) IF LOF(1) = 0 THEN InitializeData END IF CLS animalnum& = 1 GET #1, animalnum&, animal companimal$ = RTRIM$(animal.animal$) DO IF animal.yes <> -1 THEN 'question, not animal PRINT companimal$; " "; GetChoice choice% PRINT : PRINT IF choice% THEN 'choice = 'YES' animalnum& = animal.yes ELSE 'choice = 'NO' animalnum& = animal.no END IF END IF GET #1, animalnum&, animal companimal$ = RTRIM$(animal.animal$) LOOP UNTIL animal.yes = -1 PRINT "Is your animal a "; companimal$; "? "; GetChoice choice% PRINT : PRINT IF choice% THEN PRINT "Wow, I'm smart!" PRINT "(Press a key)" DO: LOOP UNTIL LEN(INKEY$) ELSE LINE INPUT "What was your animal? ", useranimal$ PRINT PRINT "Please type a yes/no question that differentiates a" PRINT useranimal$; " from a "; companimal$; ": "; LINE INPUT "", newanimal.animal PRINT PRINT "If your animal was a "; useranimal$; ", how would you answer" PRINT "the above question? "; GetChoice choice% records& = LOF(1) \ LEN(animal) newanimal.yes = records& + 1 newanimal.no = records& + 2 PUT #1, animalnum&, newanimal newanimal.animal = useranimal$ newanimal.yes = -1 newanimal.no = -1 IF choice% THEN PUT #1, records& + 1, newanimal PUT #1, records& + 2, animal ELSE PUT #1, records& + 1, animal PUT #1, records& + 2, newanimal END IF END IF CLOSE #1 END SUB '-----------------8<----[ Begin ANIMAL.DAT ]---->8------------------ 'This is a sample data file for ANIMAL.BAS. It isn't required, 'but you may enjoy the program more (at first, at least) if 'you unzip it into the directory containing ANIMAL.BAS. Simply 'execute in a QB-related environment to get ANIMAL.ZIP, then 'unzip with PKUNZIP v2.04 or greater to get ANIMAL.DAT. CLS : PRINT STRING$(50, 178): DEFINT A-Z'Created by PostIt! 6.1 FOR A = 0 TO 6: P(A) = 2 ^ A: NEXT: OPEN "B", 1, "ANIMAL.ZIP" T$ = "abcdefghijklmnopqrstuvwxyz": T$ = T$ + UCASE$(T$) + "0123456789#$" G "qT0aeqb)icaCANXRrE1TM#My)WUl(Gc*b5usnfetUququ1Sw3Fj12aHNx69EVoH" G "uifinsVFbscqkKqi96y7X2kRSKpz5Bzj9Ep5p5elVl84wVoC238dz#byFlpM9tt" G "5BksNgC6W#SCfoZw7qYOkinwnvv8S4OLlbU0U6uR2GrLb95mUMXtoVkEa$gNbCM" G "D1ze5MSnW5NceSpvYMuP3nd9wKjFdI9EnJhMtWdRsuMmC$wBYP437SGZg2lz2Ko" G "t1Z2gOSrGBboWMp5egPCjOnflD8y0#5aNBhCwXNWdLmgl75bNFxFuo143ToYKXn" G "FvcgPP4jyL3Pk5Qt9pXfaxyp6uZzBH$$Rs#NgXRYyhkNucR31hLBRRySK9JdNxe" G "CXRm30KHPoBb6D8wXeUj5oGD2tUzTjHDzoBZFpqDgSNfwZeEgkMCvWv3fNHSYuv" G "v#iZMUt4U#V5LMsE2nmLFzWL3t85uokItWuEWU$NdwdswwNRxtXBdYURaUYoCDv" G "EYfo674G00QDmCDh87v5KBckNCtWn3J9mvzgz##oGBTBUzdWt4abQJhA8EqUg4A" G "xwNrQSaNIpNmn6ViK7pmfFdWn2ZzNqVR2mg3$1bx$QI5NWHQCrkpJj2HYJg87PA" G "MqbL7hEGEY31QbtYDs4K1CzJdXJcj3nCpl735J6vM4rYXhKuiRB8zbv08HrR07f" G "UVEILyvwUFuvpFi4H7QZKa$zIDQjeqft#48b1sYtbpDVX8PKjEg6j1andTXN2JI" G "sk3gC7DX5uMWyT1NpUi0aoZRlidkN8eWtUCS00CLFGmrDX5uRRafu2h8cDTNXKZ" G "nRLBM1Ji0$TH3z5ZEHk2zRITLdAyJLo7LSjRwjNx6XGhVB#UFwzB5OqF9JaQ7c2" G "DxD6SjSz8etpiSNL1PXg7RDMXtm9iWJ21V7S0aB7Q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2jxa63" G "bFFN3Za5ztaDhjNmtQYuBOmzdXK2##6QDI#EW#j4N78EfZBC7UJ$2Ti1GJWA97t" G "f963N3dM1k#8M51ffnUH2x9Py9ZBJe8wTxKVRzBSTYtfYCzSZTN6KW4LOqY87IS" G "uUf$E8CtN14TvuTtUZ#E2T3YjbEnViN$53vo3Ooumzb$j6RDEPgsA#CX6YCbJq$" G "xaqTuacqbau*G(N2z8AKxDRPVjg)S7c(O/ab(i/eKtj1uqm5crbrfulvGb+e(b(" G "o*oz," N = 1692: K = 255: IF LEN(C$) <> 2256 THEN PRINT "Bad script!": END FOR A = 1 TO N: LOCATE 1: PRINT STRING$(50 / N * A, 177): IF L = 0 THEN GOSUB G: L = 6 W = T \ P(6 - L): GOSUB G: W = W OR T * P(L): L = L - 2: B$ = CHR$(W AND K): PUT 1, , B$: NEXT PRINT : IF C = 74 THEN PRINT "Ok": END ELSE PRINT "Bad checksum!": END G: I = I + 1: T = INSTR(T$, MID$(C$, I, 1)) - 1: C = (C + T) * 2: C = C \ 256 + (C AND 255): RETURN SUB G (A$) : SHARED C$: FOR Q = 2 TO 9: DO: S = INSTR(A$, CHR$(Q + 38)) IF S THEN A$ = LEFT$(A$, S - 1) + STRING$(Q, 97) + MID$(A$, S + 1) LOOP WHILE S: NEXT: C$ = C$ + A$: END SUB '-----------------8<----[ Begin ANIMAL.DAT ]---->8------------------