Welcome To Darwinbots > Newbie
Enemy Recognition.
Moonfisher:
Would be easier to see if you posted all the eye and turning code together, the error might not be in the gene you think it is...
From what I can see the gene should be working correctly... if your focus eye is on a friendly unit the gene won't trigger.
But remember that changing the focus eye won't give you any new input untill next cycle. Any actions you perform in the code won't take effect till the end of the cycle. (But since you change focus eye during the code execution you'll be able to read the new value, the focus eye just hasn't changed yet, and the value in eyef and all the refvars will still be the ones from the old focuseye)
Chlorate:
Hmm, ok here's the whole code.
Apologies for it being really quite inefficient code, it's a work in progress and has a couple of bits that haven't been implemented yet:
--- Code: ---cond
*.robage 0 =
start
3 475 store
def current 101
stop
'2 Eye Position
cond
start
628 .eye3dir store
90 .eye1dir store
-628 .eye7dir store
-90 .eye9dir store
stop
'3 Focus eye position determination: target left
cond
*.eye5 0 =
*.eye1 0 >
*.eye2 0 > or
start
-4 .current store
*.current .focuseye store
stop
'4 eye 1 or 2 is closer
cond
*.current -4 =
*.eye2 *.eye1 >
start
-3 .current store
*.current .focuseye store
stop
'5 target right
cond
*.eye5 0 =
*.eye8 0 >
*.eye9 0 > or
start
4 .current store
*.current .focuseye store
stop
'6 8 or 9 closer
cond
*.current 4 =
*.eye8 *.eye9 >
start
3 .current store
*.current .focuseye store
stop
7 conditional statement
cond
*.eye5 0 =
*.eye1 add *.eye2 *.eye8 add *.eye9 >
start
-4 .current store
else
4 .current store
stop
'8 Turn to face
cond
*.eye5 0 =
*.focuseye 0 !=
*.eye1 *.eye2 add 0 >
*.eye8 *.eye9 add 0 > or
*.refeye *.myeye !=
start
*.focuseye -30 mult .aimsx store
stop
'9 focus on eye5
cond
*.refeye *.myeye !=
*.eye5 0 >
*.eye5 *.eye1 add *.eye2 >
*.eye5 *.eye8 add *.eye9 >
start
0 .aimdx store
0 .current store
*.current .focuseye store
stop
end
--- End code ---
Moonfisher:
I'm not sure you can use def in a gene, I'd sugest having those before the first gene.
Also if you wan't to save energy you can have a robage = 0 gene where you set the eyes and such. (Ofcourse it's safer to set them every cycle if you're up against an oponent that might mess with those settings)
But I think the issue may be that current doesn't exist, so you're never changing the focus eye. (If you select a bot you'll see the focus eye is the one with the red edge)
Also a tip, eyef is like eye5 but for the focus eye, it's a good idea to check that the focus eye contains something before turning.
And you should be aware that view distance isn't huge, and looking at the closest object isn't the same as looking at the most dangerous one. You may often be swithing between the 2 closest alies while an enemy is aproaching and firing. Not saying it can't be effective, but you may want a way to make sure the same eyes aren't checked repeatedly when allies are near.
You're welcome to steal anything you like from this thing (Or maybe switch to this behavior when you keep seing alies) :
[div class=\'codetop\']CODE[div class=\'codemain\' style=\'height:200px;white-space:pre;overflow:auto\']'A system with some practical eyes
'And a test bot (F3) wich shows some of the posibilities.
'The conspec is buildt into the eye system, it just uses
'.dnalen to reconize it's own
'- Variables -
'To apply new eye settings store the value 1 in seteyes
'seteyes will be 0 if not set and 2 if they've been set to something.
def seteyes 50
'When seteyes is 1 the values in seteyespace, setoffset and seteyewidth
'will be applied.
def seteyespace 52
def setoffset 53
def seteyewidth 54
'Eyeuse chooses between changing the focuseye to look,
'or turning the current focus eye to look.
'If you plan on shooting without using .aimshoot and you're using the
'system for turning, then remember to set the focus eye to the one you have centered
'Same goes for using angle and setaim to face the oponent,
'always rememeber to keep track of your focuseye.
'(Unless ofcourse you're never using the system for changing eyefocus)
def eyesystem 55
'- Constants -
'eyedist is used for turning and should be 35 unless something changes in the source.
def eyedist 35 'The eyes default offset
'These are just some values I usualy use, but you can use any values you like.
'They also don't need to be defined as constant, you can just push raw values into the set vars.
def fulleyespace 105 '360 degree spread
def fulloffset 140 'Offset to center eye9
def slimeyewidth -30 'Slimmest eye width
def normaleyewidth 0
def wideeyewidth 80 'Wider eyewidth
'- Vars and const for the test bot
'These are just used in the example to show how the system can be used.
'vars
def state 56
'const
def alge 13
def maxbody 15000
def movebody 6000
'********************************************************************
'------------------------- Init Eyes --------------------------------
'--- Initializing the eyes ---
cond
*.seteyes 0 =
start
1 .seteyes store
.dnalen .memloc store
.fulleyespace .seteyespace store
.fulloffset .setoffset store
.normaleyewidth .seteyewidth store
stop
'********************************************************************
'********************************************************************
'------------------------- Eyes -------------------------------------
'--- Setup ---
cond
*.seteyes 1 =
start
*.setoffset .eye9dir store
*.setoffset *.seteyespace add .eye8dir store
*.setoffset *.seteyespace 2 mult add .eye7dir store
*.setoffset *.seteyespace 3 mult add .eye6dir store
*.setoffset *.seteyespace 4 mult add .eye5dir store
*.setoffset *.seteyespace 5 mult add .eye4dir store
*.setoffset *.seteyespace 6 mult add .eye3dir store
*.setoffset *.seteyespace 7 mult add .eye2dir store
*.setoffset *.seteyespace 8 mult add .eye1dir store
*.seteyewidth .eye1width store
*.seteyewidth .eye2width store
*.seteyewidth .eye3width store
*.seteyewidth .eye4width store
*.seteyewidth .eye5width store
*.seteyewidth .eye6width store
*.seteyewidth .eye7width store
*.seteyewidth .eye8width store
*.seteyewidth .eye9width store
2 .seteyes store
stop
'--- Change focus ---
cond
*.eyesystem 0 =
start
*.eyef 0 =
*.memval *.dnalen = or
501 *.focuseye 5 add 9 mod add * abs sgn 501 *.focuseye 6 add 9 mod add * abs sgn 2 mult | 501 *.focuseye 7 add 9 mod add * abs sgn 4 mult | 501 *.focuseye 8 add 9 mod add * abs sgn 8 mult | 501 *.focuseye 9 add 9 mod add * abs sgn 16 mult | 501 *.focuseye 10 add 9 mod add * abs sgn 32 mult | 501 *.focuseye 11 add 9 mod add * abs sgn 64 mult | 501 *.focuseye 12 add 9 mod add * abs sgn 128 mult | dup dup dup dup dup dup dup dup 1 & 1 sub dup div 1 sub abs *.focuseye 5 add 9 mod 4 sub mult swap 3 & 2 sub dup div 1 sub abs *.focuseye 6 add 9 mod 4 sub mult add swap 7 & 4 sub dup div 1 sub abs *.focuseye 7 add 9 mod 4 sub mult add swap 15 & 8 sub dup div 1 sub abs *.focuseye 8 add 9 mod 4 sub mult add swap 31 & 16 sub dup div 1 sub abs *.focuseye 9 add 9 mod 4 sub mult add swap 63 & 32 sub dup div 1 sub abs *.focuseye 10 add 9 mod 4 sub mult add swap 127 & 64 sub dup div 1 sub abs *.focuseye 11 add 9 mod 4 sub mult add swap 255 & 128 sub dup div 1 sub abs *.focuseye 12 add 9 mod 4 sub mult add swap 511 swap sgn mult store
stop
'--- Turn ---
cond
*.eyesystem 1 =
start
*.eyef 0 =
*.memval *.dnalen = or
501 *.focuseye 5 add 9 mod add * abs sgn 501 *.focuseye 6 add 9 mod add * abs sgn 2 mult | 501 *.focuseye 7 add 9 mod add * abs sgn 4 mult | 501 *.focuseye 8 add 9 mod add * abs sgn 8 mult | 501 *.focuseye 9 add 9 mod add * abs sgn 16 mult | 501 *.focuseye 10 add 9 mod add * abs sgn 32 mult | 501 *.focuseye 11 add 9 mod add * abs sgn 64 mult | 501 *.focuseye 12 add 9 mod add * abs sgn 128 mult | dup dup dup dup dup dup dup dup 1 & 1 sub dup div 1 sub abs *.aim 521 *.focuseye 5 add 9 mod add * add 35 4 mult add mult swap 3 & 2 sub dup div 1 sub abs *.aim 521 *.focuseye 6 add 9 mod add * add 35 3 mult add mult add swap 7 & 4 sub dup div 1 sub abs *.aim 521 *.focuseye 7 add 9 mod add * add 35 2 mult add mult add swap 15 & 8 sub dup div 1 sub abs *.aim 521 *.focuseye 8 add 9 mod add * add 35 1 mult add mult add swap 31 & 16 sub dup div 1 sub abs *.aim 521 *.focuseye 9 add 9 mod add * add 35 0 mult add mult add swap 63 & 32 sub dup div 1 sub abs *.aim 521 *.focuseye 10 add 9 mod add * add 35 1 mult sub mult add swap 127 & 64 sub dup div 1 sub abs *.aim 521 *.focuseye 11 add 9 mod add * add 35 2 mult sub mult add swap 255 & 128 sub dup div 1 sub abs *.aim 521 *.focuseye 12 add 9 mod add * add 35 3 mult sub mult add swap 19 swap sgn mult store
stop
'********************************************************************
'********************************************************************
'************ From here on it's just the test bot *******************
'********************************************************************
start
.fixpos dec
.deltie inc
*.nrg *.body >
*.nrg 500 > and
100 .strbody store
*.nrg 2000 >
*.body *.nrg < and
*.body .maxbody < and
*.nrg 10 mult *.body sub .strbody store
*.robage 50 >
1 .seteyes store
.wideeyewidth .seteyewidth store
stop
'- Scout -
cond
*.state 0 =
start
*.eyesystem 0 !=
0 .eyesystem store
*.eyef 0 =
*.memval *.dnalen = or
*.maxvel .up store
*.robage 5 <
*.body 1100 > and
*.maxvel - .up store
*.eyef 0 !=
*.memval .alge != and
*.memval *.dnalen != and
*.refvelsx 100 mult .dx store
*.refveldn 100 mult .up store
*.eyef 0 !=
*.memval .alge = and
1 .state store
*.eyef 0 =
*.memval *.dnalen = or
*.shflav 0 = and
*.nrg 20000 > and
*.body 3000 > and
2 .state store
*.eyef 0 !=
*.memval *.dnalen != and
*.body *.refbody 200 sub > and
3 .state store
*.body .movebody >
4 .state store
*.totalmyspecies 2 < and
*.nrg 10000 > and
*.eyef 0 = and
2 .state store
stop
cond
*.state 1 =
start
*.eyesystem 1 !=
1 .eyesystem store
4 .focuseye store
*.eyef 0 !=
*.memval .alge = and
*.refxpos *.refypos angle .setaim store
*.refvelsx *.veldx add .sx store
*.refvelup 100 *.eyef sub add 10 floor .up store
-6 .shoot store
16 .shootval store
*.eyef 0 =
*.memval .alge != or
0 .state store
stop
cond
*.state 2 =
start
*.eyef 0 =
*.memval *.dnalen = or
*.shflav 0 = and
*.nrg 20000 > and
*.body 3000 > and
*.aim 314 add .setaim store
20 .repro store
not
3 .state store
stop
cond
*.state 3 =
start
*.eyesystem 1 !=
1 .eyesystem store
4 .focuseye store
*.eyef 0 !=
*.memval *.dnalen != and
*.refxpos *.refypos angle .setaim store
*.refvelsx *.veldx add .sx store
*.refxpos *.xpos sub abs *.refypos *.ypos sub abs pyth 5 div 30 sub 0 floor 100 ceil *.refvelup add .up store
*.nrg 100 div *.refnrg ceil 25 floor .shootval store
-6 .shoot store
*.shflav 0 !=
*.shang .aimshoot store
-6 .shoot store
40 .shootval store
0 .shflav store
*.eyef 0 =
*.memval *.dnalen = or
0 .state store
*.body .movebody >
4 .state store
stop
cond
*.state 4 =
start
*.eyesystem 1 !=
1 .eyesystem store
4 .focuseye store
1 .seteyes store
.wideeyewidth .seteyewidth store
*.eyef 0 !=
*.memval *.dnalen != and
*.refxpos *.refypos angle .setaim store
-6 .shoot store
*.memval .alge != and
*.nrg 100 div *.refnrg ceil 25 floor .shootval store
*.refxpos *.refypos dist 600 >
*.memval .alge = and
*.shflav 0 = and
-10 .shootval store
*.timer 15 mod 0 =
*.memval .alge = and
150 .aimsx store
*.shflav 0 !=
*.shang .aimshoot store
-6 .shoot store
40 .shootval store
0 .shflav store
*.eyef 0 =
*.memval *.dnalen = or
0 .state store
*.eyef 0 =
*.memval *.dnalen = or
*.memval .alge = or
*.body .movebody < and
0 .state store
*.eyef 0 =
*.memval *.dnalen = or
*.memval .alge = or
*.body .maxbody > and
4 .state store
stop
end
The first 2 genes are for initializing the eyes, the next 2 are 2 different ways of using the eyes, one turns to the next non empty eye, while the other one just changes the focus eye. (Those 2 genes are hard to read, I can post a broken down version, but it'll still be kinda hard to read it) But the point is that you don't need to understand them to use them, you just change the defined values at the beginning of the code.
After that the remaining genes are just a test bot to show how you can use the eye genes.
You can also change the overall eye setup if you like, but be aware that the turning gene won't work without the current eye setup (You can change the width and distance between the eyes by using the defined values, but not scramble it any way you like), however the focus eye switching gene should work no matter how you set the eyes.
Chlorate:
I checked that the variable "current" exists by looking it up on the bot's memory, and yes the little red edge marker does move to the relevant eye when something is in its field of view. I built the code up gene by gene testing that they were working ok.
Thanks for the help though, I'll probably have a look at that one sometime. Currently fiddling with something else for the time being.
Moonfisher:
Didn't seem to work properly when I ran it, you should try advancing one cycle at the time in the sim to see the result.
From what I can see, if I place a friendly bot in the left or right eye it will turn before switching the focus eye, and after turning it switches the focus eye...
So you're one cycle behind, my first suspition seems to have been the right one:
--- Quote ---But remember that changing the focus eye won't give you any new input untill next cycle. Any actions you perform in the code won't take effect till the end of the cycle. (But since you change focus eye during the code execution you'll be able to read the new value, the focus eye just hasn't changed yet, and the value in eyef and all the refvars will still be the ones from the old focuseye)
--- End quote ---
You turn before the focus eye has changed.
When your code is executed the only thing that happens is you're setting some values in some sysvars, you don't shoot, turn or anything (Including changing the focuseye).
Then once the end of the code is reached the values are read and the corresponding commands are executed. (Can't remember the order, but I think the important ones go : turn, shoot, tie (Can't remember when movement is done though))
So the fix is easy, just place the turning gene before the genes that manipulate focuseye.
I'd recomend doing something a litle easier though :
(This also seems to have the advantage of turning to the position where the target will be next cycle, not sure why, but it makes everything a lot easier (Maybe that's why ))
[div class=\'codetop\']CODE[div class=\'codemain\' style=\'height:200px;white-space:pre;overflow:auto\']
'Since eye5 is 0 it's enough to make sure eyef isn't and you'll know the focus eye isn't eye5 (No matter what it says in the .focuseye sysvar)
cond
*.eye5 0 =
*.eyef 0 >
*.refeye *.myeye !=
start
*.refxpos *.refypos angle .setaim store
0 .focuseye store
stop
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version