もちろん、どのように考えればいいのかはどこだったかを参考にしたけれど。
なれない言語でやるとこんがらがりそうだったから、まずは使い慣れているJavaで作って、それをD言語に移植することにした。
以下はJavaで作ってみたコード。
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
public class MainClass {
//マップデータ
int[][] mapData= {
{1,1,1,1,1},
{1,1,1,0,1},
{1,0,0,0,1},
{1,0,1,0,1},
{1,1,1,1,1}
};
public static void main(String[] args) {
new MainClass();
}
//結果出力用
ArrayList route = new ArrayList();
public MainClass(){
//スタート地点
Vector start = new Vector(0,0,-1);
//ゴール地点
Vector goal = new Vector(2,3,-1);
//マップの探索可・不可、探索前・後のフラグをセット
int x = mapData[0].length; int y = mapData.length;
State[][] mapState = new State[y][x];
for(int i=0; i {
public int compare(Vector s, Vector t) {
// + (x > y)
// compare x y = 0 (x = y)
// - (x {
public int compare(Vector s, Vector t) {
// + (x > y)
// compare x y = 0 (x = y)
// - (x < y)
if(s == null) return -1;
if(t == null) return 1;
return s.cost - t.cost;
}
}