gpt4 book ai didi

ios - 提供解决 15 个谜题的 Action 的最佳算法是哪个?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:43:09 26 4
gpt4 key购买 nike

<分区>

我正在努力寻找随机生成的“15 个谜题”的解决步骤。所以告诉我哪个是用于快速解决它的最佳算法。为我提供这样做的方法。

我正在制作一棵包含 4*4 数组的节点树,并遍历所有尚未处理的节点,当我得到解决方案时,我停止迭代。

在 viewcontroller 中我有一些代码作为

- (IBAction)getSolution:(id)sender {
while (!appDelegate.isResultFound) {
TreeNode *node=[self nodeWithLowestCostAndUnproceessedInRootNode];
[node expandNodeToChilds];
//break;
}
NSLog(@"Result Found");
if([appDelegate.result isEqualToString:@""])
NSLog(@"No move required");
else
NSLog(@"%@",appDelegate.result);

-(TreeNode*)nodeWithLowestCostAndUnproceessedInRootNode{
TreeNode *node1;
int lowestCost=200;
for (TreeNode *node in appDelegate.treeNodes) {
if([node myHeuristicsFunction]<lowestCost&&node.isProcessed==NO){
node1=node;
lowestCost=[node.cost intValue];
}
}
return node1;}

并且在节点类中,我将节点扩展为(父节点使用的移动除外)

-(void)expandNodeToChilds{
[self checkMovesForEmptyPlace];

if(top.x>=0){
[self addPuzzleBoxToTreeBySwapingPoint:top withMove:@"Bottom"];
}
if(right.y<=3){
[self addPuzzleBoxToTreeBySwapingPoint:right withMove:@"Left"];
}
if(bottom.x<=3){
[self addPuzzleBoxToTreeBySwapingPoint:bottom withMove:@"Top"];
}
if(left.y>=0){
[self addPuzzleBoxToTreeBySwapingPoint:left withMove:@"Right"];
}
self.isProcessed=true;}

目前我正在使用 A* 的曼哈顿距离,但在很长一段时间内没有得到结果,应用程序内存增加到 1GB 并且应用程序崩溃。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com