我需要实现扫雷解算器.我已经开始实现基于规则的代理.我已经实施了一些规则.我有一个启发式函数,用于为当前单元格(有关周围单元格的信息)选择最佳匹配规则.因此,对于每个选定的细胞,它可以决定8个环境细胞打开它们,标记它们或什么都不做.我的意思是.此时,代理人将一些显示的细胞作为输入,并决定如何处理周围的细胞(此时,代理人不知道,如何决定要治疗哪个细胞).
我的问题是,用什么算法来决定要处理哪个细胞?
假设,对于第一次移动,代理将显示角落单元格(或根据某些规则进行第一次移动).那后该怎么办?
我知道我需要实现某种搜索.我知道很多搜索算法(BFS,DFS,A-STAR等),这不是问题,我只是不明白我怎么能在这里使用这些搜索.
我需要在人工智能原理中实现它:一种现代方法.
我正在使用GPUImage框架(一些旧版本)来混合两个图像(将边框叠加添加到某个图像).在我更新到最新的框架版本后,应用这样的混合后,我得到一个空的黑色图像.
我正在使用下一个方法:
- (void)addBorder {
if (currentBorder != kBorderInitialValue) {
GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
GPUImagePicture *imageToProcess = [[GPUImagePicture alloc] initWithImage:self.imageToWorkWithView.image];
GPUImagePicture *border = [[GPUImagePicture alloc] initWithImage:self.imageBorder];
blendFilter.mix = 1.0f;
[imageToProcess addTarget:blendFilter];
[border addTarget:blendFilter];
[imageToProcess processImage];
self.imageToWorkWithView.image = [blendFilter imageFromCurrentlyProcessedOutput];
[blendFilter release];
[imageToProcess release];
[border release];
}
}
Run Code Online (Sandbox Code Playgroud)
问题是什么?
虽然有很多关于这个问题的讨论,但我还没有找到答案.
问题是,在UIWebView加载页面后,它永远不会释放所有已用的内存资源.
我创建了一个空项目.刚刚添加了UIWebView.加载请求之前使用的内存(http://methodhome.com/cleanhappy)为4.5MB,加载完成后为70~90 MB.
在发布UIWebView之后,使用的内存仍然是55MB.
所以看起来有大约50MB的泄漏内存.
我尝试过下一个方法:
[_webView stringByEvaluatingJavaScriptFromString:@"var body=document.getElementsByTagName('body')[0];body.style.backgroundColor=(body.style.backgroundColor=='')?'white':'';"];
[_webView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML='';"];
[_webView stringByEvaluatingJavaScriptFromString:@"document.open();document.close();"];
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
[_webView loadHTMLString:@"" baseURL:nil];
[_webView stopLoading];
_webView.delegate = nil;
[_webView removeFromSuperview];
_webView = nil;
[[NSURLCache sharedURLCache] removeAllCachedResponses];
Run Code Online (Sandbox Code Playgroud)
我也尝试过设置:
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
Run Code Online (Sandbox Code Playgroud)
并使用内存和磁盘的缓存设置.什么都没有帮助.
怎么可能?流行的浏览器如何像Safari和Chrome一样工作,如此漏洞.释放这些资源的诀窍是什么?
我正在使用NSURLSession进行网络连接.在带有连接丢弃的Charlesproxy中进行测试表明,实际上发送了三个请求而不是一个请求.
看起来它是一种NSURLSession低级工作 - 如果它确定连接丢弃,它实际上会发送几个请求,然后才能确定没有网络并且调用委托/块失败.
为了证明我的假设,我将NSURLSessionConfiguration从defaultSessionConfiguration更改为backgroundSessionConfigurationWithIdentifier,并在调用delegate/block之前开始发送更多请求(4).
在我看来,这不是一个问题,只是想知道它可以以某种方式配置.
我使用嵌套的上下文模式来支持CoreData的多线程工作.我有CoredDataManager单例类,上下文的内容是:
self.masterContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
self.masterContext.persistentStoreCoordinator = self.persistentStoreCoordinator;
self.mainContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
self.mainContext.parentContext = self.masterContext;
Run Code Online (Sandbox Code Playgroud)
对于来自Web服务的响应的每个插入操作,我使用我的CoreDataManager的API来获取新的托管上下文:
- (NSManagedObjectContext *)newManagedObjectContext {
NSManagedObjectContext *workerContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
workerContext.parentContext = self.mainContext;
return workerContext;
}
Run Code Online (Sandbox Code Playgroud)
它看起来像(PlayerView类是NSManagedObject类的子类):
[PlayerView insertIfNeededByUniqueKey:@"playerViewId" value:playerViewId inBackgroundWithCompletionBlock:^(NSManagedObjectContext *context, PlayerView *playerView) {
playerView.playerViewId = playerViewId;
playerView.username = playerViewDictionary[@"name"];
[context saveContextWithCompletionBlock:^{
//do something
} onMainThread:NO];//block invocation on background thread
}];
Run Code Online (Sandbox Code Playgroud)
saveContextWithCompletionBlock方法在NSManagedObjectContext类中实现:
- (void)saveContextWithCompletionBlock:(SaveContextBlock)completionBlock onMainThread:(BOOL)onMainThread {
__block NSError *error = nil;
if (self.hasChanges) {
[self performBlock:^{
[self save:&error];
if (error) { …Run Code Online (Sandbox Code Playgroud) 我写了一些 ruby 脚本,它使用 CocoaPods/Xcodeproj 来编辑 xcode 项目文件。
此脚本从 xcode 构建阶段脚本执行:
ruby script.rb someProj.xcodeproj
Run Code Online (Sandbox Code Playgroud)
在 ruby 脚本中,xcodeproj 有一个“要求”:
require 'xcodeproj'
Run Code Online (Sandbox Code Playgroud)
当我从终端手动调用此脚本时,一切正常。
但是当它从 xcode 构建阶段调用时,ruby 抛出异常:
cannot load such a file xcodeproj (something like that)
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
我需要在视网膜显示器上绘制一些形状,所以我转换视网膜显示的逻辑点,如下所示:
self.inverseScale = (CGFloat)1.0/[UIScreen mainScreen].scale;
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextScaleCTM(context, inverseScale, inverseScale);
Run Code Online (Sandbox Code Playgroud)
之后定义下一个:
CGContextSetShouldAntialias(context, NO);
CGContextSetLineWidth(context, 1.0);
Run Code Online (Sandbox Code Playgroud)
好的,现在我的视网膜显示尺寸为640x960,但我对坐标感到困惑.我想如果我需要绘制一些矩形框架,我需要做下一个:
CGContextSetFillColorWithColor(context, someBlackColor);
CGContextFillRect(context, displaySizeRect);
CGContextSetStrokeColorWithColor(context, white);
CGContextAddRect(context, CGRectMake(0, 0, 639, 959));
CGContextStrokePath(context);
Run Code Online (Sandbox Code Playgroud)
但不是,我发现我需要写:
CGContextAddRect(context, CGRectMake(0, 1, 639, 959));
Run Code Online (Sandbox Code Playgroud)
代替:
CGContextAddRect(context, CGRectMake(0, 0, 639, 959));
Run Code Online (Sandbox Code Playgroud)
为什么???
我的转换是错的还是什么?
如何调用身份验证窗口,从类中为当前应用程序授予 root 一段时间的访问权限。例如,我正在编写一些应用程序来处理分区,因此它需要 root 权限才能执行某些操作。
我正在写一些应用程序.我有一些自定义视图的课程.在视图中有一个定时器正在调用"setNeedsDisplayInRect"方法.为了动画的目的,我需要那个计时器非常令人反感(没有非常复杂的动画).我已设置计时器的值:0.0001.那个价值不算太大吗?该应用程序正常使用它.
iphone ×5
objective-c ×4
ios ×3
xcode ×3
networking ×2
animation ×1
cocoa ×1
cocoapods ×1
core-data ×1
game-engine ×1
gpuimage ×1
java ×1
memory-leaks ×1
minesweeper ×1
nstimer ×1
nsurlsession ×1
root ×1
ruby ×1
ubuntu ×1
uiwebview ×1
xcodeproj ×1