### Author Topic: Bot test 1  (Read 4453 times)

#### rayz

• Bot Neophyte
• Posts: 19
##### 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 50def sineOut 51def pi 52def factor 53def aimHeading 410 def magnitude 54def turn 55 def aimTurn 56def factor2 57'set constantscond*.robage 1 =start31415 .pi store10000 .factor store32000 .factor2 store100 .magnitude store0 .aimHeading store*.tiepres .deltie store35 .turn store5 .aimTurn store'just to move them out of the way1221 .eye1width store1221 .eye2width store1221 .eye3width store1221 .eye4width store'1221 .eye5width store1221 .eye6width store1221 .eye7width store1221 .eye8width store1221 .eye9width storestop'manage bodycond*.body 10 <*.nrg 300 >start100 .strbody storestopcond*.nrg 500 <*.body 10 >start10 .fdbody storestopcondstart*.aim *.turn add .setaim store*.aimHeading *.aimTurn add .aimHeading storestop'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 aimheadingcond*.aimHeading 1256 >=start*.aimHeading 1256 sub .aimHeading storestopcond*.aimHeading 0 <start*.aimHeading 1256 add .aimHeading storestop'from here down it makes the bot move in the direction of *.aimheadingcondstart*.aimHeading *.aim sub .sineIn storestop'begin sineIn normalizationcond*.sineIn 0 <start*.sineIn 1256 add .sineIn storestopcond*.sineIn 1256 >start*.sineIn 1256 sub .sineIn storestop'Taylor expansion of sine functioncondstart628 *.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 storestopcondstart*.sineOut *.magnitude mult *.factor2 div .sx storestop'calculate value for .upcondstart314 *.aimHeading *.aim sub sub .sineIn storestopcond*.sineIn 0 <start*.sineIn 1256 add .sineIn storestopcond*.sineIn 1256 >start*.sineIn 1256 sub .sineIn storestop'Taylor expansion of sine functioncondstart628 *.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 storestopcondstart*.sineOut *.magnitude mult *.factor2 div .up storestop'end movement section'cond'*.nrg 500 >'*.body 1000 >='start'50 .repro store'stopend`
« Last Edit: April 05, 2009, 12:35:55 AM by rayz »

#### Moonfisher

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

#### bacillus

• Bot Overlord
• Posts: 907
##### 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 store`This 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

#### Moonfisher

• Bot Overlord
• Posts: 592
##### 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...

#### rayz

• Bot Neophyte
• Posts: 19
##### 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 store`This 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!

#### Prsn828

• Bot Destroyer
• Posts: 139
##### 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 store`This 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!

#### Botsareus

• Society makes it all backwards - there is a good reason for that
• Moderator
• Bot God
• Posts: 4483
##### 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.