͕A:dd ( @ (//(  0/80@0?/8 0( ?G@POWOXOP?H0@/7@O_``h_hPX 0(P_oppxow_g@O/8'' 7p`o?G/7 0??H/8`/o?GOX@H0?/pOW?H/8 7OP?G/7( P0@PX@O0@ 0O @H/@' 00@@P0?'_OP@H( 7/7' ^^^^^^^^^^^^^^^^^^^^^^^^^^TeeBBBBeTT^^^^^^^eBDJ33333JJDBeZ^^^^TD33==#####==3JDBT^^^^eJ=###=3DeZ^^TB3# #=3JBZ^^T3#  #=JBT^^J# Sll #=JBZ^T# %,68??86,/@A*< ##45('.6787-9%:;*<=#$+&,--.,/01)2 3 $%&&'%($!)* ##  !"#     ??dA#D@sprite0   Xxs5a3 b(fdH@Q@(EhpG45V`N]+c0 !6Q~j T7|Q4'sprite1   |xs5a3 b(fdH@Q@(Eh3PG 1ȅ#׎l2G  Ed؂x@ 0)hspeed-=1 if (output[1]>0)hspeed+=1 if (output[2]>0)vspeed-=1 if (output[3]>0)vspeed+=1 0000000c bughealth150000000action_kill_object00000000daction_if_variable bughealth1000200000[bughealth=500 newid=instance_create(x+20,y+20,bug) //copy over the parent genes for (i=0 ;i<20; i+=1) { for (j=0;j<12; j+=1) { newid.gene[i,j]= gene[i,j] } } // mutate one gene newid.gene[random(20),random(12)]=random(100)-500000000 daction_if_variable showstats000000000000000c showstats1000000cdepth-1000000000ccontroller.displayanything2000000000000000000000000000000c showstats0000000cdepth100000000000000000daction_if_variablex room_width200000cx0000000daction_if_variablex0100000cx room_width000000daction_if_variabley room_height200000cy0000000daction_if_variabley0100000cy room_height000000action_draw_sprite100-10000daction_if_variablecontroller.displayanything020000000000000 action_draw_font"Times New Roman",8,0,0,0,0,010000000action_draw_text"" +string(bughealth)01000000daction_if_variable showstats0000000[*draw_line(x,y,x+30,y+30) draw_rectangle(x+30,y+30,x+420,y+200) displaystring= "input " for (i=0; i<20; i+=1) displaystring=displaystring + string(sign(input[i])) + " " draw_text(x+35,y+30,displaystring) draw_text(x+35,y+40,"gene") for (j=0; j<12; j+=1) { displaystring= "" for (i=0; i<20; i+=1) { displaystring=displaystring + string (round(gene[i,j])) + " " } draw_text(x+35,y+50+10*j,displaystring) } displaystring= "output " for (j=0; j<12; j+=1) displaystring=displaystring + string(sign(output[j])) + " " draw_text(x+35,y+170,displaystring) //draw food sensors, red if food sensed if(instance_position(x+15,y,food)= noone) draw_sprite(sprite2,-1,x+15,y) else draw_sprite(sprite3,-1,x+15,y) if(instance_position(x-15,y,food)= noone) draw_sprite(sprite2,-1,x-15,y) else draw_sprite(sprite3,-1,x-15,y) if(instance_position(x+25,y,food)= noone) draw_sprite(sprite2,-1,x+25,y) else draw_sprite(sprite3,-1,x+25,y) if(instance_position(x-25,y,food)= noone) draw_sprite(sprite2,-1,x-25,y) else draw_sprite(sprite3,-1,x-25,y) if(instance_position(x,y+15,food)= noone) draw_sprite(sprite2,-1,x,y+15) else draw_sprite(sprite3,-1,x,y+15) if(instance_position(x,y-15,food)= noone) draw_sprite(sprite2,-1,x,y-15) else draw_sprite(sprite3,-1,x,y-15) if(instance_position(x,y+25,food)= noone) draw_sprite(sprite2,-1,x,y+25) else draw_sprite(sprite3,-1,x,y+25) if(instance_position(x,y-25,food)= noone) draw_sprite(sprite2,-1,x,y-25) else draw_sprite(sprite3,-1,x,y-25) 000000000000000 controller -action_set_alarm70000000c foodnumber0000000c bugnumber0000000[ show_info()0000000cdepth-500000000c writetofile0000000cdisplayanything2000000[//this alarm is set by the f key file_write_string(string(foodnumber) +", " +string(bugnumber)) file_writeln() alarm[1]=50 //save every 50th step to file 0000000action_create_object 010+ random(room_width-20)10+ random(room_height-20)00000-action_set_alarm70000000 [// if info boxes are displayed close them, otherwise quit the simulation numbershowing=0 with(bug) { controller.numbershowing+=showstats showstats=0 depth=1000 } 0000000 action_ifnumbershowing=0000000000000000daction_if_variabledisplayanything2000000cdisplayanything10000000000000000000000action_if_questionQuit?0000000Laction_end_game000000000000000000000000[ file_close()0000000daction_if_variabledisplayanything020000000000000action_draw_rectangle00displayanything*170-90displayanything*80-500000action_draw_text" food " +string(foodnumber)0000000action_draw_text" bugs " +string(bugnumber)01000000daction_if_variabledisplayanything120000000000000action_draw_text p pause02000000action_draw_text c de-select all03000000action_draw_text a select all04000000action_draw_text% d display detail, affects speed05000000action_draw_text5 f save population stats to comma separated file06000000action_draw_text left click select bug07000000action_draw_text F1 help08000000action_draw_text esc return to simulation090000000000000000000000P[mkeyboard_wait(); // waits until user presses a key io_clear(); // clears all keyboard and mouse states 0000000Fdaction_if_variable writetofile000000000000000action_if_question&Save population stats to smartbug.txt?0000000[alarm[1]=1 writetofile=1 file_open_write("smartbug.txt") file_write_string("foodnumber, bugnumber") file_writeln() room_caption=room_caption +" (statistics are being saved to file)" 000000000000000D daction_if_variabledisplayanything0000000cdisplayanything20000000000000000000000daction_if_variabledisplayanything1000000cdisplayanything000000000000000daction_if_variabledisplayanything2000000cdisplayanything100000000000000C[H//close all info boxes with(bug) { showstats=0 depth=1000 } 0000000A[`// show info boxes for all with(bug) { showstats=1 depth=-1000 } displayanything=20000000room0$Smartbug - evolution of intelligence X        ``0pP0 0@@ pP@0`0`†ÆPĆPņPƆPPdžPȆ@Ɇ0@ʆPˆ 0̆p0͆0Ά @φPІ`0ц0҆@ӆ@Ԇ Նֆ@׆؆نچۆP܆ ݆@ކ߆@ @@`@  PP` `````@`0 PP pp @`  0 @p  p  Pp00p0 `! #@$0%p&'() *@+0 ,p0-0.0/ 00@0123456789:` < = ? @ 0ABD`EFpGpHI JK L@M`NOPQRST U@VPWpXYZ[\]^_`a b@cdefg0hPipjklmnpopppqrstupvPw0x yz{|}p~pP@p`pP p   Pp000ppp @ @@ ` 0Pp0000P0Pp@{\rtf1\ansi\deff0\deftab720{\fonttbl{\f0\fswiss MS Sans Serif;}{\f1\froman\fcharset2 Symbol;}{\f2\fswiss\fcharset1 Arial;}{\f3\fswiss\fcharset1 Arial;}{\f4\fswiss\fcharset1 MS Sans Serif;}{\f5\fmodern\fcharset1 Courier New;}{\f6\fswiss\fprq2 System;}{\f7\fmodern\fcharset1 Courier New;}} {\colortbl\red0\green0\blue0;\red0\green0\blue255;\red128\green0\blue128;\red0\green0\blue128;\red0\green128\blue0;} \deflang1033\pard\plain\f3\fs32\cf0\b Smartbug \par \plain\f3\fs24\cf0\b Tony Forster October 05 \par \plain\f3\fs24\cf0 Evolution through natural selection \par May be copied with acknowledgement \par \par mouse click \tab select, displays bug info including genetic code \par p \tab \tab pause \par c \tab \tab de-select all \par a\tab \tab select all \par d\tab \tab display detail: all, population&health, none \par f\tab \tab save population stats to comma separated file \par F1 \tab \tab to display this screen \par escape \tab return to simulation \par \par The info boxes show the "genetic code" or the program the bugs have developed by natural selection. You can see how the bugs are related. (The level of information you display affects the program speed.) \par \par The save to file option allows you to import population statistics into a spread sheet and examine population trends \par \par \plain\f3\fs24\cf0\ul How its programmed \par \plain\f3\fs24\cf0 Each bug loses one unit of health per step \par \plain\f4\fs16 set variable bughealth relative to -1 \par \plain\f3\fs24\cf0 \par If a bug runs out of food it dies \par \plain\f4\fs16 set variable bughealth relative to -1 \par if bughealth is smaller than 0 \par destroy the instance\plain\f3\fs24\cf0 \par \par If it eats food, its health increases \par \plain\f4\fs16 set variable bughealth relative to 150\plain\f3\fs24\cf0 \par \par If its health reaches 1000 it divides \par \plain\f4\fs16 if bughealth is larger than 1000 \par execute code: \par bughealth=500 \par newid=instance_create(x+20,y+20,bug) \par \plain\f3\fs24\cf0 \par Its genes are copied to the new bug \par \plain\f4\fs16 for (i=0 ;i<20; i+=1) \par \{ \par for (j=0;j<12; j+=1) \par \{ \par newid.gene[i,j]= gene[i,j] \par \} \par \} \par \plain\f3\fs24\cf0 \par One gene is mutated \par \plain\f4\fs16 newid.gene[random(20),random(12)]=random(100)-50 \par \plain\f3\fs24\cf0 \par The genes are used to determine behaviour \par There are 20 inputs, 8 related to food nearby, 4 previous direction and 8 memory stores \par \plain\f4\fs16 execute code: \par input[0]= sign(instance_position(x+15,y,food)) \par input[1]= sign(instance_position(x-15,y,food)) \par input[2]= sign(instance_position(x,y+15,food)) \par input[3]= sign(instance_position(x,y-15,food)) \par input[4]= sign(instance_position(x+22,y,food)) \par input[5]= sign(instance_position(x-22,y,food)) \par input[6]= sign(instance_position(x,y+22,food)) \par input[7]= sign(instance_position(x,y-22,food)) \par \par for (i=8; i<20; i+=1) \par \{ \par input[i] = sign(output[i-8]) \par \} \par \par \plain\f3\fs24\cf0 \par The 20 inputs are multiplied by a 20x12 gene array to produce 12 outputs \par \plain\f4\fs16 for (i=0 ;i<20; i+=1) \par \{ \par for (j=0;j<12; j+=1) \par \{ \par newid.gene[i,j]= gene[i,j] \par \} \par \} \par \plain\f3\fs24\cf0 \par Four of which control motion \par \plain\f4\fs16 if (output[0]>0)hspeed=-1 \par if (output[1]>0)hspeed=1 \par if (output[2]>0)vspeed=-1 \par if (output[3]>0)vspeed=1\plain\f3\fs24\cf0 \par \par and eight are memory data \par \par \plain\f3\fs24\cf0\ul Discussion \par \plain\f3\fs24\cf0 See how badly adapted lifeforms become extinct: \par The first to die are the ones that don't move \par Soon they are all related through one ancestor \par Diagonal movers take over from horizontal and vertical movers \par They learn to spread out \par Some get stuck with some food patterns and die \par Run it overnight, eventually the learn to hunt for food. \par Run it on 2 computers, compare the genetic code. \par \par Enable save to file "smartbug.txt" with the f key \par Import the comma separated text file into a spreadsheet \par Graph it \par What is the average bug population? Why? \par What is the trend in food population? Why? \par Why are there fluctuations? \par \par Is it sexual or asexual reproduction? \par What are the implications for the gene pool and the evolutionary process? \par Is this a good model of evolution? \par \par \plain\f3\fs24\cf0\ul Programming challenge \par \plain\f3\fs24\cf0 Write a version with sexual reproduction, when two bugs with health>1000 collide, they produce offspring with genetic code taken randomly from its parents. \par \par } Spritessprite0sprite1sprite2sprite3Sounds BackgroundsPathsScripts Data Files Time LinesObjectsfoodbug controllerRoomsroom0 Game Information Game Options