Capturing SIGINT signal
authorindvdum (gotoindvdum[at]gmail[dot]com)
Mon, 16 Jul 2012 04:20:54 +0400
changeset 380af2bd7f816a
parent 37 6b5044129537
child 39 27b98e729716
Capturing SIGINT signal
icfp-solver/src/main/java/ru/bosony/solvers/Solver.java
     1.1 --- a/icfp-solver/src/main/java/ru/bosony/solvers/Solver.java	Mon Jul 16 04:07:15 2012 +0400
     1.2 +++ b/icfp-solver/src/main/java/ru/bosony/solvers/Solver.java	Mon Jul 16 04:20:54 2012 +0400
     1.3 @@ -1,8 +1,6 @@
     1.4  package ru.bosony.solvers;
     1.5  
     1.6 -import java.io.BufferedWriter;
     1.7  import java.io.IOException;
     1.8 -import java.io.OutputStreamWriter;
     1.9  
    1.10  import ru.bosony.model.mine.Mine;
    1.11  
    1.12 @@ -13,21 +11,27 @@
    1.13   */
    1.14  public class Solver {
    1.15  
    1.16 -	protected Mine				mine;
    1.17 -	protected BufferedWriter	writer;
    1.18 +	protected Mine		mine;
    1.19 +	protected String	route	= "A";
    1.20  
    1.21  	public Solver(Mine mine) {
    1.22  		this.mine = mine;
    1.23 -		writer = new BufferedWriter(new OutputStreamWriter(System.out));
    1.24  	}
    1.25  
    1.26 -	public void start() throws IOException {
    1.27 +	public void start() throws IOException, InterruptedException {
    1.28 +		Runtime.getRuntime().addShutdownHook(new Thread() {
    1.29 +			@Override
    1.30 +			public void run() {
    1.31 +				System.out.println(route);
    1.32 +			}
    1.33 +		});
    1.34  		// TODO solver
    1.35 -		writer.write("A");
    1.36 -		writer.flush();
    1.37 +		while (true) {
    1.38 +			Thread.sleep(1000);
    1.39 +		}
    1.40  	}
    1.41  
    1.42 -	public static void main(String[] args) throws IOException {
    1.43 +	public static void main(String[] args) throws IOException, InterruptedException {
    1.44  		String map = "";
    1.45  		for (String arg : args) {
    1.46  			map += arg + "\n";