#
Junjie
4 天以前 5d1aa071ca6f385a8ec9bb2b5135d259f0f225eb
src/main/java/com/zy/common/model/NavigateNode.java
New file
@@ -0,0 +1,64 @@
package com.zy.common.model;
import lombok.Data;
import lombok.ToString;
import java.io.Serializable;
import java.util.List;
/**
 * A*寻路算法Node节点
 */
@Data
public class NavigateNode implements Comparable<NavigateNode>, Cloneable, Serializable {
    private int x;//坐标x
    private int y;//坐标y
    private int F;//综合花费的步数
    private int G;//已经花费的步数
    private int H;//将要花费的步数
    private int value;
    @ToString.Exclude
    private NavigateNode Father;//父节点
    private List<String> directionList;//行走方向
    private String nodeValue;//节点数据
    private String nodeType;//节点类型
    public NavigateNode(int x, int y) {
        this.x = x;
        this.y = y;
    }
    //通过结点的坐标和目标结点的坐标可以计算出F, G, H三个属性
    //需要传入这个节点的上一个节点和最终的结点
    public void init_node(NavigateNode father, NavigateNode end) {
        this.Father = father;
        if (this.Father != null) {
            //走过的步数等于父节点走过的步数加一
            this.G = father.G + this.G;
        } else { //父节点为空代表它是第一个结点
            this.G = 0;
        }
        //以下计算方案为算法原始方案,没有去拐点方案。已被Solution计算时自动覆盖。
        //计算通过现在的结点的位置和最终结点的位置计算H值(曼哈顿法:坐标分别取差值相加)
        this.H = Math.abs(this.x - end.x) + Math.abs(this.y - end.y);
        this.F = this.G + this.H;
    }
    @Override
    public int compareTo(NavigateNode o) {
        return Integer.compare(this.F, o.F);
    }
    @Override
    public NavigateNode clone() {
        try {
            return (NavigateNode) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return null;
    }
}