Qbasicnews.com

Full Version: Challenge: Creating AI that can "learn" through pr
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
years ago, I saw a documentary, on Sentient AI. Personally I believe its impossible to create sentiency on a computer, no matter how powerful. Since computers, by their very nature are little more than glorified "pachinko machines", though most say thats a stupid analogy.

Anyway, I started toying with the idea, of creating a program, that would learn and develop after reacting to certain stimuli.
In my example, getting the + makes him more likely to go after it, until thats all the charatcers does, and getting touched by X teaches him to avoid X
Its not real learning, but the illusion is fun.

Can you come up with a program that gives the genuine impression of learning? Im expecting anyone who does, to do better than my attempt, since Im no mathmatician or master at programming.

heck, maybe someone could even turn these into a kind of "sandbox" game, where by altering something, the "avatar" will react differently. I mean, what if you controlled X in my example, you could almost lead him around. Or perhaps youd both be after the "+"?

rules:
1) no libs, pure QB only
2) Aesthtics unimportant
3) no connecting to other programs etc.
4) no prescripted long movements, or demos, the AI must think on its own, based on surrounding stimulus and variables.

Code:
'LEARNING AI
'This is a program to simulate learning and intelligence
'the smiley face needs to eat the "+"
'The X hunts the smiley face
'eating more food teaches him to go after food but makes him complacent about X
'getting attacked teaches him to avoid X but he frogets to eat
'feel free to tweak the AI and variables, or use this in making your own learning AI


RANDOMIZE TIMER
SCREEN 13
COLOR 7
INPUT "SUB LOOP WAIT = ", SP%
CLS
PRINT
PRINT
PRINT "         ÛÛÛÛÛÛÛÛÛÛÛÛ"
PRINT "         Û          Ã›"
PRINT "         Û          Ã›"
PRINT "         Û          Ã›"
PRINT "         Û          Ã›"
PRINT "         Û          Ã›"
PRINT "         Û          Ã›"
PRINT "         Û          Ã›"
PRINT "         Û          Ã›"
PRINT "         Û          Ã›"
PRINT "         Û          Ã›"
PRINT "         ÛÛÛÛÛÛÛÛÛÛÛÛ"

A = INT(RND * 10) + 4    'CHARACTER
B = INT(RND * 10) + 11
GA = INT(RND * 10) + 4   'GOOD
GB = INT(RND * 10) + 11
BA = INT(RND * 10) + 4    'BAD
BB = INT(RND * 10) + 11
GI = 10
BI = 10

DO
Q = Q + 1
IF Q > SP% THEN GOSUB MRV

LOCATE A, B
PRINT CHR$(1)
LOCATE GA, GB
PRINT "+"
  LOCATE BA, BB
  PRINT "X"
'LOCATE 1, 1
'PRINT "A="; A; "B="; B; "GA="; GA; "GB="; GB; "BA="; BA; "BB="; BB
LOCATE 18, 1
PRINT "GI="; CINT(GI); "   "
LOCATE 19, 1
PRINT "BI="; CINT(BI); "   "
LOCATE 16, 1
PRINT "SCORE:"; CINT(SC); "   "

IF A = GA AND B = GB THEN           'WHAT HAPPENS IF TOUCH GOOD
SC = SC + 1
GI = GI - 1
IF GI < 2 THEN GI = 2
BI = BI + .5
IF B > 25 THEN BI = 25
LOCATE GA, GB
PRINT " "
GA = INT(RND * 10) + 4   'GOOD
GB = INT(RND * 10) + 11
SOUND 200, .5
END IF

IF A = BA AND B = BB THEN          'WHAT HAPPENS IF TOUCH BAD
SC = SC - 1.4
BI = BI - 1
IF BI < 1 THEN BI = 1
GI = GI + 1
IF GI > 10 THEN GI = 10
LOCATE BA, BB
PRINT " "
BA = INT(RND * 10) + 4   'BAD
BB = INT(RND * 10) + 11
SOUND 50, .5
END IF

IF SC <= -25 THEN GOTO FIN
IF SC >= 25 THEN GOTO FIN

LOOP UNTIL INKEY$ <> ""
END

MRV:
Q = 0
LOCATE A, B
PRINT " "

GG = INT(RND * GI) + 1    ' GOTO GOOD , BASED ON GOOD INTELIIGENCE
IF GG = 1 THEN
IF A < GA THEN A = A + 1
IF A > GA THEN A = A - 1
IF B < GB THEN B = B + 1
IF B > GB THEN B = B - 1
ELSEIF GG > 1 THEN
RM = INT(RND * 4) + 1
IF RM = 1 THEN A = A + 1
IF RM = 2 THEN A = A - 1
IF RM = 3 THEN B = B + 1
IF RM = 4 THEN B = B - 1
END IF
GGB = INT(RND * BI) + 1    ' AVOIDING BAD BASED ON BAD INTEL
IF GGB = 1 THEN
IF A > BA - 7 THEN A = A - 1
IF A < BA + 7 THEN A = A + 1
IF B > BB - 7 THEN B = B - 1
IF B < BB + 7 THEN B = B + 1
END IF

