hedgewars/uAIAmmoTests.pas
changeset 998 65792c4e6f01
parent 994 ea415d03968c
child 1001 502508979713
equal deleted inserted replaced
997:d828d1d1ecc4 998:65792c4e6f01
   196     Score, EX, EY, Result: LongInt;
   196     Score, EX, EY, Result: LongInt;
   197     TestTime: Longword;
   197     TestTime: Longword;
   198 
   198 
   199 	function CheckTrace: LongInt;
   199 	function CheckTrace: LongInt;
   200 	var x, y, dY: hwFloat;
   200 	var x, y, dY: hwFloat;
       
   201 		Result: LongInt;
   201 	begin
   202 	begin
   202 	x:= Me^.X;
   203 		x:= Me^.X;
   203 	y:= Me^.Y;
   204 		y:= Me^.Y;
   204 	dY:= -Vy;
   205 		dY:= -Vy;
   205 	repeat
   206 		
   206 		x:= x + Vx;
   207 		repeat
   207 		y:= y + dY;
   208 			x:= x + Vx;
   208 		dY:= dY + cGravity;
   209 			y:= y + dY;
   209 		EX:= hwRound(x);
   210 			dY:= dY + cGravity;
   210 		EY:= hwRound(y);
   211 			EX:= hwRound(x);
   211 	until TestColl(EX, EY, 5) or (EY > 1000);
   212 			EY:= hwRound(y);
   212 	if EY < 1000 then
   213 		until TestColl(EX, EY, 5) or (EY > 1000);
   213 		begin
   214 		
   214 		CheckTrace:= RateExplosion(Me, EX, EY, 91);
   215 		if EY < 1000 then
   215 		if (CheckTrace = 0)
   216 			begin
   216 			and (not dY.isNegative) then CheckTrace:= - abs(Targ.Y - EY) div 32;
   217 			Result:= RateExplosion(Me, EX, EY, 91);
   217 		end
   218 			if (Result = 0) then
   218 	else
   219 				if (dY > _0_15) then
   219 		CheckTrace:= BadTurn
   220 					begin
       
   221 					Result:= - abs(Targ.Y - EY) div 32;
       
   222 					AddFileLog('dY > _0_15');
       
   223 					end
       
   224 				else
       
   225 					Result:= BadTurn
       
   226 			else if (Result < 0) then Result:= BadTurn
       
   227 			end
       
   228 		else
       
   229 			Result:= BadTurn;
       
   230 
       
   231 		CheckTrace:= Result
   220 	end;
   232 	end;
   221 
   233 
   222 	function Solve: LongWord;
   234 	function Solve: LongWord;
   223 	var A, B, D, T: hwFloat;
   235 	var A, B, D, T: hwFloat;
   224 		C: LongInt;
   236 		C: LongInt;
   225 	begin
   237 	begin
   226 	A:= hwSqr(cGravity) * _0_25;
   238 		A:= hwSqr(cGravity) * _0_25;
   227 	B:= - cGravity * (Targ.Y - hwRound(Me^.Y)) - _1;
   239 		B:= - cGravity * (Targ.Y - hwRound(Me^.Y)) - _1;
   228 	C:= sqr(Targ.Y - hwRound(Me^.Y)) + sqr(Targ.X - hwRound(Me^.X));
   240 		C:= sqr(Targ.Y - hwRound(Me^.Y)) + sqr(Targ.X - hwRound(Me^.X));
   229 	D:= hwSqr(B) - (A * C * 4);
   241 		D:= hwSqr(B) - (A * C * 4);
   230 	if D.isNegative = false then
       
   231 		begin
       
   232 		D:= ( - B + hwSqrt(D)) * _0_5 / A;
       
   233 		if D.isNegative = false then
   242 		if D.isNegative = false then
   234 			T:= hwSqrt(D)
   243 			begin
   235 		else
   244 			D:= ( - B + hwSqrt(D)) * _0_5 / A;
   236 			T:= _0;
   245 			if D.isNegative = false then
   237 		Solve:= hwRound(T)
   246 				T:= hwSqrt(D)
   238 		end else Solve:= 0
   247 			else
       
   248 				T:= _0;
       
   249 			Solve:= hwRound(T)
       
   250 			end else Solve:= 0
   239 	end;
   251 	end;
   240 
   252 
   241 begin
   253 begin
   242 Result:= BadTurn;
   254 Result:= BadTurn;
   243 ap.ExplR:= 0;
   255 ap.ExplR:= 0;
   244 
   256 
       
   257 if (Level > 2) then exit(BadTurn);
   245 
   258 
   246 TestTime:= Solve;
   259 TestTime:= Solve;
   247 
   260 
   248 if TestTime = 0 then exit;
   261 if TestTime = 0 then exit(BadTurn);
   249 
   262 
   250 	Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime);
   263 	Vx:= (int2hwFloat(Targ.X) - Me^.X) / int2hwFloat(TestTime);
   251 	Vy:= cGravity * (TestTime div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime);
   264 	Vy:= cGravity * (TestTime div 2) - (int2hwFloat(Targ.Y) - Me^.Y) / int2hwFloat(TestTime);
   252 
   265 
   253 	Score:= CheckTrace;
   266 	Score:= CheckTrace;