Commit 2d109468 by 李进峰

neighbour matrix implement question

parent 20b6149a
...@@ -68,36 +68,43 @@ public class GameEnv implements Serializable{ ...@@ -68,36 +68,43 @@ public class GameEnv implements Serializable{
int x = this.mapNames.get(placeMapTmp.get(tmp)); int x = this.mapNames.get(placeMapTmp.get(tmp));
int y = this.mapNames.get(placeMapTmp.get(idName)); int y = this.mapNames.get(placeMapTmp.get(idName));
this.mapGraph[x][y] = 1; this.mapGraph[x][y] = 1;
// 有方向的添加
// this.mapGraph[y][x] = 1;
} }
placeIndex.get(placeMapTmp.get(tmp)).setAbleGo(ableGos); placeIndex.get(placeMapTmp.get(tmp)).setAbleGo(ableGos);
} }
// 映射index -> map name
this.mapIndexName = new String[mapGraph.length];
for(i=0; i<mapGraph.length; i++) { for(i=0; i<mapGraph.length; i++) {
for(String mapName:mapNames.keySet()) { for(String mapName:mapNames.keySet()) {
if(mapNames.get(mapName).equals(i)) { if(mapNames.get(mapName).equals(i)) {
System.out.print(mapName+"\t"); mapIndexName[i] = mapName;
} }
} }
} }
// 映射index -> map name
this.mapIndexName = new String[mapGraph.length]; System.out.println("\n");
System.out.print("\t");
for(i=0; i<mapGraph.length; i++) { for(i=0; i<mapGraph.length; i++) {
for(String mapName:mapNames.keySet()) { for(String mapName:mapNames.keySet()) {
if(mapNames.get(mapName).equals(i)) { if(mapNames.get(mapName).equals(i)) {
mapIndexName[i] = mapName; System.out.print(mapName+"\t");
} }
} }
} }
// for(i=0; i<this.mapGraph.length; i++) { System.out.print("\n");
// for(String mapName:mapNames.keySet()) { for(i=0; i<this.mapGraph.length; i++) {
// if(mapNames.get(mapName).equals(i)) { for(String mapName:mapNames.keySet()) {
// System.out.print(mapName+"\t"); if(mapNames.get(mapName).equals(i)) {
// } System.out.print(mapName+"\t");
// } }
// for(int j=0; j<this.mapGraph[i].length; j++) { }
// System.out.print(this.mapGraph[i][j]+"\t"); for(int j=0; j<this.mapGraph[i].length; j++) {
// } System.out.print(this.mapGraph[i][j]+"\t");
// System.out.print("\n\n"); }
// } System.out.print("\n\n");
}
} }
// npc // npc
// npc class // npc class
...@@ -282,10 +289,11 @@ public class GameEnv implements Serializable{ ...@@ -282,10 +289,11 @@ public class GameEnv implements Serializable{
// 我现在能去哪 // 我现在能去哪
public List<String> queryCanGoBySite(String site){ public List<String> queryCanGoBySite(String site){
List<String> ableGoString = new ArrayList<String>(); List<String> ableGoString = new ArrayList<String>();
Place place = this.placeIndex.get(site); int x = this.mapNames.get(site);
List<Place> ableGos = place.getAbleGo(); for(int i=0; i<this.mapGraph[x].length; i++) {
for(int i=0; i<ableGos.size(); i++) { if(this.mapGraph[x][i]==1) {
ableGoString.add(ableGos.get(i).getName()); ableGoString.add(this.mapIndexName[i]);
}
} }
return ableGoString; return ableGoString;
} }
...@@ -297,9 +305,9 @@ public class GameEnv implements Serializable{ ...@@ -297,9 +305,9 @@ public class GameEnv implements Serializable{
int x = this.mapNames.get(placeA); int x = this.mapNames.get(placeA);
int y = this.mapNames.get(placeB); int y = this.mapNames.get(placeB);
if(this.mapGraph[x][y] == 1) { if(this.mapGraph[x][y] == 1) {
return 2;
}else {
return 1; return 1;
}else {
return 2;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment