| author | indvdum (gotoindvdum[at]gmail[dot]com) |
| Mon, 16 Jul 2012 13:10:14 +0400 | |
| changeset 42 | 2bd032a701a7 |
| parent 39 | 27b98e729716 |
| child 46 | 4197f736166a |
| permissions | -rw-r--r-- |
| indvdum@34 | 1 |
package ru.bosony.solvers; |
| indvdum@34 | 2 |
|
| indvdum@35 | 3 |
import java.io.IOException; |
| indvdum@34 | 4 |
|
| indvdum@34 | 5 |
import ru.bosony.model.mine.Mine; |
| indvdum@34 | 6 |
|
| indvdum@34 | 7 |
/** |
| indvdum@34 | 8 |
* @author indvdum (gotoindvdum[at]gmail[dot]com) <br> |
| indvdum@34 | 9 |
* 16.07.2012 2:16:03 |
| indvdum@34 | 10 |
* |
| indvdum@34 | 11 |
*/ |
| indvdum@34 | 12 |
public class Solver {
|
| indvdum@34 | 13 |
|
| indvdum@38 | 14 |
protected Mine mine; |
| indvdum@38 | 15 |
protected String route = "A"; |
| indvdum@34 | 16 |
|
| indvdum@34 | 17 |
public Solver(Mine mine) {
|
| indvdum@34 | 18 |
this.mine = mine; |
| indvdum@34 | 19 |
} |
| indvdum@34 | 20 |
|
| indvdum@38 | 21 |
public void start() throws IOException, InterruptedException {
|
| indvdum@38 | 22 |
Runtime.getRuntime().addShutdownHook(new Thread() {
|
| indvdum@38 | 23 |
@Override |
| indvdum@38 | 24 |
public void run() {
|
| indvdum@38 | 25 |
System.out.println(route); |
| indvdum@38 | 26 |
} |
| indvdum@38 | 27 |
}); |
| indvdum@42 | 28 |
AbstractSolver solver = new DijkstraSolver(mine, new SolverListener() {
|
| indvdum@42 | 29 |
|
| indvdum@39 | 30 |
@Override |
| indvdum@39 | 31 |
public void foundNextRoute(String newRoute) {
|
| indvdum@39 | 32 |
route = newRoute; |
| indvdum@39 | 33 |
} |
| indvdum@39 | 34 |
}); |
| indvdum@34 | 35 |
} |
| indvdum@34 | 36 |
|
| indvdum@38 | 37 |
public static void main(String[] args) throws IOException, InterruptedException {
|
| indvdum@34 | 38 |
String map = ""; |
| indvdum@34 | 39 |
for (String arg : args) {
|
| indvdum@34 | 40 |
map += arg + "\n"; |
| indvdum@34 | 41 |
} |
| indvdum@34 | 42 |
map = map.replaceAll("\n$", "");
|
| indvdum@34 | 43 |
Mine mine = new Mine(map); |
| indvdum@34 | 44 |
Solver solver = new Solver(mine); |
| indvdum@34 | 45 |
solver.start(); |
| indvdum@34 | 46 |
} |
| indvdum@34 | 47 |
|
| indvdum@34 | 48 |
} |