Bots and Simulations > DNA - General
Find the error: For all who like complicated code
Welwordion:
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: ---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
--- End code ---
Numsgil:
You just blew my mind sir
Endy:
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.
Welwordion:
The following was false:
--- Code: ---'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
--- End code ---
just replace it with
--- Code: ---5 sub 35 mult .aimdx store
--- End code ---
oh and if you want an easier and probably more reliabile version of the gene:
--- Code: ---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
--- End code ---
Elite:
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)?
Navigation
[0] Message Index
[#] Next page
Go to full version