working on server AI's have an issue

What do you want to see in Armagetron soon? Any new feature ideas? Let's ponder these ground breaking ideas...
Post Reply
User avatar
Galaxip
Core Dumper
Posts: 112
Joined: Wed Aug 24, 2016 10:49 pm

working on server AI's have an issue

Post by Galaxip »

Hi, i've been making some tweaks to the AI's and everything is going well but I have an issue trying to get x y xdir ydir info from the cycles

I added this code into gAIPlayer::Timestep in src/tron/gAIBase.cpp
currently it doesnt do anything except read x y xdir and ydir but it just seems to lockup the server.
does anyone know what im doing wrong ?. thanks

Code: Select all

3285   // get list of game objects
3286   const tList<eGameObject>& gameObjects = Object()->Grid()->GameObjects();
3287
3288   // search object list
3289   for (int i=gameObjects.Len()-1; i>=0; i--)
3290   {
3291     // get target cycle
3292     gCycle *target=dynamic_cast<gCycle *>(gameObjects(i));
3293
3294     // get target coordinates and direction
3295     REAL tarX = target->Position().x;
3296     REAL tarY = target->Position().y;
3297     REAL tarDirX = target->Direction().x;
3298     REAL tarDirY = target->Direction().y;
3299
3300 //    if(st_aiDebug)
3301 //    {
3302 //      lbm="";
3303 //      lbm << "tarX = " << tarX << ", tarY = " << tarY << ", tarDirX = " << tarDirX << ", tarDirY = " << tarDirY << "\n";
3304 //      sn_ConsoleOut(lbm);
3305 //    }
3306
3307   }
Image Image Image
randomly changing stuff in your code until it works is "hacky" and "bad coding practice"
do it fast enough and its "machine learning"

User avatar
aP|Nelg
Match Winner
Posts: 593
Joined: Wed Oct 22, 2014 10:22 pm
Contact:

Re: working on server AI's have an issue

Post by aP|Nelg »

You're looping through all game objects, not all of them are actually cycles. You want to check to see the return from dynamic_cast is not null...
Also, I didn't see where "lbm" was defined, so I made that a tString:

Code: Select all

	// get list of game objects
	const tList<eGameObject>& gameObjects = Object()->Grid()->GameObjects();

	// search object list
	for (int i=gameObjects.Len()-1; i>=0; i--)
	{
		// get target cycle
		gCycle *target=dynamic_cast<gCycle *>(gameObjects(i));
		
		if(target)
		{

			// get target coordinates and direction
			REAL tarX = target->Position().x;
			REAL tarY = target->Position().y;
			REAL tarDirX = target->Direction().x;
			REAL tarDirY = target->Direction().y;

			//if(st_aiDebug)
			//{
			//	tString lbm("");
			//	lbm << "tarX = " << tarX << ", tarY = " << tarY << ", tarDirX = " << tarDirX << ", tarDirY = " << tarDirY << "\n";
			//	sn_ConsoleOut(lbm);
			//}
	
		}

	}

User avatar
Galaxip
Core Dumper
Posts: 112
Joined: Wed Aug 24, 2016 10:49 pm

Re: working on server AI's have an issue

Post by Galaxip »

thanks nelg the missing if(target) was the problem, lbm is defined early on in the code sorry I didnt include it

is there a better what to loop through just the list of cycles instead of all objects ?
Last edited by Galaxip on Tue Feb 09, 2021 11:33 pm, edited 1 time in total.
Image Image Image
randomly changing stuff in your code until it works is "hacky" and "bad coding practice"
do it fast enough and its "machine learning"

User avatar
Galaxip
Core Dumper
Posts: 112
Joined: Wed Aug 24, 2016 10:49 pm

Re: working on server AI's have an issue

Post by Galaxip »

that if(target) fixed the crashing issue but I now I realise im also getting target coordinates from the ai cycle too so any test I was going to do will fail as it'll be tested against itself :(


-------------- edit -------------
actually it might work as the difference between the ai and itself will be 0 hmmmm
Image Image Image
randomly changing stuff in your code until it works is "hacky" and "bad coding practice"
do it fast enough and its "machine learning"

User avatar
Galaxip
Core Dumper
Posts: 112
Joined: Wed Aug 24, 2016 10:49 pm

Re: working on server AI's have an issue

Post by Galaxip »

I couldnt do the math to calculate the direction and distance between the ai and a cycle and its just a mess of false detections

headhunter was kind enough to do a quick demo in javascript which calculates distance and direction correctly and I will base my code on this

i've uploaded the page here https://lovebug.ml/test/
Image Image Image
randomly changing stuff in your code until it works is "hacky" and "bad coding practice"
do it fast enough and its "machine learning"

User avatar
Galaxip
Core Dumper
Posts: 112
Joined: Wed Aug 24, 2016 10:49 pm

Re: working on server AI's have an issue

Post by Galaxip »

one thing I would like to do is add a command AI_FILE somefilename to reload the ai settings while im testing but using the filename I specify

I see in src/tron/gArmagetron.cpp at line 696

Code: Select all

gAICharacter::LoadAll(tString( "aiplayers.cfg" ) );
if I used this line but with a string variable containing a filename do you think the game accept the new settings ?

I know how to add commands to armagetron to set variables but I have no idea how to make a command that will trigger a call to my function to load the file
Image Image Image
randomly changing stuff in your code until it works is "hacky" and "bad coding practice"
do it fast enough and its "machine learning"

User avatar
delinquent
Match Winner
Posts: 728
Joined: Sat Jul 07, 2012 3:07 am

Re: working on server AI's have an issue

Post by delinquent »

No reason why it wouldn't, afaik. You might need to edit the contents of aiplayers.cfg instead, though - perhaps cycling through iterations of the file. I don't have the source in front of me at the moment, though, so I can't be certain that this file isn't loaded on server startup rather than on round cycling.

User avatar
aP|Nelg
Match Winner
Posts: 593
Joined: Wed Oct 22, 2014 10:22 pm
Contact:

Re: working on server AI's have an issue

Post by aP|Nelg »

A concern I can think of, if its anything like the language file situation: it will load the new stuff into RAM but also keep holding the old stuff in RAM. Therefore, you might have to clear the old contents somehow before loading the new.

User avatar
Galaxip
Core Dumper
Posts: 112
Joined: Wed Aug 24, 2016 10:49 pm

Re: working on server AI's have an issue

Post by Galaxip »

yeah i thought i would have to free the memory allocated for the original aiplayers.cfg

I still have no clue how to make a command call my custom function :(
Image Image Image
randomly changing stuff in your code until it works is "hacky" and "bad coding practice"
do it fast enough and its "machine learning"

Post Reply