A Conversation for BASIC - the Programming Language

BASIC Artificial Intelligence project

Post 1

soushanstarra

My friend and I have gound a program where you can teach the computer things, and the first try went very well.smiley - ok But we don't know how to tell the computer to save what we've taught it.smiley - erm So when we end the program, it loses all it's knowledge. As soon as I can get hold of a copy of the program I will post it. Please help. Soushanstarrasmiley - magic


BASIC Artificial Intelligence project

Post 2

xyroth

If you have the code, then you can fix this.

The program works by loading the data into arrays, with some structure to the combination of arrays.

what you need is an extension to the program so that it can save the structured data in such a way as to be able to reload it next time.

you can do this either by saving the contents of all the arrays, or by saving the data in a structured format, which is more likely to preserve the meaning.

As you are talking about basic, you will probably find you run into memory limits fairly quickly (unless you are using the "brandy" inerpreter).

Be carefull about posting the code, as it is likely to be copyright someone or other, and thus probably won't be visible here for long.


BASIC Artificial Intelligence project

Post 3

soushanstarra

Thanks ever so much. We are using Border Basic 3 but the program was designed for a BBC microcomputer. Here is the program. The hash stands for the "not equals" sign.
10 REM ANIMALS
50 DIM Q$(100),Y(100), N(100),A$(100)
60 CLS:PRINT:PRINT "DO YOU HAVE A FILE TO USE?";
70 GOSUB 520:IF G$="Y" THEN GOTO 100
80 LET NQ=1:LET Q$=(1)="IS IT DOMESTIC":LET Y(1)=101:LET N(1)=102
90 LET NA=2:LET A$(1)="A CAT":LET A$(2)="A LION":GOTO 180
100 PRINT:PRINT "LOADING FILE"
120 PRINT "PUT TAPE IN AND PRESS PLAY"
130 LET F=OPENIN(F$) INPUT #F,Q$(K)
140 FOR K=1 TO NQ:INPUT #F,N
150 FOR K=1 TO NA
160 INPUT #F,A$
170 NEXT K:CLOSE F
180 CLS
190 LET Q=1
200 PRINT:PRINT Q$(Q):PRINT " ? "
210 GOSUB 520
220 IF G$="Y" THEN LET N=Y(Q)
230 IF G$="N" THEN LET N=N(Q)
240 IF N96 THEN LET G=G-32
540 IF G<>78 AND G<>89 THEN GOTO 520
550 LET G$=CHR$ (G) :PRINT G$;
560 LET J$=INKEY$(0):IF J$="" THEN GOTO 560
570 LET J=ASC(J$):IF J<>13 AND J<>127 THEN GOTO 560
580 IF J=13 THEN PRINT:RETURN
590 PRINT CHR$(8);" ";CHR$(8);:GOTO 520

Well that's it. I is all perfectly allright if you're saving onto videotape. But we are saving onto out computers. And just incase it changes things a but, we both use network computers, so we save everything to our P (Pretty Private Place to Put stuff) drives. We think it might be something to do with OPENIN & OPENOUT. thanks smiley - magic


BASIC Artificial Intelligence project

Post 4

xyroth

you have identified the right region for the problem, but the wrong cause.

I still use bbc basic for prototyping new tools, so I am very familiar with it.

basically the program is incredibly simple.

what it does is has an array of questions Q$(max), an array of answers A$(max) and two arrays of pointers Y(max) and N(max).

to start with it sticks a question in Q$(1), two answers in A$(1) and A$(2), and loads the pointer arrays with the index to the individual answers plus the maximum count, and uses a simple test to split the pointers into questions and answers.

so Y(1)=1 (the answer) plus the maximal count (100), and N(1) points to 2 + 100.

This is the simplest varient of the animals game, and so there is no real problem of copyright.

the load and save routines have got a problem that they don't reflect this structure.

in particular:

480 FOR K=1 TO NQ:PRINT #F, Q$(K):PRINT #F,N(K):NEXT K

should be:

480 FOR K=1 TO NQ:PRINT #F, Q$(K):PRINT #F,N(K):PRINT#F,Y(K):NEXT K

thereby saving all of the data structure, giving you:

470 LET F=OPENOUT(F$):PRINT #F,NQ:PRINT #F,NA
480 FOR K=1 TO NQ:PRINT #F, Q$(K):PRINT #F,N(K):PRINT#F,Y(K):NEXT K
490 FOR K=1 TO NA:PRINT #F,A$(K):NEXT K

the load routine has an even bigger problem, as it uses a completely different data structure, and then doesn't bother to store anywhere the values it has input.

so the input routine needs to load nq,na, followed by q$(k),n(k),y(k) where k=1 to nq and then you need to load a$(k) where k =1 to na.

that should basically solve the problem.

also, due to the small array sizes you are using, it will run out of room fairly quickly.

However the algorithm has a number of fundamental weaknesses due to being based upon a tree structure.

in particular, you have to present it with the right animals in the right order, and ask the right questions for the tree structure to have the right shape.

Also, if there are multiple pathways to the same animal, you end up having the knowledge dispersed throughout the tree, and often duplicated.

this can result in the program having the information to solve the problem, but not in a form which it can use.

there are ways around this problem, but they need a much more flexible data structure, and usually require dynamically loaded data structures, which makes the program a lot bigger and more complex, so you don't often see it done in basic.

I hope this helps.


BASIC Artificial Intelligence project

Post 5

soushanstarra

Thank's so much. I'll give this to my friend, she is better at basic than me. I'll tell you if it helps ASAP.


BASIC Artificial Intelligence project

Post 6

soushanstarra

do you know vba

We are trying to make the program work in excel on the visual basic editor.

hope you can help (if we ever need it!!)

smiley - magic


BASIC Artificial Intelligence project

Post 7

xyroth

Sorry, I don't use microsoft languages since an unfortunate encounter with microsoft C. As a group, they have the problem that while they all include the standard stuff, microsoft prefers you to use their proprietary varients to encourage lock-in.

this maks moving programs to a non microsoft varient a real pain.

I tend to use "brandy", which is a version of bbc basic which works in windows and in linux, and being bbc basic is also very structured.

this structure, combined with being cross-platform makes it more suited to tasks where you don't need a gui.

I also don't have excel, so I wouldn't be able to help with that in any case.


Key: Complain about this post

Write an Entry

"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."

Write an entry
Read more