1.1 --- a/icfp-solver/src/main/java/ru/bosony/solvers/AbstractSolver.java Mon Jul 16 13:09:16 2012 +0400
1.2 +++ b/icfp-solver/src/main/java/ru/bosony/solvers/AbstractSolver.java Mon Jul 16 13:10:14 2012 +0400
1.3 @@ -1,16 +1,21 @@
1.4 package ru.bosony.solvers;
1.5
1.6 +import java.util.HashMap;
1.7 +import java.util.Map;
1.8 +
1.9 import ru.bosony.model.mine.Mine;
1.10
1.11 /**
1.12 - * @author indvdum (gotoindvdum[at]gmail[dot]com) <br>
1.13 - * 16.07.2012 4:30:47
1.14 - *
1.15 + * @author indvdum (gotoindvdum[at]gmail[dot]com) <br>
1.16 + * 16.07.2012 4:30:47
1.17 + *
1.18 */
1.19 public abstract class AbstractSolver {
1.20
1.21 - protected Mine mine = null;
1.22 - SolverListener listener = null;
1.23 + protected Mine mine = null;
1.24 + protected SolverListener listener = null;
1.25 + protected Map<String, Integer> routesWithScore = new HashMap<String, Integer>();
1.26 + protected long attemptsCount = 0;
1.27
1.28 public AbstractSolver(Mine mine, SolverListener listener) {
1.29 this.mine = mine;
1.30 @@ -18,5 +23,21 @@
1.31 solve();
1.32 }
1.33
1.34 + protected void addNewRoute(String route, int score) {
1.35 + if (!routesWithScore.containsKey(route) && score > getMaxFoundScore()) {
1.36 + routesWithScore.put(route, score);
1.37 + listener.foundNextRoute(route);
1.38 + }
1.39 + }
1.40 +
1.41 + protected int getMaxFoundScore() {
1.42 + int maxScore = 0;
1.43 + for (int foundScore : routesWithScore.values()) {
1.44 + if (foundScore > maxScore)
1.45 + maxScore = foundScore;
1.46 + }
1.47 + return maxScore;
1.48 + }
1.49 +
1.50 protected abstract void solve();
1.51 }