Thread: Onwaal
View Single Post
  #4  
Old 05-25-2007, 01:26 AM
JkWhoSaysNi JkWhoSaysNi is offline
Ruler of the graalaxy
Join Date: Feb 2005
Location: Great Britain
Posts: 488
JkWhoSaysNi is on a distinguished road
Send a message via ICQ to JkWhoSaysNi
Actually I have some code similar to what you're doing.

This was for an NPC:

PHP Code:
s1 = (onwall2(x+vecx(this.dir)+vecx(this.dir)-abs(vecy(this.dir)),y+vecy(this.dir)+vecy(this.dir)-abs(vecx(this.dir)),1,1)) ? 10;
  
s2 = (onwall2(x+vecx(this.dir)+vecx(this.dir)+abs(vecy(this.dir)*2),y+vecy(this.dir)+vecy(this.dir)+abs(vecx(this.dir)*2),1,1)) ? 10
It puts 2 'sensors' in at the front of the NPC, then I had the NPC decide which way to turn based on the check.

It was actually a line follower which I tried (without success :P ) to develop into a maze solver.

The line follower code may actually help as a base for deciding what should happen depending on which 'sensor' has been hit.

PHP Code:
//Line follower

function onTimeout() {
 
weights = {{1,0,-1},{1,-1,0}};
 
output = {1,1};

  
s1 = (onwall2(x+vecx(this.dir)+vecx(this.dir)-abs(vecy(this.dir)),y+vecy(this.dir)+vecy(this.dir)-abs(vecx(this.dir)),1,1)) ? 10;
  
s2 = (onwall2(x+vecx(this.dir)+vecx(this.dir)+abs(vecy(this.dir)*2),y+vecy(this.dir)+vecy(this.dir)+abs(vecx(this.dir)*2),1,1)) ? 10;
  
res1=weights[0][1]*s1+weights[0][2]*s2+weights[0][0];
  
output[0] = (res1>0) ? 0;
  
res2=weights[1][1]*s1+weights[1][2]*s2+weights[1][0];
  
output[1] = (res2>0) ? 0;



   if ((
output[0]==1)&&(output[1]==1))
    
lturn(); //turn -45 degrees
   
if ((output[0]==0)&&(output[1]==0))
    
rturn(); //turn 45 degrees

   
if ((output[0]==1)&&(output[1]==0))
    
forward(); 
   if ((
output[0]==0)&&(output[1]==1))
    
back();


     
setTimer(0.05);


It actually uses a 2 neuron model (not really a neural net because it's just a 2 neuron model but it could be developed into one)
__________________

Coming soon (Hopefully:P)
Reply With Quote