作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
<分区>
我正在构建一个无状态游戏 AI 原型(prototype),如果有一种方法可以组合多个数据源并决定 2D 中的“最佳”位置,我很感兴趣方格游戏板
示例输入:
例如,我的方法是计算与一群玩家的最远距离并将怪物移动到那里(如果受重伤)。我想通过包含来自上述数组的数据来改进这一点。恐怕这真的会使这些方法膨胀 - 是否有更好的方法来分析我提到的数据?
-(void)runAway
{
[self debugMessage];
int bestTileIndex = 0;
int maxDistance = 0;
NSMutableArray* playerLocations = [[MapOfTiles sharedInstance] playerLocations];
NSMutableDictionary* validMoveDistanceToEnemy =[[NSMutableDictionary alloc] initWithCapacity:112];
float sum = 0;
//valid move arrays is an array of arrays of tiles at 1, 2, 3,etc moves away from the origin
if(validMoveArrays.count>0)
{
for(NSArray* reachableTiles in validMoveArrays)
{
for(NSNumber* tileNumber in reachableTiles)
{
sum = 0;
for(NSNumber* playerLocation in playerLocations)
{
sum += [self distanceFromTileIndex:tileNumber.intValue toTileIndex:playerLocation.intValue];
}
[validMoveDistanceToEnemy setObject:@(sum) forKey:tileNumber];
}
}
}
DLog(@"validMoveDistanceToEnemy: %@",validMoveDistanceToEnemy);
NSNumber* distanceToEnemy = nil;
for (NSNumber* key in [validMoveDistanceToEnemy allKeys])
{
distanceToEnemy = [validMoveDistanceToEnemy objectForKey:key];
if(distanceToEnemy.intValue >maxDistance)
{
maxDistance = distanceToEnemy.intValue;
bestTileIndex = key.intValue;
}
}
if(bestTileIndex>tileCountTall*tileCountWide)
{
//out of bounds or some other error
[self stationaryAction];
}else
{
//move to safest tile
[self.actor moveToTileIndex:bestTileIndex];
}
}
我是一名优秀的程序员,十分优秀!