Author Topic: Random Bot  (Read 4418 times)

Offline Tilthanseco

  • Bot Builder
  • **
  • Posts: 60
    • View Profile
Random Bot
« on: August 05, 2012, 12:42:09 AM »
I took the random bot idea and used an internal random number generator instead of "rnd".

This way mutations can still affect the bot very well. I'm running this bot as a alga with a simple bot.

Regular Random Bot 0 to 1000
Code: [Select]
cond
start
1000 rnd 1000 rnd store
stop

Very Simple Internal Generator 0 to 999
Code: [Select]
'Environmental Seed
cond
*.robage 1 =
start
*.xpos *.ypos add 2 div 51 store
stop

'Location Generator
cond
start
*51 125 mult 31991 mod 51 store
*51 1000 mod 52 store
stop

'Value Generator to keep from Looping
cond
*52 51 !=
start
*51 125 mult 31991 mod 51 store *51 1000 mod *52 store
stop
P.S. Making a random number generator is hard... It took me most of the day to make a random enough one that was simple while limited to a state of 32000.
Many tries led to loops of often only 10 numbers.
Undisputed creator of bot Sonar!

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Moderator
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Re: Random Bot
« Reply #1 on: August 05, 2012, 10:44:56 AM »
Nice concept. How is this better then using rnd?

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Re: Random Bot
« Reply #2 on: August 05, 2012, 04:44:18 PM »
Yeah, random number generators are hard.  You might want to read chapter 7 of Numerical Recipes in C if you're interested in the subject at all.  It's a good introductory chapter on generators and why they're tricky.

Offline Tilthanseco

  • Bot Builder
  • **
  • Posts: 60
    • View Profile
Re: Random Bot
« Reply #3 on: August 06, 2012, 01:53:11 AM »
Thanks Nums, I read 7.1 and it was interesting and useful. The rest was out of my league...

I found out what my big problem was though, the stack only holds 2^21 and I was thinking 2^32. The stack overflows were leading to my looping problems.

The book says I should use a fraction to limit the rand like: state * 143/1125 but this leads to half as many 0's as other numbers.  ???
Using a mod like: state mod 1001 gives the right number of 0's, what's up with that?

I settled on this:
Code: [Select]
'Seed
cond
*.robage 1 =
start
*.xpos *.ypos add 9 div 51 store
stop

'Location Generator
cond
start
*51 211 mult 1663 add 7875 mod 51 store
*51 143 mult 1125 div 52 store
stop

'Value Generator
cond
*52 51 !=
start
*51 211 mult 1663 add 7875 mod 143 mult 1125 div *52 store
stop

@Botsareus I figured a random number generator that was able to change would be better than a static Random gen.  :P
This new one works almost as well as rnd according to my very limited testing, besides the stupid 0's. (Replacing [143 mult 1125 div] with [1001 mod] fixes that)
I thought you would like it because it lets mutations affect more things.

P.S. The stack is so small, I had to reduce my fraction from 1001/7875 to 143/1125  :wacko:
Undisputed creator of bot Sonar!

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Moderator
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
Re: Random Bot
« Reply #4 on: August 06, 2012, 12:01:48 PM »
oh  8)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Re: Random Bot
« Reply #5 on: August 07, 2012, 02:18:29 AM »
Yeah, the stack cap is pretty tough once you start getting in to any sort of numerical algorithms.  You have to get really creative.