Darwinbots Forum
Bots and Simulations => DNA - General => Topic started by: MysticalDumpling on May 01, 2014, 03:52:04 PM
-
Alas, sin-1 does not seem to be a valid operator according to the wiki. Does anyone know how to in DB?
-
Well, after a long time trawling through calculus functions and really, really technical documents, 2 broken pencils and several smudged sheets of looseleaf, I then discovered on Khan Academy than arcsin(x) = x + (x^3)/6. Then, I wasted even more looseleaf getting a "proper" DB function down. I used previously wrangled trig equations to fid a pair of variables- the distance of the end target (c) and the angle needed to turn (capital b ).
c:
*.refxpos *.refypos dist sqr *.refvelscalr sqr add 2 *.refxpos *.refypos dist mult *.refvelscalr mult sub *.refaim cos
B
Now, I used c for short for the eq. above
*.refaim sin *.refvelscalar mult c div *.refaim sin *.refvelscalar mult c div 3 pow 6 div add
Full B:
*.refaim sin *.refvelscalar mult ]*.refxpos *.refypos dist sqr *.refvelscalr sqr add 2 *.refxpos *.refypos dist mult *.refvelscalr mult sub *.refaim cos div *.refaim sin *.refvelscalar mult *.refxpos *.refypos dist sqr *.refvelscalr sqr add 2 *.refxpos *.refypos dist mult *.refvelscalr mult sub *.refaim cos div 3 pow 6 div add
Now, I need to use my lengthy shot-dist calculating gene, a as-of-yet unknown shot velocity and a factor to account for maximum shot distance based on bot size, stick it together for an excessively long functio that most likely will have more bugs than a beehive.
-
Then again, this was fun in a masochistic way :happy:
-
[bump]
Now, I am working on trying to find shot-distance-based-on-bot-size-and-logx snippet.
This means trawling through VB. I know very little about VB, except it's fundamental basics. Woohoo.
-
Found this snippet
If rob(n).vbody > 10 Then
Shots(a).nrg = Log(Abs(rob(n).vbody)) * 60 * rngmultiplier
Dim temp As Long
temp = (Shots(a).nrg + 40 + 1) \ 40 'divides and rounds up
Shots(a).Range = temp
So, base shot range is the log of body, timess 60, times "nrgmultiplier", which I assume is .shootval
Also, it seems that shot velocity is 40
Now, to figger out a cohesive code line
If this works, it will be so badass....
-
I got a seemingly very effective calculator for shootval for a seen distance:
*.body 2 logx 60 mult *.refxpos *.refypos dist sqr *.refvelscalar sqr add 2 *.refxpos *.refypos dist mult *.refvelscalar mult sub *.refaim cos sub abs 2 logx -1 mult .shootval store
When I tried to use one to predict shootangle, it is 90deg. off to the right. It goes:
*.refaim sin *.refvelscalar mult *.refxpos *.refypos dist sqr *.refvelscalar sqr add 2 *.refxpos *.refypos dist mult *.refvelscalar mult sub *.refaim cos div *.refaim sin *.refvelscalar mult *.refxpos *.refypos dist sqr *.refvelscalar sqr add 2 *.refxpos *.refypos dist mult *.refvelscalar mult sub *.refaim cos div 3 pow 6 div add *.aim sub .aimshoot store
Neither of these have shot velocity factored in.
-
Alas, pre-emptive aiming and shooting eludes me. Some of my notes in a txt file might help someone open up this vault of secrets
updated .txt
-
I now have the "working" base for the pre-emtive aim:
start
-40 *.eye9 sgn mult -30 *.eye8 sgn mult add -20 *.eye7 sgn mult add -10 *.eye6 sgn mult add 10 *.eye4 sgn mult add 20 *.eye3 sgn mult add 30 *.eye2 sgn mult add 40 *.eye1 sgn mult add .aimsx store
*.refaim sin *.refvelscalar mult *.refxpos *.refypos dist sqr *.refvelscalar sqr add 2 *.refxpos *.refypos dist mult *.refvelscalar mult sub *.refaim cos div *.refaim sin *.refvelscalar mult *.refxpos *.refypos dist sqr *.refvelscalar sqr add 2 *.refxpos *.refypos dist mult *.refvelscalar mult sub *.refaim cos div 3 pow 6 div add
.aimsx store
stop
However (as noted in the txt), there are some issues:
'The aiming kinda works- it shoots ahead of the bot. However, depending on how "late" in the cycle (?)
'or something like that, it does not hit. Not taking into account shot velocity causes problems as well.
'Another problem is that it overturns with large distances.
This might mean there is some problem in the math. Helpings?
-
I just realized I was spamming the thread. Sorry :wub:
Anyway, I think I realized my prob.- I used *.refaim, which is absolute aim. Instead, I should find the dir, convert it to deg (if is that necissary?), based on my bot's frame of reference.
I added *.aim sub to the end of every *.refaim. Now, it works a little better. However, sometimes it works, then it "randomly" rotates WAAAAY too far. Well, I'm getting somewhere... :dry:
-
i can't help but notice that the equation doesn't factor in the vel of any bot as far as i can tell. this could help.
-
cond
start
*.xpos 33 cos add *.ypos 33 sin sub angle debugint
stop
end
PwaPwaPwaPwaaaaown :P
edit:
Private Sub Form_Load()
Dim ang As Double
ang = 1.1
'MsgBox Sin(ang) & " " & Cos(ang)
'MsgBox (Sin(ang) ^ 2 + Cos(ang) ^ 2) ^ 0.5
'MsgBox Sin(ang) & " " & (1 - Cos(ang) ^ 2) ^ 0.5
'MsgBox Atn(Sin(ang) / ((1 - Sin(ang) ^ 2) ^ 0.5))
mysin = Sin(ang)
'MsgBox Atn(Sin(ang) / ((1 - Sin(ang) ^ 2) ^ 0.5))
yo = 0.5
MsgBox Atn(yo / ((1 - yo ^ 2) ^ 0.5))
End Sub
-
i can't help but notice that the equation doesn't factor in the vel of any bot as far as i can tell. this could help.
I know. I made a new formula. And *.refvelscalar is sprinkled through both equations.
-
My new formula in DB
If Nums is right an arccos ~= 1, then
1600 *.refxpos *.refypos angle mult 2 pow *.refvelscalar 2 pow add *.refxpos *.refypos angle *.refvelscalar mult 2 mult *.refaim *.aim sub cos mult 40 *.refvelscalar mult div 2 pow *.refxpos *.refypos angle 2 pow add 1600 *.refxpos *.refypos angle mult 2 pow *.refvelscalar 2 pow add *.refxpos *.refypos angle *.refvelscalar mult 2 mult *.refaim *.aim sub cos mult 40 *.refvelscalar mult div*.refvelscalar mult 2 pow 80 ]1600 *.refxpos *.refypos angle mult 2 pow *.refvelscalar 2 pow add *.refxpos *.refypos angle *.refvelscalar mult 2 mult *.refaim *.aim sub cos mult 40 *.refvelscalar mult div 2 pow mult 2 *.refxpos *.refypos angle mult mult div
Otherwise, it has to be
22 14 div 1600 *.refxpos *.refypos angle mult 2 pow *.refvelscalar 2 pow add *.refxpos *.refypos angle *.refvelscalar mult 2 mult *.refaim *.aim sub cos mult 40 *.refvelscalar mult div 2 pow *.refxpos *.refypos angle 2 pow add 1600 *.refxpos *.refypos angle mult 2 pow *.refvelscalar 2 pow add *.refxpos *.refypos angle *.refvelscalar mult 2 mult *.refaim *.aim sub cos mult 40 *.refvelscalar mult div*.refvelscalar mult 2 pow 80 ]1600 *.refxpos *.refypos angle mult 2 pow *.refvelscalar 2 pow add *.refxpos *.refypos angle *.refvelscalar mult 2 mult *.refaim *.aim sub cos mult 40 *.refvelscalar mult div 2 pow mult 2 *.refxpos *.refypos angle mult mult div sub 1600 *.refxpos *.refypos angle mult 2 pow *.refvelscalar 2 pow add *.refxpos *.refypos angle *.refvelscalar mult 2 mult *.refaim *.aim sub cos mult 40 *.refvelscalar mult div 2 pow *.refxpos *.refypos angle 2 pow add 1600 *.refxpos *.refypos angle mult 2 pow *.refvelscalar 2 pow add *.refxpos *.refypos angle *.refvelscalar mult 2 mult *.refaim *.aim sub cos mult 40 *.refvelscalar mult div*.refvelscalar mult 2 pow 80 ]1600 *.refxpos *.refypos angle mult 2 pow *.refvelscalar 2 pow add *.refxpos *.refypos angle *.refvelscalar mult 2 mult *.refaim *.aim sub cos mult 40 *.refvelscalar mult div 2 pow mult 2 *.refxpos *.refypos angle mult mult div 3 pow 6 div sub
Acck. I hate reverse polish with equations like this. I probably misplaced something imp. :wacko:
Now, how to use the darn thing....
vector math sounds like a good idea.
-
While I was typing that post, a conversation happened in real time. I have never seen anything like it before...
-
it happens :P
-
ok fine, in plain English:
Use the following to get sin-1 instead of approximating it:
cond
start
33 999 store
*.xpos 1 999 * 2 pow sub 2 root add *.ypos 999 * sub angle
stop
end
There is ways to fix the above to not use a variable.
You will also have to multiply everything into integer range.
-
And.... my equation worked for 3 cycles- it did an ahead shot and everything... then it swang around randomly. *sigh* Such is life.
Bit too late, Bots. I need arccos. :P Thanks though
-
Ok, then simply use.
cond
start
33 999 store
*.xpos 999 * add *.ypos 1 999 * 2 pow sub 2 root sub angle
stop
end
-
Ok
-
Something like that anyway. I did not review my work other then the vb portion and my original post. Maybe I'll have time later to properly fix it up. :P
-
On further review, I can see why you may want to approximate it using different methods because I am overflowing at 1024000000 if you try to fix my formula. :P
-
Dumpling, what are you trying to accomplish anyway?
-
Nm, actually took the time to read your code.