function f = startFind(depth,currentStatus,notNum)
global open close targetStatus operation;
fprintf('depth: %d\n',depth);
fprintf('notLocation: %d',notNum);
currentStatus
if currentStatus == targetStatus
return
end
if isempty(open) && ~isempty(close)
return
end
[zeroRow,zeroCol] = findZero(currentStatus);
[row,col] = size(currentStatus);
% 上下左右移动
for i = 1:4
if (zeroRow + operation(i).row >= 1) && (zeroRow + operation(i).row <= row) && (zeroCol + operation(i).col >= 1) && (zeroCol + operation(i).col <= col)
zero.row = zeroRow;
zero.col = zeroCol;
status = wrapLocation(zero,currentStatus,i);
flag = isExist(status);
len = length(open);
if ~flag
open(len + 1).status = status;
open(len + 1).depth = depth + 1;
open(len + 1).notNum = notLocation(status);
open(len + 1).fn = depth + 1 + notLocation(status);
end
end
end
% open表排序
[seedNew,index] = sort([open.fn]);
temp = open(index);
open = temp;
closeLen = length(close);
close(closeLen + 1).status = currentStatus;
firstItem = open(1);
open(1) = [];
startFind(firstItem.depth,firstItem.status,firstItem.notNum)
end
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
八数码问题 基于A算法得matlab版本.zip (6个子文件)
eight-figure-puzzles-aStar-matlab-master
findZero.m 266B
isExist.m 507B
notLocation.m 272B
main.m 498B
wrapLocation.m 672B
startFind.m 1KB
共 6 条
- 1
资源评论
博士僧小星
- 粉丝: 1935
- 资源: 5894
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功