Bots and Simulations > DNA - General
shootval and distance for -1 shots
peterb:
I'm trying to figure out a formula for shootval so that the bullets are shot with the right distance.
But on the wiki sysvars i dont read how it behaves.
Here on the forums i read some words about log2(distance) ??
However log2 is not an operator in DarwinBots , what might come close to it is bit operation >> ???
So far i failed to write a good formula and searched the forums and wiki, and the beastairy.
Has someone already solved it. ??
How to perfectly shoot at something with the right distance.
Also i think .mass impacts a shot distance ??, but 'm not sure but bot size and shotlength dont seam to compare
I can figure out how to get the distance and angle with :
*.refxpos *.refypos dist .edist store
*.refxpos *.refypos angle .setaim store
-1 .shoot store
But now how to shoot exactly to it ? (or with a margin : *.edist 10 add .edist store)
ashton15:
Ok, i worked on this for a little bit, scraped edist as it's a waste of energy and used unconditional logic also for effciency, basically if something is just past the range of the bot or equal to it doubles the value of .shootval starting at -2 (it is possible to store 0) it shots at things which are up to five times the distance of a base shot length though I don't know what that is... anyways hope this helps
def XXX 100
'XXX = how far a shot goes at shootval 0, you will have to work this out yourself
start
*.eyef 0 !=
*.refxpos *.refypos angle .setaim store
-2 *.refxpos *.refypos dist *.XXX sub abs sub sgn ++ sgn mult
-2 *.refxpos *.refypos dist *.XXX 2 mult sub abs sub sgn ++ sgn mult add
-4 *.refxpos *.refypos dist *.XXX 3 mult sub abs sub sgn ++ sgn mult add
-8 *.refxpos *.refypos dist *.XXX 4 mult sub abs sub sgn ++ sgn mult add
-16 *.refxpos *.refypos dist *.XXX 5 mult sub abs sub sgn ++ sgn mult add
.shootval store
'btw -32 is the lowest which can be stored in shootval
.shoot dec
stop
peterb:
--- Quote from: ashton15 ---Ok, i worked on this for a little bit, scraped edist as it's a waste of energy and used unconditional logic also for effciency, basically if something is just past the range of the bot or equal to it doubles the value of .shootval starting at -2 (it is possible to store 0) it shots at things which are up to five times the distance of a base shot length though I don't know what that is... anyways hope this helps
def XXX 100
'XXX = how far a shot goes at shootval 0, you will have to work this out yourself
start
*.eyef 0 !=
*.refxpos *.refypos angle .setaim store
-2 *.refxpos *.refypos dist *.XXX sub abs sub sgn ++ sgn mult
-2 *.refxpos *.refypos dist *.XXX 2 mult sub abs sub sgn ++ sgn mult add
-4 *.refxpos *.refypos dist *.XXX 3 mult sub abs sub sgn ++ sgn mult add
-8 *.refxpos *.refypos dist *.XXX 4 mult sub abs sub sgn ++ sgn mult add
-16 *.refxpos *.refypos dist *.XXX 5 mult sub abs sub sgn ++ sgn mult add
.shootval store
'btw -32 is the lowest which can be stored in shootval
.shoot dec
stop
--- End quote ---
doesnt seam to do the trick,
I created a simple test bot, used some test valeus for xxx
And tried to feed it some vegie in front to see when it starts shooting at the vegie
You used a lot of complex code in the math can you clarify it simply is it a if x > then rule ?
hmm myabe directly edit a veggie to investigate how shootval works
'test
def etarget 60
def edist 61
def XXX 100
cond
*.eye5 0 >
start
*.refxpos *.refypos dist .edist store
*.refxpos *.refypos angle .setaim store
'positive longer
'negative smaller
'XXX = how far a shot goes at shootval 0, you will have to work this out yourself
1 .xxx store
-2 *.refxpos *.refypos dist *.XXX sub abs sub sgn ++ sgn mult
-2 *.refxpos *.refypos dist *.XXX 2 mult sub abs sub sgn ++ sgn mult add
-4 *.refxpos *.refypos dist *.XXX 3 mult sub abs sub sgn ++ sgn mult add
-8 *.refxpos *.refypos dist *.XXX 4 mult sub abs sub sgn ++ sgn mult add
-16 *.refxpos *.refypos dist *.XXX 5 mult sub abs sub sgn ++ sgn mult add
.shootval store
'btw -32 is the lowest which can be stored in shootval
.shoot dec
stop
ashton15:
Just realized I was a bit silly... rather than doing
sub sgn ++
(which returns 1 if the two past values are >= to each other and 0 if they aren't) I wrote
sub abs sub sgn ++
However that still doesn't cure the problem (it does however remove another one from apearing), I tried this code which didn't seem to store any values (?) but still shoot a far range. That's annoying as I can't check to see wether this is working or not.
*.refxpos *.refypos dist *.XXX >= -2 .shootval store
*.refxpos *.refypos dist *.XXX 2 mult >= -4 .shootval store
*.refxpos *.refypos dist *.XXX 3 mult >= -8 .shootval store
*.refxpos *.refypos dist *.XXX 4 mult >= -16 .shootval store
*.refxpos *.refypos dist *.XXX 5 mult >= -32 .shootval store
also I checked the locations by putting
-2 *.refxpos *.refypos dist *.XXX sub sgn ++ sgn mult .101 store
and
*.refxpos *.refypos dist *.XXX >= -2 .shootval store .101 store
no values were stored again... I'm really confudled by this one... I checked over the code multiple times and don't understand why it won't work... are you sure *.refxpos *.refypos dist works?
P.S. I think I've worked on this to long...
peterb:
--- Quote from: ashton15 ---Just realized I was a bit silly... rather than doing
sub sgn ++
(which returns 1 if the two past values are >= to each other and 0 if they aren't) I wrote
sub abs sub sgn ++
However that still doesn't cure the problem (it does however remove another one from apearing), I tried this code which didn't seem to store any values (?) but still shoot a far range. That's annoying as I can't check to see wether this is working or not.
*.refxpos *.refypos dist *.XXX >= -2 .shootval store
*.refxpos *.refypos dist *.XXX 2 mult >= -4 .shootval store
*.refxpos *.refypos dist *.XXX 3 mult >= -8 .shootval store
*.refxpos *.refypos dist *.XXX 4 mult >= -16 .shootval store
*.refxpos *.refypos dist *.XXX 5 mult >= -32 .shootval store
also I checked the locations by putting
-2 *.refxpos *.refypos dist *.XXX sub sgn ++ sgn mult .101 store
and
*.refxpos *.refypos dist *.XXX >= -2 .shootval store .101 store
no values were stored again... I'm really confudled by this one... I checked over the code multiple times and don't understand why it won't work... are you sure *.refxpos *.refypos dist works?
P.S. I think I've worked on this to long...
--- End quote ---
Hmmm i think your close to something... i have also not figured it out yet.
the problem of distance and strange valeus for it..
And check against it and then to set valeu to (32 /16 /8 /4 /2 ....-2 -8 -16)...
Maybe something based on this : ?
-6000 + distanse add 0 floor sgn 32 mult store .shootval store
i'm not sure because it got to work against multiple distances and multiple valeus
Maybe each line that passes ok sould add or substract to something until you reach 24 /16/.../.../... etc.
A nice thing of it is that short shots (when you bump into someone) become more powerfull.
The long shots cost more, but on the otherside sometimes you can hun a faster bot that way.
Also the both grows its shooting range changes.. hmm maybe 6000 + or mult a factor ? the factor is not that clear to me.. its inside shots.bas in the code, but its strange looking.
I wonder why shootval works that complex, why has it been made to such a complexity level
Navigation
[0] Message Index
[#] Next page
Go to full version