souvik1997 wrote:
KermMartian wrote:
souvik1997 wrote:
Progress?
Haven't had an ounce of free time, I'm afraid. Sad Other than that, though, I'm hoping Sunday and Monday I'll have time to work on this and Obliterate. Feel free to nag me (all of you) so I do so!

Nag. Very Happy
I shall consider myself properly nagged. In the meantime, anyone want to check my equations?

> Given: fixed (x1,y1)
> Given: fixed (x2,y2)
> Given: theta

For v0, such that v0x = v0*cos(theta) and v0y = v0*sin(theta):

Q = [(cos(theta))^2]/[(x2-x1)^2]
R = a/2
S = (y2-y1) - (x2 - x1)*[sin(theta)/cos(theta)]

v0 = QR/S
err, this is off topic and noobish, but

1. what type of math is that?
2. what grade do you learn that in? Shock my brain hurts from looking at it.
It looks like vector math.
It's one solution to the parabolic motion equations in 2D expressed as Cartesian coordinate pairs.
KermMartian wrote:
I shall consider myself properly nagged. In the meantime, anyone want to check my equations?

> Given: fixed (x1,y1)
> Given: fixed (x2,y2)
> Given: theta

For v0, such that v0x = v0*cos(theta) and v0y = v0*sin(theta):

Q = [(cos(theta))^2]/[(x2-x1)^2]
R = a/2
S = (y2-y1) - (x2 - x1)*[sin(theta)/cos(theta)]

v0 = QR/S


Can we get some sub-scripting for Cemetech? Also, before I check, are all the terms properly grouped for S?
We have it, I just don't like using it for some reason. And yes, that multiplication is only for the latter term of S.
I got, probably through a different method:

x = x2 - x1
y = y1 - y2

V0 = sqrt(-(sqrt(((x/cos(t))^2)((sin(t)^2)+2gy))-xtan(t))/(2gy)))

Visualized: C and P the whole link; Kerm's BBcode fails.
http://www.wolframalpha.com/input/?i=sqrt(-(sqrt(((x/cos(t))^2)((sin(t)^2)%2B2ay))-xtan(t))/(2ay))
Add it to the BBCode buttons list you silly thing! And I started to check it, but remembered I need to finish 2 papers tonight...
Pseudo: don't forget that I'm working in z80 ASM. I have a sine and cosine lookup table of low-ish precision for theta=0 through theta=180, but square room, tangent, etc are expensive. Mine also has a sqrt, unfortunately, although I originally omitted it. I edited my post above accordingly. I'm not sure why you have so many square roots...
I used:
0 = -.5at^2 + VyT + (y2-y1)
and quad formula'd it to find the amount of time T it would be in the air which is
(V0sin(t) + sqrt((V0sin(t))^2 + 2a(y2-y1)))/a

then I find the amount of time T it would need to be in the air to travel the X distance (which is V0cos(t) )
so:

t=(x2-x1)/(V0cos(t))

set the two equations equal to each other and solve for V0.
That was my original approach as well, but I didn't like the square root that that required. Unfortunately, it then turned out I would need a square root anyway.
How did you arrive at your solution?
Pseudoprogrammer wrote:
How did you arrive at your solution?
I started with x2 = x1 + v0x*t = x1 + (v0*cos(theta))*t, used y2 = y1 + (v0*sin(theta))*t + 0.5*a*t^2, solved the first equation for t, and plugged it in as t in the second equation.
Methinks we need "The (Other) Vector Thread" to stop diverting this one Razz
I solved the equations again using a different method and I got:

sqrt((y1 + tan(t)(x2-x1) + .5a((x2-x1)^2))/(y2cos(t)))

Not sure if they're equivalent.
Doesn't seem to be equivalent. I don't think that that equation is correct; if y2 = 0, then you get division by zero, and not every equation with a final y-coordinate of zero is unsolvable...
Hmmm, here's the latest thing I came up with.


Code:
Gameplay_AITurn_Aim:
   ; 1. Pick an alive tank
   ; 1a. Set deltaX, deltaY
   ; 2. Loop Theta 0 to 180, step 2*(6-Difficulty)
   ; 2a. calculate Q = a/2 * deltaX
   ; 2b. calculate R = deltaY * cos(theta)
   ; 2c. calculate R = sin(theta)-R/deltaX
   ; 2d. calculate R = Rcos(theta)
   ; 2e. calculate v0 = sqrt(Q/R)
   ; 2f. if 0 < v0 <= 100, fire!


