# Where can I find info on grid based algorithms for stateless AI? [closed]

There seems to be an overwhelming amount of info out there on AI of all kinds, and it's kind hard to digest at once.

For my testing purposes, I'm creating a "typical stateless AI", as described in this article, and now I need to implement the following functions for a 2D square based game board:

-(void)runAway;
-(void)attackPlayer;
-(void)moveTowardsPlayer;
-(void)tacticalMoveAwayFromPlayer;
-(void)waitOrStationaryAction;


For example, I can run my own run away function like this:

-(void)runAway
{
DLog(@"runAway");
[self debugMessage];

int bestTileIndex = 0;
int largestDistance = 0;
int distance = 0;
if(validMoves.count>0)
{

for(NSNumber* tileNumber in validMoves)
{
distance = [self distanceToTargetFromTile:tileNumber.intValue];
if(distance >largestDistance)
{
largestDistance = distance;
bestTileIndex = tileNumber.intValue;
}
}
}
//move to best tile

}


but this method only checks the distance from 1 target, which may not be the best if there are multiple enemies on the game board.

Where can I find good/efficient implementations of algorithms for searching a 2D grid for these functions? For example finding a point that is furthest away from multiple opponents and is accessible within a certain number of moves.

Other functions that come to mind is picking the best/weakest target, moving towards a specific target while accounting for variable terrain cost, etc

I'm certain someone has already done this before.

• Voted to close as requests for libraries or existing code (and anything asking for an open-ended list of answers and not a single concrete answer) is off-topic for GDSE. You may consider rewording the question or asking new ones to ask for the algorithm (not just an implementation) for solving a specific problem. – Sean Middleditch Dec 17 '13 at 1:53