+Vorticon Posted February 15, 2013 Share Posted February 15, 2013 (edited) Hi.I have been reading the 1982 book by David L. Heiserman titled "Projects in Machine Intelligence For Your Home Computer" which I found on Ebay a while back. At first glance, it looked like a very primitive book for the beginner programmer with a lofty title, but then as I dug further into it out of boredom while on a plane ride, it started to reveal some very interesting concepts particularly about the emergence of seemingly complex behavior out of simple reflexive elements.So I decided to start a thread on my experimentations with this topic, basing it on the concepts detailed in the book.First the framework: a box with two bugs and random obstacles. The bugs have fight and flight behavior, and have an even chance of destroying an obstacle or their counterpart versus fleeing away. Their direction of motion is randomly chosen and will only change when an impenetrable obstacle blocks the way. The activities of the bugs are simulated through asynchronous multitasking. Here's what it looks like:http://youtu.be/L_5Sy0NYdiYAs you can see, it's very simple, for now. Over the course of the next several weeks (or months), I will be adding more features. For example, what happens if I add resource competition? How about random mutations that add or subtract capabilities? And if I add non-aggressive strains to the mix, will predator-pray behavior emerge?We shall see Stay tuned...Oh and it's written in XB of expediency and ease of programming. Here's the listing: 5 CALL CLEAR :: RANDOMIZE 6 DIM PHASE(2),PX(2),PY(2),BUG(2),CX(2),CY(2) 10 CALL CHAR(96,"FFFFFFFFFFFFFFFF",104,"007E7E7E7E7E7E00",112,"80433C3C3C7C8204",120,"80433C3C3C7C8204") 20 CALL COLOR(10,15,1,11,10,1,12,6,1)::CALL SCREEN(4) 25 BUG(1)=112::BUG(2)=120 30 REM SET UP FIELD 40 CALL HCHAR(1,1,96,32) :: CALL VCHAR(2,1,96,23) :: CALL VCHAR(2,32,96,23) :: CALL HCHAR(24,2,96,30) 50 FOR I=1 TO 40 :: CALL PLACE(X,Y) :: CALL HCHAR(Y,X,104) :: NEXT I 60 FOR ID=1 TO 2::CALL PLACE(PX(ID),PY(ID)) :: CALL HCHAR(PY(ID),PX(ID),BUG(ID))::PHASE(ID)=1::NEXT ID 100 REM ALPHA BEHAVIOR 101 ID=1 102 IF PHASE(ID)=0 THEN 150 ELSE IF PHASE(ID)=2 THEN 120 103 REM PHASE 1 - SELECT MOVE DIRECTION 110 CALL MOVE(CX(ID),CY(ID)) 111 REM PHASE 2 - DETECT OBSTACLE AND MOVE 120 CALL DETECT(PX(ID),PY(ID),CX(ID),CY(ID),RC,R,NX,NY) 130 IF R=1 THEN CALL SOUND(10,110,15) :: PHASE(ID)=1::GOTO 150 131 IF R=2 AND ID=1 THEN PHASE(2)=0 ELSE IF R=2 AND ID=2 THEN PHASE(1)=0 132 PHASE(ID)=2 140 CALL HCHAR(PY(ID),PX(ID),32) :: PX(ID)=NX :: PY(ID)=NY :: CALL HCHAR(PY(ID),PX(ID),BUG(ID)) :: CALL SOUND(10,2000,15) 150 IF ID=1 THEN ID=2 ELSE ID=1 160 GOTO 102 10000 SUB PLACE(X,Y) 10010 X=INT(RND*30)+2 :: Y=INT(RND*21)+2 10020 CALL GCHAR(Y,X,C) :: IF C<>32 THEN 10010 10030 SUBEND 10040 SUB MOVE(CX,CY) 10050 CX=INT(RND*2) :: DIR=INT(RND*9)+1 :: IF DIR>5 THEN CX=-CX 10060 CY=INT(RND*2) :: DIR=INT(RND*9)+1 :: IF DIR>5 THEN CY=-CY 10065 IF CX=0 AND CY=0 THEN 10050 10070 SUBEND 10080 SUB DETECT(X,Y,CX,CY,RC,R,NX,NY) 10090 NX=X :: NY=Y :: SX=SGN(CX) :: SY=SGN(CY) :: AX=ABS(CX) :: AY=ABS(CY) :: R=0 10100 IF AX=0 THEN 10130 10110 AX=AX-1 :: IF SX=1 THEN NX=NX+1 ELSE NX=NX-1 10130 IF AY=0 THEN 10150 10140 AY=AY-1 :: IF SY=1 THEN NY=NY+1 ELSE NY=NY-1 10150 CALL GCHAR(NY,NX,RC) 10160 IF RC=32 THEN 10170 10161 IF RC=96 THEN R=1::GOTO 10180 10162 KILL=INT(RND*9)+1::IF KILL>5 THEN CALL SOUND(10,-5,15) ELSE R=1::GOTO 10180 10163 IF RC=112 OR RC=120 THEN R=2::GOTO 10180 10170 IF AX>0 OR AY>0 THEN 10100 10180 SUBEND Edited January 29, 2016 by Vorticon 2 Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.