IF A >= 14 THEN A = 13               'WALL COLLISION
IF A <= 3 THEN A = 4
IF B >= 21 THEN B = 20
IF B <= 10 THEN B = 11

BTM = BTM + 1
IF BTM >= 4 THEN GOSUB BMRV 'BAD GUYS MOVES EVERY 2 SUB LOOPS
RETURN

BMRV:
BTM = 0                           'ALL THIS IS BAD GUYS HUNTING
LOCATE BA, BB
PRINT " "
RM = INT(RND * 7) + 1
IF RM > 4 THEN
IF BA < A THEN BA = BA + 1
IF BA > A THEN BA = BA - 1
IF BB < B THEN BB = BB + 1
IF BB > B THEN BB = BB - 1
END IF
RM = INT(RND * 4) + 1
IF RM = 1 THEN BA = BA + 1
IF RM = 2 THEN BA = BA - 1
IF RM = 3 THEN BB = BB + 1
IF RM = 4 THEN BB = BB - 1
IF BA >= 14 THEN BA = 13         'BAD GUY WALL
IF BA <= 3 THEN BA = 4
IF BB >= 21 THEN BB = 20
IF BB <= 10 THEN BB = 11
RETURN

FIN:
IF SC <= -20 THEN PRINT "DEATH"
IF SC >= 20 THEN PRINT "EVOLUTION"
END

I knocked it up in about an hour and a half.
Feel free to mess around with it.
It is easy to create a computer that learns just about anything.

Ask me again in three years, when desktop computers are 10ghz.
perhaps, but I argue theyll never gain proper sentiency, at least not in human terms. The illusion that they can think for themselves, perhaps, but not true self awareness.
Humans are just blobs of stuff, so why can't computers simulate those blobs of stuff? They can. You will see it soon.
Ive actually got a glitch in my AI program. I couldnt quite get the avoiding the enemy coding right.

the smiley face is meant to avoid the enemy X only when the x is within a certain range. if the X comes within7, or maybe 5 blocks, the face is supposed to try and avoid him, based on the randomisation lines.

I dunno, I cant quite get it right. he either goes towards him, or simply doesnt avoid him. Im perplexed. any ideas?
Make your if statements exit out of the subs....

Or use SELECT CASE.
I dont think select case would work here.

Code:
GGB = INT(RND * BI) + 1    ' AVOIDING BAD BASED ON BAD INTEL
IF GGB = 1 THEN
IF A > BA - 7 THEN A = A - 1     'its these 4 troublesome lines
IF A < BA + 7 THEN A = A + 1
IF B > BB - 7 THEN B = B - 1
IF B < BB + 7 THEN B = B + 1
END IF

its all the IF statements, regarding position of each co-ordinates.
for example, if the A coordinate is more than the enemy minus a bit, IE to his left, then go left until you are no longer in that area.

at least thats the way my mind calculates it.
Firstly the +/-7 bit you have in your code, is just changing the co-ords of the X.

IF ABS(A - BA) < 3 AND ABS(B - BB) < 3 THEN
IF SQR((A - BA) ^ 2 + (B - BB) ^ 2) < 3 THEN

either of these lines above will test for distance. It might also help you if you use more meaningfull variable names. Smile


If you adjust you code so there is no +7/-7 and fix BI at 1 your character hunts down the X Tongue
This is because you have the +1/-1 at the end of each line mixed up. (in your 2nd code sample)


You'll also need to refine your code, as the creatures can move more than one square at a turn.

It might also be more interesting if the AI behaves differently, e.g. if the AI needs food, the hungrier it gets the more willing it is to dodge past the X and risk getting caught. meh... just thoughts... Smile
starting back to your first statement, that was a very good analogy (for those of us who have been to Japan :wink: )

::EDIT::
Wow, I'm a guru now! :lol:
hmmm.... sounds interesting.

i believe SOMEDAY computers can gain sentience. i remember in one of my popular science magazines, there was a program that had a stick man. it had muscles, nerves and everything. it was to walk across the screen, by stimulating it's muscles. however, the programmers didn't tell the program what muscles, so the program would create "generations" of stick men, that fired different sequences of muscles. after a generation, it would record the results, and if had anything that seemed to be on the right track, it would save those characteristics for the next generation, so the program would basically pass down the good parts. eventually, after many tests, the program learned how to walk. It did many odd things as well, like bounce, crawl, etc. etc. the technology was developed so people wouldn't have to waste time programming in each and every movements of characters for 3d movies, or something like that.

i myself am going to try to make a chat ai program. it'll know a few words. as you talk to it, it will dissect your sentences, and put the seperate words in categories (nouns, etc.) i also hope to make it so it will be able to construct messages from scratch. it'll take more than a day, i know, but hopefully it'll be worth it.

my ultimate goal would be able to make it to develop a personality. give it likes, dislikes, a way of speaking, etc. etc. i'm probably WAY WAY in over my head with this, but it's interesting to say the least.
Pages: 1 2