Author Topic: Bot test 1  (Read 4453 times)

Offline rayz

  • Bot Neophyte
  • *
  • Posts: 19
    • View Profile
Bot test 1
« on: April 03, 2009, 04:58:02 PM »
Since I went through all of the trouble to make it a bot to test my algorithm, I thought I might post it here.

It's an interesting behavior bot.  It approimates sine and cosine for use with direction setting. I think most of the stuff is explained in the comments.

I commented out a tracking and shooting section.  If you uncomment it (except for the shooting part), and make a new version with more .up store commands, you can have the two species of bots just run straight at each other and go into complex little loops.    

Anyway, here it is!

Works best in no costs environment, too inefficient to run otherwise.
Code: [Select]
'An attempt to make the bot move north no matter how it is turned.
'Lacks precision due to a integer-only stack.
'Attempt to correct that by waiting to divide bigs numbers till end.
'
'edit these to wherever--maybe pi should be epigenetic?
'sineIn and sineOut are input/output for Taylor series
'sineOut returns a number multiplied by factor2 (approx.)
'pi and factor are internal constants for sine calculation
'aimHeading is the absolute heading that the bot wants to travel
'magnitude is how approximately how fast (in Darwinbots units) the bot will travel
'turn is how much the bot itself turns each cycle--useful to sweep area around the bot
'aimTurn is how much the bot changes the heading each cycle.
def sineIn 50
def sineOut 51
def pi 52
def factor 53
def aimHeading 410
def magnitude 54
def turn 55
def aimTurn 56
def factor2 57

'set constants
cond
*.robage 1 =
start
31415 .pi store
10000 .factor store
32000 .factor2 store
100 .magnitude store
0 .aimHeading store
*.tiepres .deltie store
35 .turn store
5 .aimTurn store
'just to move them out of the way
1221 .eye1width store
1221 .eye2width store
1221 .eye3width store
1221 .eye4width store
'1221 .eye5width store
1221 .eye6width store
1221 .eye7width store
1221 .eye8width store
1221 .eye9width store
stop

'manage body
cond
*.body 10 <
*.nrg 300 >
start
100 .strbody store
stop

cond
*.nrg 500 <
*.body 10 >
start
10 .fdbody store
stop

cond
start
*.aim *.turn add .setaim store
*.aimHeading *.aimTurn add .aimHeading store
stop

'try to aim the eye and shoot
'cond
'*.refup *.myup !=
'*.eye5 0 !=
'start
'*.refxpos *.refypos angle .aimHeading store
'*.aimHeading *.aim sub *.turn sub .eye5dir store
'*.turn *.aim add *.aimHeading sub .aimshoot store
'-6 .shoot store
'*.nrg 2 div .shootval store
'stop
'
'cond
'*.waste 100 >
'start
'-4 .shoot store
'*.waste .shootval store
'stop

'begin movement section: it makes the bot move in the direction of aimHeading
'normalize aimheading
cond
*.aimHeading 1256 >=
start
*.aimHeading 1256 sub .aimHeading store
stop

cond
*.aimHeading 0 <
start
*.aimHeading 1256 add .aimHeading store
stop

'from here down it makes the bot move in the direction of *.aimheading
cond
start
*.aimHeading *.aim sub .sineIn store
stop

'begin sineIn normalization
cond
*.sineIn 0 <
start
*.sineIn 1256 add .sineIn store
stop

cond
*.sineIn 1256 >
start
*.sineIn 1256 sub .sineIn store
stop

'Taylor expansion of sine function
cond
start
628 *.sineIn sub *.pi mult 628 div *.factor div 1 pow *.factor2 mult 1 div 628 *.sineIn sub *.pi mult 628 div *.factor div 3 pow *.factor2 mult 6 div sub 628 *.sineIn sub *.pi mult 628 div *.factor div 5 pow *.factor2 mult 120 div add 628 *.sineIn sub *.pi mult 628 div *.factor div 7 pow *.factor2 mult 5040 div sub .sineOut store
stop

cond
start
*.sineOut *.magnitude mult *.factor2 div .sx store
stop

'calculate value for .up
cond
start
314 *.aimHeading *.aim sub sub .sineIn store
stop

cond
*.sineIn 0 <
start
*.sineIn 1256 add .sineIn store
stop

