我正在尝试使用递归函数来确定网格中值的最大可能组合。我的功能之一是行为很奇怪,给了我错误:
warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.
我的功能代码如下:
-(int)pattern4XBottomAtTile:(Tile *)t1 TileTwo: (Tile *) t2{
//base case
if(t1.x == t2.x && t1.y == t2.y){
return t2.value;
}
//move 1
if((t1.y < 4) && (t1.y == t2.y) && (abs(t2.x-t1.x) == 2)){
return t1.value + [self pattern4XBottomAtTile:t1.bottom TileTwo:t2];
}
//move 2
if((t1.x-t2.x == 2)&&(t1.y - t2.y > 0) ){
return t1.value + [self pattern4XBottomAtTile:t1.left TileTwo:t2];
}
if((t1.x-t2.x == -2)&&(t1.y - t2.y > 0) ){
return t1.value + [self pattern4XBottomAtTile:t1.right TileTwo:t2];
}
//move 3
if((abs(t2.y-t1.y) == 1)&&(abs(t2.x-t1.x) == 1)){
return t1.value + [self pattern4XBottomAtTile:t1.top TileTwo:t2];
}
//move 4
if((t1.y == t2.y)&&(t1.x-t2.x == 1)){
return t1.value + [self pattern4XBottomAtTile:t1.left TileTwo:t2];
}
if((t1.y == t2.y)&&(t1.x-t2.x == -1)){
return t1.value + [self pattern4XBottomAtTile:t1.right TileTwo:t2];
}
return 0;
}
到目前为止,我发现的问题是,通过使用多个断点,对象被传递给该函数,并且在零时刻后才变为零。
方法开始处的断点显示:
但是,当我运行该函数时,会遇到错误:
在屏幕的左侧,有些信息可能是相关的。
t2和t1的值都从#4处的nil开始,而t1在#5处变为nil。
该值直到大约40264才再次更改,其中t1更改为图块的地址,然后在40265再次更改。
我对我的问题所在很困惑。我的递归代码是从我的朋友提供的有效Java函数转换而来的,所以我对这一切有些迷惑。任何帮助将不胜感激。
最佳答案
如果有那么多堆栈帧,则可能是堆栈空间不足(又名内存)。您需要一个更好的算法,或者您有一个错误,并且递归不会停止。
关于ios - 奇怪的错误-对象变为零,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33895726/