----------------------------------------------------------------------------- Casio fx-6000G Ballistics (c) 1986, 2006 by GanjaTron ----------------------------------------------------------------------------- VARIABLES A Projectile X-pos [m] / projectile angle [deg] B Projectile Y-pos [m] D Projectile hit distance [m] J Comp targetting jitter [0..1] P Player1 (user) X-pos [m] Q Player2 (comp) X-pos [m] S Range player1 & player2 cannons [m] T Projectile flight time [s] / swap U Projectile flight time increment [s] V Projectile X-velocity [m/s] W Projectile Y-velocity [m/s] / explosion particle counter Z Explosion particle flight time [s] B[1..10] (=C..L) Explosion particle X-velocity [m/s] L[1..10] (=M..V) Explosion particle Y-velocity [m/s] OPERATION 1 - Enter accuracy [0..1] (= 1 - jitter). 2 - A plot of the gunnery range is shown along with initial range (use G<->T to toggle between text & graphics). 3 - Player & computer take turns (first turn chosen randomly). 4 - Player enters shell velocity (V) and angle (A). Computer solves for exact params and applies jitter based on specified accuracy. 5 - Range is shown after shell lands. A range within 5 m results in a hit. NOTES Fills entire memory; omit carriage return / EXE on last line of each prog. PROJECTILE PHYSICS Projectile motion is described by s = v_0 t + a t^2 / 2, where v_0 is the initial shell velocity, a is the acceleration, t is the shell's flight time, and s is the shell's displacement. This can be broken up into independent horizontal and vertical components subject to the firing angle alpha: s_x = v_0,x t - a_r t^2 / 2, a_r approx. 0.06v_0,x (1) s_y = v_0,y t - g t^2 /2, g = 9.8 m/s^2, (2) where a_r is the (approximated) deceleration due to air resistance and g is the acceleration due to gravity. PROJECTILE PARAMETERS Projectile parameters for the computer are derived as follows: 1 - Choose a random initial horizontal shell velocity v_0,x > sqrt(2a_r s_x), where s_x is the range to the opponent. 2 - Solve equation (1) for the shell flight time t using quadratic formula: t = v_0,x - sqrt((v_0,x)^2 - 2a_r s_x) / a_r. 3 - Add random jitter to t: t = (1 + j (0.5 - xi)) t, where j is a user specified jitter factor affecting the computer's accuracy, and xi is a uniform random number in the range [0,1]. 4 - With shell height s_y = 0 at time t (since it has landed), solve equation (2) for initial vertical shell velocity v_0,y: 0 = v_0,y t - gt^2 / 2 ==> v_0,y = gt / 2. 5 - Solve for firing angle alpha: alpha = atan(v_0,y / v_0,x). ----------------------------------------------------------------------------- Prog 0 - Main program ----------------------------------------------------------------------------- Deg Range 100,700,800,0,400,500 /* Y-axis and tic marks outside window */ "ACC" ?->J 1-J->J Lbl 0 150+500Ran#->P /* P player has first turn */ 150+500Ran#->Q Abs(Q-P)->S S<300=>Goto 0 S->D Prog 3 Lbl 1 D[-Disp-] PProg 1 P>Q=>Prog 2 " /* Clears text screen making flickering plot easier to see */ " Prog 3 Prog 4 Abs D<=5=>Prog 5 P->T /* Swap P & Q to toggle player turns */ Q->P T->Q /* P=Q indicates game over */ P!=Q=>Goto 1 /* No carriage return / EXE! */ ----------------------------------------------------------------------------- Prog 1 - Player projectile params ----------------------------------------------------------------------------- "V" ?->V "A" ?->A Vsin A->W Vcos A->V /* No carriage return / EXE! */ ----------------------------------------------------------------------------- Prog 2 - Computer projectile params ----------------------------------------------------------------------------- Lbl 0 (.12+.1Ran#)S->V /* Choose random initial X-velocity V */ (V-sqrt(V^2-.12VS))/.06V->T /* Solve for shell flight time T */ T+(.5-Ran#)JT->T /* Apply jitter to T */ 4.9T->W /* Solve for initial V-velocity W */ tan^(-1) WV^(-1)->A /* Solve for angle A */ A>70=>Goto 0 /* Make sure solution is sane */ A<30=>Goto 0 -V->V /* No carriage return / EXE! */ ----------------------------------------------------------------------------- Prog 3 - Gunnery range plot ----------------------------------------------------------------------------- Cls Plot P-5,10 /* Cannon represented by 10x10m box */ Plot P+5,10 Line Plot Q-5,10 Plot Q+5,10 Line /* No carriage return / EXE! */ ----------------------------------------------------------------------------- Prog 4 - Projectile plot ----------------------------------------------------------------------------- 0->T 20/sqrt(V^2+W^2)->U /* Sensible time increment based on vel. */ Lbl 0 VT-0.03VT^2+P->A /* X & Y pos at time T; 0.03V approximates WT-4.9T^2+10->B deceleration due to air resistance */ Plot A,B T+U->T B>=10=>Goto 0 /* Shell landed? */ Line /* Disables XY coordinate display */ A-Q->D /* Return range in D */ P>Q=>-D->D /* No carriage return / EXE! */ ----------------------------------------------------------------------------- Prog 5 - Explosion plot ----------------------------------------------------------------------------- 10->W Lbl 0 30-60Ran#->B[W] /* Random initial particle X-velocity */ 30+30Ran#->L[W] /* Random initial particle Y-velocity */ Dsz W Goto 0 0->Z Lbl 1 10->W Lbl 2 Plot B[W]Z+A,L[W]Z-4.9Z^2+B /* Particle X & Y pos at time Z */ Dsz W Goto 2 Z+.5->Z Z<8=>Goto 1 P->Q /* Terminates main loop in Prog 0 */ Plot 0,0 /* Disables XY coordinate display; No carriage return / EXE! */