cond
*.sineIn 1256 >
start
*.sineIn 1256 sub .sineIn store
stop

'Taylor expansion of sine function
cond
start
628 *.sineIn sub *.pi mult 628 div *.factor div 1 pow *.factor2 mult 1 div 628 *.sineIn sub *.pi mult 628 div *.factor div 3 pow *.factor2 mult 6 div sub 628 *.sineIn sub *.pi mult 628 div *.factor div 5 pow *.factor2 mult 120 div add 628 *.sineIn sub *.pi mult 628 div *.factor div 7 pow *.factor2 mult 5040 div sub .sineOut store
stop

cond
start
*.sineOut *.magnitude mult *.factor2 div .up store
stop
'end movement section

'cond
'*.nrg 500 >
'*.body 1000 >=
'start
'50 .repro store
'stop
end
« Last Edit: April 05, 2009, 12:35:55 AM by rayz »

Offline Moonfisher

  • Bot Overlord
  • ****
  • Posts: 592
    • View Profile
Bot test 1
« Reply #1 on: April 03, 2009, 07:45:29 PM »
Very nice... hope you don't mind if I steal that.

Offline bacillus

  • Bot Overlord
  • ****
  • Posts: 907
    • View Profile
Bot test 1
« Reply #2 on: April 06, 2009, 03:31:59 AM »
Very nicely done   . One minor thing I would change though is replace all that tedious wrapping with
Code: [Select]
*.sineIn 1256 mod .sineIn storeThis modulus function replaces the four genes you used.
I look forward to new innovations using this algoritm...  
"They laughed at Columbus, they laughed at Fulton, they laughed at the Wright brothers. But they also laughed at Bozo the Clown."
- Carl Sagan

Offline Moonfisher

  • Bot Overlord
  • ****
  • Posts: 592
    • View Profile
Bot test 1
« Reply #3 on: April 06, 2009, 01:06:55 PM »
There's actualy a slight advantage to wrapping manualy. Although modulus is a nifty operator and I personaly prefer to use it aswell, it is a bit heavy to execute.
So if you have a bot that runs realy slow and it has a lot of mod operators in it then it might actualy help a litle to replace them with logic. (Not sure how big of a difference it would make in DB... maybe if you have a high population or something)

Personaly I'll take readability over speed wherever possible. And the actual energy costs in DB are lower when using math over logic anyway...

Offline rayz

  • Bot Neophyte
  • *
  • Posts: 19
    • View Profile
Bot test 1
« Reply #4 on: April 15, 2009, 11:01:44 PM »
Quote from: bacillus
Very nicely done   . One minor thing I would change though is replace all that tedious wrapping with
Code: [Select]
*.sineIn 1256 mod .sineIn storeThis modulus function replaces the four genes you used.
I look forward to new innovations using this algoritm...  

one small problem that I found: at certain numbers, it reads numbers greater than 1 and less than -1, and at these values the value switches from something like 312... to -312...-- something a sine function does not do.

If somebody could take a look through it and see if there are any bugs, that would be great!

Thanks!

-Raymond

...School takes up too much time!

Offline Prsn828

  • Bot Destroyer
  • ***
  • Posts: 139
    • View Profile
Bot test 1
« Reply #5 on: April 16, 2009, 10:46:48 AM »
Quote from: rayz
Quote from: bacillus
Very nicely done   . One minor thing I would change though is replace all that tedious wrapping with
Code: [Select]
*.sineIn 1256 mod .sineIn storeThis modulus function replaces the four genes you used.
I look forward to new innovations using this algoritm...  

one small problem that I found: at certain numbers, it reads numbers greater than 1 and less than -1, and at these values the value switches from something like 312... to -312...-- something a sine function does not do.

If somebody could take a look through it and see if there are any bugs, that would be great!

Thanks!

-Raymond

...School takes up too much time!

Interesting point.  Perhaps you could say you re-invented the sine, and leave it at that   But honestly, it is probably integer rounding trouble, it is something we must all accept at some point... or you could fix the source code, but accepting it is much easier.
So, what will it be? Will you submit to my will, or must I bend reality to suit my needs?
Better answer before I do BOTH!

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Moderator
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Re: Bot test 1
« Reply #6 on: April 30, 2014, 02:05:21 PM »
rayz, you will be happy to know that sin and cos are now native.  :)