1a. deltaX, deltaY are 16-bit words
2. theta is a 8-bit byte
2a. a/2 is a byte. deltaX is a 16-bit word, so Q is a 16-bit word (well, 24-bit, but it turns out a/2 = 2/2 = 1)
2b. cos(theta) is a nine-bit sign-prepended byte. deltaY is a 16-bit word. R is potentially a 25-bit (?!) word.
2c. R is, say, 24 bits (dearie me), deltaX is 16 bits, so it pains me to realize that the new R could also be 24 bits
2d. R is now 24 bits, cos(theta) is 9 bits, so the new R could be 33 FREAKING BITS
2e. Q is 16b, R is 33b, Q/R is OH GOD SAVE ME

HEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEELP
Edit: Split, by the way.
I can't understand the fine specifics here, but I wouldn't call this AI until each tank can assess a situation.
  • Which tank poses a greater threat (closer tank first then most accurate tank targeting it as the game progresses)
  • Tank knows how far off it was from an enemy tank and adjusts next turn accordingly
This is likely for version two, if anything. From what I understood above the AI chooses a tank at random and random settings each turn.

The tanks are on a master graph. Tank A at -30pxls away from the origin, Tank B at +10. Then, each Tank is at the origin of it's own graph. When Tank B fires short of Tank A the value would be, say, 13. If it overshot the value would be -6.

If it was short, it'd either adjust the power up or the angle down. Even Power up*2 and angle up.

Only problem is that you'd have to store values for each tank. So you'd have n-1 lists of n elements denoting accuracy on individual tanks. (-1 for a human player). But, each tank would only have access to it's own list to prevent each tank from targeting the one tank until it's dead then moving on to the next most accurate.

I don't expect that last paragraph to make much sense to anyone else and it probably won't for me in a day. But, how exactly does the AI work in English?
You vastly overestimate how easy manipulation of all this math is in z80 assembly. Smile I'm already suffering enough with a targetting AI; I don't feel like complicating it any more at this point. You've presented a good system, though, and one that would make sense if in the future I have more patience. At this point I'm mostly interested in getting a decent AI working, publishing a beta, and starting Direct USB gCn. And yes, it's a real AI because it adjusts the angle and power properly to hit an enemy tank.

Edit: I remembered that my sin and cos are 100-scaled. Improved magnitude estimates.


Code:
Gameplay_AITurn_Aim:
   ; 1. Pick an alive tank
   ; 1a. Set deltaX, deltaY
   ; 2. Loop Theta 0 to 180, step 2*(6-Difficulty)
   ; 2a. calculate Q = a/2 * deltaX
   ; 2b. calculate R = deltaY * cos(theta) / 100
   ; 2c. calculate R = sin(theta)/100-R/deltaX
   ; 2d. calculate R = Rcos(theta)/100
   ; 2e. calculate v0 = sqrt(Q/R)
   ; 2f. if 0 < v0 <= 100, fire!


1a. deltaX, deltaY are 16-bit words
2. theta is a 8-bit byte
2a. a/2 is a byte. deltaX is a 16-bit word, so Q is a 16-bit word (well, 24-bit, but it turns out a/2 = 2/2 = 1)
2b. cos(theta) is a nine-bit sign-prepended byte. deltaY is a 16-bit word. R is potentially a 24-bit word. R/100 is up to an 18-bit word.
2c. R is, say, 18 bits (dearie me), deltaX is 16 bits, so it pains me to realize that the new R could also be 18 bits (but probably less)
2d. R is now 18 bits, cos(theta) is 9 bits, divide by 100 first to get 12 bits for R, multiply by cos(theta) to get 21 bits or so.
2e. Q is 16b, R is 21b, Q/R is something. Q/R is half or so of that.

2a requires no code.
2b requires a 16*16 multiply and a 32/8 divide.
2c requires a 32/16 divide, a 16/8 divide, and a (?!) 32-bit addition
2d requires a 24*8 bit multiply and a 32/8 divide
2e requires a 16/24 divide and a 16-bit square root

Here's the equation for reference, by the way:
*bump* I can has partial success burger? I suspect they're just using the wrong delta-Y now.

  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 3
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement