Author Topic: Find the error: For all who like complicated code  (Read 4135 times)

Offline Welwordion

  • Bot Destroyer
  • ***
  • Posts: 325
    • View Profile
Find the error: For all who like complicated code
« on: April 17, 2006, 08:11:03 PM »
Tried to make a new search gene that aims at the nearest  bot unfortunately the robot does not rotate, so where is the error?
Code: [Select]
cond
start

'compare the numbers and leave the highest on stack , mark from which eye it came by adding 1000*eyenumber
'repeat the progress until you reached eye9

*.eye1 1000 add dup 1000 mod *.eye2 sub 0 floor sgn mult dup sgn 1 sub abs 2000 *.eye2 add mult add
dup 1000 mod *.eye3 sub 0 floor sgn mult dup sgn 1 sub abs 3000 *.eye3 add mult add
dup 1000 mod *.eye4 sub 0 floor sgn mult dup sgn 1 sub abs 4000 *.eye4 add mult add
dup 1000 mod *.eye5 sub 0 floor sgn mult dup sgn 1 sub abs 5000 *.eye5 add mult add
dup 1000 mod *.eye6 sub 0 ceil sgn 1 add mult dup sgn 1 sub abs 6000 *.eye6 add mult add
dup 1000 mod *.eye7 sub 0 ceil sgn 1 add mult dup sgn 1 sub abs 7000 *.eye7 add mult add
dup 1000 mod *.eye8 sub 0 ceil sgn 1 add mult dup sgn 1 sub abs 8000 *.eye8 add mult add
dup 1000 mod *.eye9 sub 0 ceil sgn 1 add mult dup sgn 1 sub abs 9000 *.eye9 add mult add
dup 1000 mod sub 1000 div


'Test from which location the number came and insert the right rotation/aimdx value

dup 1 sub abs sgn 1 sub abs -140 mult  
dup 2 sub abs sgn 1 sub abs -105 mult add
dup 3 sub abs sgn 1 sub abs -70 mult add
dup 4 sub abs sgn 1 sub abs -35 mult add
dup 6 sub abs sgn 1 sub abs 35 mult add
dup 7 sub abs sgn 1 sub abs 70 mult add
dup 8 sub abs sgn 1 sub abs 105 mult add
9 sub abs sgn 1 sub abs 140 mult add
aimdx. store
stop
« Last Edit: April 17, 2006, 08:12:24 PM by Welwordion »

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Find the error: For all who like complicated code
« Reply #1 on: April 17, 2006, 08:47:28 PM »
You just blew my mind sir

Offline Endy

  • Bot Overlord
  • ****
  • Posts: 852
    • View Profile
Find the error: For all who like complicated code
« Reply #2 on: April 17, 2006, 11:56:07 PM »
I'm guessing you're trying to have the bot's turn based entirely on which eye has the greatest value out of the entire series of eyes. If working the bot would immediatly turn to the closest object everytime.

I've been trying to do something similar off and on for awhile now. The best I've come up with is subtracting on group of eyes at a time from the other. Using this method you can gradually home in on the highest value...theorectically at least. Had problems with eyes being equal, not sure if your code could have similar problems but it's probably worth a look.

Offline Welwordion

  • Bot Destroyer
  • ***
  • Posts: 325
    • View Profile
Find the error: For all who like complicated code
« Reply #3 on: April 18, 2006, 07:57:56 AM »
The following was false:
Code: [Select]
'Test from which location the number came and insert the right rotation/aimdx value

dup 1 sub abs sgn 1 sub abs -140 mult  
dup 2 sub abs sgn 1 sub abs -105 mult add
dup 3 sub abs sgn 1 sub abs -70 mult add
dup 4 sub abs sgn 1 sub abs -35 mult add
dup 6 sub abs sgn 1 sub abs 35 mult add
dup 7 sub abs sgn 1 sub abs 70 mult add
dup 8 sub abs sgn 1 sub abs 105 mult add
9 sub abs sgn 1 sub abs 140 mult add
aimdx. store
stop
just replace it with
Code: [Select]
5 sub 35 mult .aimdx store
oh and if you want an easier and probably more reliabile version of the gene:
Code: [Select]
cond
start
*.eye1 dup *.eye2 sub abs add *.eye2 add 2 div
dup *.eye3 sub abs add *.eye3 add 2 div
dup *.eye4 sub abs add *.eye4 add 2 div
dup *.eye5 sub abs add *.eye5 add 2 div
dup *.eye6 sub abs add *.eye6 add 2 div
dup *.eye7 sub abs add *.eye7 add 2 div
dup *.eye8 sub abs add *.eye8 add 2 div
dup *.eye9 sub abs add *.eye9 add 2 div

dup dup *.eye5 sub sgn 1 sub abs 5 mult add
dup *.eye6 sub sgn 1 sub abs 6 mult add
dup *.eye4 sub sgn 1 sub abs 4 mult add
dup *.eye7 sub sgn 1 sub abs 7 mult add
dup *.eye3 sub sgn 1 sub abs 3 mult add
dup *.eye6 sub sgn 1 sub abs 8 mult add
dup *.eye2 sub sgn 1 sub abs 2 mult add
dup *.eye9 sub sgn 1 sub abs 9 mult add
dup *.eye1 sub sgn 1 sub abs 1 mult add
sub abs

5 sub 35 mult .aimdx store
stop

Offline Elite

  • Bot Overlord
  • ****
  • Posts: 532
    • View Profile
Find the error: For all who like complicated code
« Reply #4 on: April 18, 2006, 11:40:53 AM »
Wow   That's one nice gene  
Kudos Welwordion

You might want to add this code before the store:

*.eye1 *.eye2 *.eye3 *.eye4 *.eye5 *.eye6 *.eye7 *.eye8 *.eye9 add add add add add add add add sgn mult

so it becomes:

5 sub 35 mult .aimdx *.eye1 *.eye2 *.eye3 *.eye4 *.eye5 *.eye6 *.eye7 *.eye8 *.eye9 add add add add add add add add sgn mult store

then you don't waste energy when there's nothing in view

You might want to add this code too:

*.refxpos *.refypos angle .setaim *.eye5 sgn mult store

to further increase the accuracy

Hey Endy, how about SGifying DIN, updating it, and replacing the old looking genes with this one (since the only thing stopping the SGification of DIN is the turning genes)?
« Last Edit: April 18, 2006, 11:41:29 AM by Elite »

Offline Welwordion

  • Bot Destroyer
  • ***
  • Posts: 325
    • View Profile
Find the error: For all who like complicated code
« Reply #5 on: April 18, 2006, 12:53:45 PM »
Heh, Elite you can read my mind I just wanted to post that the accuracy needs improvement and I also tried to improve it with a "*.refxpos *.refypos angle .setaim" code.
Also I thought about a when zero do not store code like you posted , but said to myself: Wait until 2.5 when storing in 0 does not cost anything anymore again.

Note: ensure that .aimdx is deactivated when you use setaim I think they interfere to some degree.

Hmm another question  has anyone succeeded in writing a gene that lets you aim in the direction you are shoot from? Somehow it starts rotating when I try to implement that.
« Last Edit: April 18, 2006, 01:35:19 PM by Welwordion »