• 大小: 29KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-02
  • 语言: Java
  • 标签:

资源简介

利用Java实现人工智能的八数码问题的宽度优先算法,实现对该问题的解决

资源截图

代码片段和文件信息

/*
 * To change this license header choose License Headers in Project Properties.
 * To change this template file choose Tools | Templates
 * and open the template in the editor.
 */
package eightnumpathbfs;

/**
 *
 * @author student
 */
public class BFS {
    static int[][] goal={{123}{804}{765}};
    Node open=new Node();
    Node close=new Node();
    Node p=new Node();
    Node q=new Node();
    BFS(int[][] wish){
    Judgement(wish);
    }
    
public void Print(int[][] W){
    System.out.println(“最终结果:“);
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
        System.out.print(“  “+W[i][j]+“  “);
        if(j==2){
            System.out.println();
        }
    }
}
}

public void TrackingProcess(int[][] Wint l){
    System.out.println(“第“+l+“次:“);
    for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
            System.out.print(“  “+W[i][j]+“  “);
            if(j==2){
                System.out.println();
            }
            }
        }
}

public void print(Node W){
    while(W.next!=null){
    System.out.println(“close:“);
        for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
        System.out.print(“  “+W.Judge[i][j]+“  “);
        if(j==2){
            System.out.println();
        }
        }
    }
    System.out.println(“close结束“);
    W=W.next;
}
}

public void Judgement(int[][] m){
    if(arraJadge(mgoal)){
        System.out.println(“已找到!“);
        Print(m);
    }else{
    for(;!arraJadge(mgoal);){
        m=move(m);
        Print(m);
    }
    }
}

public int[][] move(int[][] select){
    p=open;
    int zero[]first[][]=new int[3][3]last[][]=new int[3][3];
    int templ=0;
    last=Copy(lastselect);
    first=Copy(firstselect);
    open.Judge=first;
    for(;!arraJadge(lastgoal);){
        last=Copy(lastfirst);
        zero=getZero(last);  
        if(zero[0]==0&&zero[1]==0){
            temp=first[0][0];
            first[0][0]=first[1][0];
            first[1][0]=temp;
            if((!Judgeclose(closefirst))){
            open=creat(open first);
            }
            first=Copy(firstlast);
            temp=first[0][0];
            first[0][0]=first[0][1];
            first[0][1]=temp;
            if((!Judgeclose(closefirst))){
            open=creat(open first);
            }
        }else if(zero[0]==0&&zero[1]==1){
            temp=first[0][0];
            first[0][0]=first[0][1];
            first[0][1]=temp;
            if((!Judgeclose(closefirst))){
            open=creat(open first);
            }
            first=Copy(firstlast);
            temp=first[0][2];
            first[0][2]=first[0][1];
            first[0][1]=temp;
            if((!Judgeclose(closefirst))){
            open=creat(open first);
            }
            first=Copy(firstlast);
            temp=first[1][1];
            first[1][1]=first[0][1];
            first[0][1]=temp

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-11-30 21:48  EightNumPathBFS\
     目录           0  2018-11-30 21:48  EightNumPathBFS\build\
     文件        3630  2018-11-05 17:23  EightNumPathBFS\build.xml
     文件         101  2018-11-30 21:47  EightNumPathBFS\build\built-jar.properties
     目录           0  2018-11-30 21:48  EightNumPathBFS\build\classes\
     文件           0  2018-11-30 21:48  EightNumPathBFS\build\classes\.netbeans_automatic_build
     文件           0  2018-11-30 21:48  EightNumPathBFS\build\classes\.netbeans_update_resources
     目录           0  2018-12-02 21:48  EightNumPathBFS\build\classes\eightnumpathbfs\
     文件        6427  2018-12-02 21:48  EightNumPathBFS\build\classes\eightnumpathbfs\BFS.class
     文件        1109  2018-12-02 21:41  EightNumPathBFS\build\classes\eightnumpathbfs\EightNumPathBFS.class
     文件         352  2018-12-02 21:41  EightNumPathBFS\build\classes\eightnumpathbfs\Node.class
     目录           0  2018-11-30 21:47  EightNumPathBFS\build\empty\
     目录           0  2018-11-30 21:47  EightNumPathBFS\build\generated-sources\
     目录           0  2018-11-30 21:47  EightNumPathBFS\build\generated-sources\ap-source-output\
     目录           0  2018-11-30 21:48  EightNumPathBFS\dist\
     文件        9229  2018-11-30 21:48  EightNumPathBFS\dist\EightNumPathBFS.jar
     文件        1331  2018-11-30 21:48  EightNumPathBFS\dist\README.TXT
     文件          85  2018-11-05 17:23  EightNumPathBFS\manifest.mf
     目录           0  2018-11-05 17:23  EightNumPathBFS\nbproject\
     文件       79910  2018-11-22 10:21  EightNumPathBFS\nbproject\build-impl.xml
     文件         475  2018-11-22 10:21  EightNumPathBFS\nbproject\genfiles.properties
     目录           0  2018-11-05 18:06  EightNumPathBFS\nbproject\private\
     文件         112  2018-11-26 19:17  EightNumPathBFS\nbproject\private\private.properties
     文件         343  2018-12-04 20:00  EightNumPathBFS\nbproject\private\private.xml
     文件        2497  2018-11-05 17:23  EightNumPathBFS\nbproject\project.properties
     文件         523  2018-11-05 17:23  EightNumPathBFS\nbproject\project.xml
     目录           0  2018-11-05 17:23  EightNumPathBFS\src\
     目录           0  2018-12-02 21:41  EightNumPathBFS\src\eightnumpathbfs\
     文件        9031  2018-12-02 21:48  EightNumPathBFS\src\eightnumpathbfs\BFS.java
     文件         781  2018-11-19 17:29  EightNumPathBFS\src\eightnumpathbfs\EightNumPathBFS.java
     文件         345  2018-12-02 21:41  EightNumPathBFS\src\eightnumpathbfs\Node.java
............此处省略1个文件信息

评论

共有 条评论

相关资源