Smartzkid
2008-08-21 20:05:09
Well, let me start off, this isn't at all my idea, I was just looking at Sum's pathmaker (gj, sum!), and it reminded me of a thread I saw at RSBot.
http://rsbot.com/smf/index.php?topic=9826.msg83227#msg83227
Basically, map out (by hand; it really isn't that bad, if you do it in small increments) all of RS with this web - a walkable mesh. Add 1 or 2 tolerance to every tile, and you can walk anywhere using a nearly infinite many paths.
EDIT: More code, for anyone interested. http://pastebin.ubuntu.com/39593/ :
http://rsbot.com/smf/index.php?topic=9826.msg83227#msg83227
Basically, map out (by hand; it really isn't that bad, if you do it in small increments) all of RS with this web - a walkable mesh. Add 1 or 2 tolerance to every tile, and you can walk anywhere using a nearly infinite many paths.
EDIT: More code, for anyone interested. http://pastebin.ubuntu.com/39593/ :
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import com.speljohan.rsbot.script.*;
import com.speljohan.rsbot.bot.*;
import com.speljohan.rsbot.script.wrappers.*;
import com.speljohan.rsbot.event.listeners.*;
import com.speljohan.rsbot.event.events.*;
import java.awt.event.KeyEvent;
import java.applet.Applet;
import com.speljohan.rsbot.plugin.NonPluginClass;
public class BotArmy extends Script {
RSTile[] path;
public String getName() {
return "Bot Army";
}
public double getVersion() {
return 2.1;
}
public String getAuthor() {
return "Mike";
}
public String getScriptCategory() {
return "Mike's Scripts";
}
public String getScriptDescription() {
return "<html>\n" +
"<head></head>\n" +
"<body>\n" +
"<center>" +
"<h2>" + getName() + "</h2>" +
"</center>\n" +
"<b>Author:</b> " + getAuthor() + "<br/>\n" +
"<b>Version:</b> " + getVersion() + "<br/>\n" +
"<br/>\n" +
"<b>Starting Location:</b> Tutorial island/Lumbridge<br/>" +
"<b>Function:</b> Will do 'Learning The Ropes' then train your stats to the desired levels." +
"<br/>" +
"<b>Version Notes:</b> " +
"<ul>" +
"<li>" +
"<li>" +
"<b>0.*:</b> Beta Versions" +
"</li>" +
"</ul>" +
"</body>\n" +
"</html>";
}
public boolean onStart(String[] args) {
nodes = new ArrayList<MapNode>();
links = new ArrayList<MapLink>();
loadMap();
path = generateProperPath(3253, 3401);
return true;
}
public int loop() {
try {
if(getMyPlayer().isMoving())
return random(300,500);
if(walkPathMM(randomizePath(path,2,2),17))
return -1;
} catch(Exception e) {
}
return random(300,500);
}
static List nodes, links;
int nodeCount = 0;
int[][] pathFound = null;
int[][] mapPath = null;
public RSTile[] generateProperPath(int x, int y) {
try {
ArrayList<RSTile> list = new ArrayList<RSTile>();
int[][] test = findPath(getLocation().getX(), getLocation().getY(), x,y);
for(int i=0; i<test.length; i++)
list.add(new RSTile(test[i][0], test[i][1]));
return list.toArray(new RSTile[list.size()]);
} catch(Exception e){
e.printStackTrace();
}
return null;
}
private void loadMap() {
try {
FileReader fileReader = new FileReader("Scripts\\nodes.txt");
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line;
while((line = bufferedReader.readLine()) != null) {
String[] thisLine = line.split("\t");
addNode(Integer.parseInt(thisLine[0]), Integer.parseInt(thisLine[1]), Integer.parseInt(thisLine[2]));
}
bufferedReader.close();
} catch (Exception e) {
System.out.println("error loading nodes");
}
try {
FileReader fileReader = new FileReader("Scripts\\links.txt");
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line;
while((line = bufferedReader.readLine()) != null) {
String[] thisLine = line.split("\t");
addLinkIndex(Integer.parseInt(thisLine[0]), Integer.parseInt(thisLine[1]));
}
bufferedReader.close();
} catch (Exception e) {
System.out.println("error loading links");
}
}
private void addNode(int x, int y) throws Exception {
try {
nodes.add(new MapNode(x, y, nodeCount++));
} catch(Exception e){
e.printStackTrace();
}
}
private void addNode(int x, int y, int index) {
try {
nodes.add(new MapNode(x, y, index));
nodeCount = index + 1;
} catch(Exception e){
e.printStackTrace();
}
}
private void addLink(int start, int end) {
try {
start = getIndex(start);
end = getIndex(end);
for(int i = 0; i < links.size(); i++) {
MapLink link = (MapLink)links.get(i);
if(link.startNode == start && link.endNode == end)
return;
if(link.startNode == end && link.endNode == start)
return;
}
links.add(new MapLink(start, end));
} catch(Exception e){
e.printStackTrace();
}
}
private void addLinkIndex(int start, int end) {
try {
for(int i = 0; i < links.size(); i++) {
MapLink link = (MapLink)links.get(i);
if(link.startNode == start && link.endNode == end)
return;
if(link.startNode == end && link.endNode == start)
return;
}
links.add(new MapLink(start, end));
} catch(Exception e){
e.printStackTrace();
}
}
private static int coordinateX(int x) {
return (int)((x / 3) + 2032);
}
private static int coordinateY(int y) {
return (int)(4129 - (y / 3));
}
private int getIndex(int index) {
try {
MapNode node = (MapNode)nodes.get(index);
return node.index;
} catch(Exception e){
e.printStackTrace();
}
return 0;
}
private int findIndex(int index) {
for(int i = 0; i < nodes.size(); i++) {
MapNode node = (MapNode)nodes.get(i);
if(node.index == index)
return i;
}
return -1;
}
private MapNode getNode(int index) {
for(int i = 0; i < nodes.size(); i++) {
MapNode node = (MapNode)nodes.get(i);
if(node.index == index)
return node;
}
System.out.println("notfound=" + index);
return null;
}
private int distance(int x1, int x2, int y1, int y2) {
int dx = x1 - x2;
int dy = y1 - y2;
return (int)Math.sqrt(dx*dx + dy*dy);
}
private int coordinateToMapX(int x) {
return 3 * (x - 2032);
}
private int coordinateToMapY(int y) {
return -3 * (y - 4129);
}
private int[][] findPath(int startX, int startY, int endX, int endY) {
try {
pathFound = null;
mapPath = null;
int start, end, shortestIdx = -1, shortest = 99999;
for(int i = 0; i < nodes.size(); i++) {
MapNode node = (MapNode)nodes.get(i);
if(distance(coordinateToMapX(startX), node.x, coordinateToMapY(startY), node.y) < shortest || shortestIdx == -1) {
shortestIdx = i;
shortest = distance(coordinateToMapX(startX), node.x, coordinateToMapY(startY), node.y);
}
}
start = shortestIdx;
shortestIdx = -1;
shortest = 99999;
for(int i = 0; i < nodes.size(); i++) {
MapNode node = (MapNode)nodes.get(i);
if(distance(coordinateToMapX(endX), node.x, coordinateToMapY(endY), node.y) < shortest || shortestIdx == -1) {
shortestIdx = i;
shortest = distance(coordinateToMapX(endX), node.x, coordinateToMapY(endY), node.y);
}
}
end = shortestIdx;
long t = System.currentTimeMillis();
List activeNodes = new ArrayList();
MapNode node = (MapNode)nodes.get(start);
activeNodes.add(new int[] { node.x, node.y, 0, -1, activeNodes.size(), node.index });
node = (MapNode)nodes.get(end);
int endIndex = node.index;
activeNodes.add(new int[] { node.x, node.y, 999999, -1, activeNodes.size(), node.index });
for(int i = 0; i < nodes.size(); i++) {
if(i != start && i != end) {
node = (MapNode)nodes.get(i);
activeNodes.add(new int[] { node.x, node.y, 999999, -1, activeNodes.size(), node.index });
}
}
List allNodes = new ArrayList();
for(int i = 0; i < activeNodes.size(); i++)
allNodes.add(activeNodes.get(i));
while(activeNodes.isEmpty() == false) {
int j = 0;
int[] tNearestNode = (int[])activeNodes.get(0);
int[] tNode = new int[1];
for(int i = 0; i < activeNodes.size(); i++){
tNode = (int[])activeNodes.get(i);
if(tNode[2] < tNearestNode[2]) {
tNearestNode = tNode;
j = i;
}
}
activeNodes.remove(j);
if(tNearestNode[5] == endIndex) {
activeNodes.clear();
} else {
for(int i = 0; i < activeNodes.size(); i++){
tNode = (int[])activeNodes.get(i);
for(int k = 0; k < links.size(); k++) {
MapLink link = (MapLink)links.get(k);
if((link.startNode == tNode[5] && link.endNode == tNearestNode[5]) || (link.startNode == tNearestNode[5] && link.endNode == tNode[5])){
int dx = Math.abs(tNearestNode[0] - tNode[0]);
int dy = Math.abs(tNearestNode[1] - tNode[1]);
int new_dist = dx*dx + dy*dy;
int alt = tNearestNode[2] + new_dist;
if(alt < tNode[2]) {
tNode[2] = alt;
tNode[3] = tNearestNode[4];
}
}
}
}
}
}
List path = new ArrayList();
boolean doContinue = true;
int i = 1;
int j = 1;
while(doContinue) {
int[] tNode = (int[])allNodes.get(i);
path.add(new int[] {tNode[0], tNode[1], tNode[5]});
if(tNode[3] == -1)
doContinue = false;
i = tNode[3];
}
i = 0;
pathFound = new int[path.size()][2];
mapPath = new int[path.size()][2];
for(int k = path.size() - 1; k >= 0; k--) {
int[] tNode = (int[])path.get(k);
pathFound[i] = new int[] { tNode[0], tNode[1], tNode[2] };
mapPath[i++] = new int[] { coordinateX(tNode[0]), coordinateY(tNode[1]) };
}
if(path.size() == 1) {
System.out.println("no valid path found");
pathFound = null;
mapPath = null;
} else {
System.out.println("path found, time=" + (System.currentTimeMillis() - t) + "ms, " + path.size() + " nodes");
}
return mapPath;
} catch(Exception e){
e.printStackTrace();
}
return new int[0][0];
}
}
class MapLink implements NonPluginClass {
int startNode, endNode;
public MapLink(int startNode, int endNode) {
this.startNode = startNode;
this.endNode = endNode;
}
}
class MapNode implements NonPluginClass {
int x, y, index;
public MapNode(int x, int y, int index) {
this.x = x;
this.y = y;
this.index = index;
}
}