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