AI

Discuss PocketC for Palm OS (including Desktop Edition)

Postby nomar on Sun Apr 29, 2001 12:46 pm

Do you think you could post a sample AI source code for either Visual Basic or PocketC?
nomar
 
Posts: 28
Joined: Thu Apr 19, 2001 11:20 pm

Postby wossname on Sun Apr 29, 2001 5:02 pm

I haven't got any automated AI at the moment, but here is a program that lets you choose two bitmaps out of a selection and breed them together to form the next generation of offspring. If you do enough generations, you can end up with things like smiley faces :) if you can find images that look more and more like them in subsequent generations. It will become clear when you run the program. It should all fit into 1 memo record.

<pre id=code><font face=courier size=2 id=code>//Life Simulator

#define zero "0000000000000000000000000000000000000000000000000000000000000000"
#define num 32
#define select 1
#define deselect 0

#define len 64
/*len must not be more than 64*/

char alpha[16]={'0','1','2','3','4','5','6', '7','8','9','A','B','C','D','E','F'};

swap(pointer aa,pointer bb)
{
int temp;
temp=*bb;
*bb=*aa;
*aa=temp;
}

highlight(int cell, int col)
{
frame(col,8+((cell%8)*18),16+(30*(int)(cell/8)),24+((cell%8)*18),44+(30*(int)(cell/8)),0);
}
int catchpen()
{
int x,y,i,e;
while(1)
{
e=0;
while(e!=3) e=event(1);
x=penx();
y=peny();

if(x>7 && x<153 && y>15 && y<135)
return ((int)((y-16)/30)*8)+ (int)(((x-8)/18));
}
}

main()
{
string pop[num],wina,winb;
int i,j,k,a,b,cut,gen=1;
wina=strleft(zero,len);
winb=strleft(zero,len);

graph_on();
title("Life Simulator! By Adam Ward");
for(i=0;i<num;i++)
{
pop[i]=zero;
for(j=0;j<len;j++)
pop[i]@[j]=alpha[random(16)];
bitmap(8+((i%8)*18),28+(30*(int)(i/8)), "10"+pop[i]);
text(8+((i%8)*18),16+(30*(int)(i/8)),i);
}
text(0,136,"Generation: "+gen);

while(1)
{
gen++;
do{
highlight(a,deselect);
highlight(b,deselect);
rect(0,0,148,160,160,0);
text(0,148,"Choose first image");
a=catchpen();
highlight(a,select);
text(0,148,"Choose second image");
b=catchpen();
highlight(b,select);
if(a>b)
swap(&a,&b);
}while(!confirm("Breed gen: "+gen+" from #"+a+" & #"+b+"?"))

wina=pop[a];
winb=pop[b];

clearg();
for(i=0;i<num;i++)
{
cut=random(len);
pop[i]=strleft(wina,cut)+strright(winb,len-cut);

//random mutation...
k=random(6);
for(j=0;j<5;j++)
pop[i]@[random(len)]=alpha[random(16)];

bitmap(8+((i%8)*18),28+(30*(int)(i/8)), "10"+pop[i]);
text(8+((i%8)*18),16+(30*(int)(i/8)),i);
text(0,136,"Generation: "+gen);
}
}
}</font id=code></pre id=code>

Wossname :)
Wossname :)
Are you <i>local</i>?
wossname
 
Posts: 275
Joined: Sat Feb 24, 2001 7:18 am


Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 2 guests

cron