Author Topic: Using the vel functions  (Read 1186 times)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7715
    • View Profile
Using the vel functions
« on: March 02, 2005, 03:57:42 AM »
Since I'm the only one who has posted a bot using the new velocity functions, I thought it would be good to give you a walkthrough for how to use them, and use them effectively.

This technique is smoother than using the fixpos method of feeding and allows easier hunting of other moving bots since you'll match their vector, hanging on them like a shadow.  It is a bit more expensive since this way you are paying to stop.  If you could figure out how to combine the two you could gain the benefits of both.

Alright, first of all find the gene where your bot recognizes that there is a bot in the distance and moves towards it.  Depending on how you implement your bot this may vary, but usually people use this kind of command to actually move forward:

*.vel *.maxvel sub .up store

That's fine, but there's a better way!  Replace the above with these two:

Code: [Select]
*.refveldx .dx store
*.refvelup .yourspeed add .up store

Where .yourspeed is a number representing the speed at which you approach a bot.  Note that this speed is relative to the bot you're chasing, so if a bot is flying towards you you might accelerate backward!  Don't let that worry you, Ymir does that and it hasn't hurt him too much.

Okay, you've got your approach gene set up, but what happens when you get close enough to start shooting?  You're going too fast and you'll collide.  If its a veg you'll be playing soccer with it all over the arena, wasting alot of energy in the process.

Add these lines to the gene where you fire at close bots.  Again the exact implementation of your robot may make some changes necessary, but this should give you a good starting point.

Code: [Select]
*.refveldx .dx store
*.refvelup .up store

You're done!

That's all well and good, but what does a finished robot actually look like, Numsgil?  Well, I'll tell you!  I've taken a simplebot (simplebot5) from PY's tutorial (PY, post a link to that tutorial somewhere!) and added the refvel movement so you can see the difference.  Very easy changes to make, but the difference is marked.  Simplebot5 now actually survives in 2.35!  We've cured it of its 'orbitting' problem too, and very easily.  In fact, it can now beat simplebot8.  Not bad for 4 lines of code you can copy and paste.

Code: [Select]
' Simplebot 1
' Gene1. Simple search pattern.
cond
  *.eye3 *.eye5 >
start
  -70 .aimdx store
stop

' Gene2. Simple search pattern part 2
cond
  *.eye7 *.eye5 >
start
  70 .aimdx store
stop

' Gene 3. Move forward
cond
  *.vel 40 <
start
  '40 *.vel sub .up store
  *.refvelup 30 add .up store
  *.refveldx .dx store
stop

' Gene 4. Shoot the food
cond
  *.eye5 40 >
start
  -1 .shoot store
  *.refvelup .up store
  *.refveldx .dx store
stop

' Gene 5. Reproduce
cond
  *.nrg 5000 >
start
  50 .repro store
stop

' Gene 6. Avoid conspecifics
cond
*.refeye 6 =
*.eye5 0 >
start
180 .aimdx store
stop

end

Changes in gene 3 and gene 4.

Don't be afraid of the new commands!  Many have so much possible uses.  They haven't even been touched yet.  Experiment!
« Last Edit: March 02, 2005, 04:05:50 AM by Numsgil »