Commits

Vincent Fiack committed 1299a61

more scouts, more defense

Comments (0)

Files changed (3)

src/main/java/org/aichallenge/HiveMind.java

     private void doBerserkTurn(Field field) {    
     	runModule(razing, field, getRemainingTime()/2);
     	runModule(fighting, field, getRemainingTime()/2);
-    	runModule(gathering, field, getRemainingTime()/3);    	   
-    	runModule(scout, field, getRemainingTime()/2);
-    	runModule(berserk, field, getRemainingTime());
+    	runModule(gathering, field, getRemainingTime()/3);   
+    	runModule(berserk, field, getRemainingTime());  	 
+     	runModule(scout, field, getRemainingTime());
     	runModule(exploring, field, getRemainingTime());
     }
 

src/main/java/org/aichallenge/modules/Defending.java

 			return;
 				
 		int antCount = field.getMyAntPositions().size();
-		int maxDefenders = antCount/6;
+		int maxDefenders = antCount/5;
 		int maxDefendersByHill = maxDefenders/field.getMyHills().size();
 		maxDefendersByHill = Math.min(8, maxDefendersByHill);
 				
 	}
 	
 	private void defend(Field field, Cell hill, int maxDefenders) {			
-		int area = 7*7;
+		int area = 8*8;
 		List<Cell> ants = antSearcher.findAllAntsInArea(field, hill, area);
 		Log.log("Defending: ants=" + ants);
 		

src/main/java/org/aichallenge/modules/Scout.java

 		List<Cell> points = new ArrayList<Cell>(viewPoints);
 		points.addAll(0, field.getGuessedHills());
 		
+		reuseCachedPathes(field, points);		
+		tryUnseenPoints(field, points);
+		
+		int passes = hiveMind.getUnmovedAnts().size() / points.size();
+		for(int i=0;i<passes;i++) {
+			if(getRemainingTime() < 0 || hiveMind.getUnmovedAnts().isEmpty())
+				return;
+				
+			moveToAnyPoint(field, points);
+		}
+	}
+
+	private void reuseCachedPathes(Field field, List<Cell> points) {
 		//reuse cached targets first, even if already seen. 
 		//We want to follow the path as closely as possible to explore the map
 		for(Cell cached: pathCache.getCachedTargets()) {			
 			else
 				pathCache.removeFromCache(cached);
 		}
-		
+	}
+	
+	private void tryUnseenPoints(Field field, List<Cell> points) {
 		List<Direction> dirs = Arrays.asList(Direction.values());
 		Collections.shuffle(dirs, hiveMind.getRandom());
 		
 		}
 	}
 	
+	private void moveToAnyPoint(Field field, List<Cell> points) {
+		List<Direction> dirs = Arrays.asList(Direction.values());
+		Collections.shuffle(dirs, hiveMind.getRandom());
+		
+		for(Cell viewpoint: points) {			
+			//find the nearest ant
+			Cell selected = null;
+			int selectedDistance = Integer.MAX_VALUE;
+			for(Cell ant: hiveMind.getUnmovedAnts()) {
+				int distance = field.getDistance(ant, viewpoint);
+				if(distance < selectedDistance) {
+					selected = ant;
+					selectedDistance = distance;
+				}
+			}
+			
+			if(selected == null)
+				continue;
+			
+			//find a partial path for this ant
+			long timeLimit = getRemainingTime();		
+			int pathLimit = 30;
+			Path path = pathFinder.findPartialPath(field, selected, viewpoint, pathLimit, timeLimit);
+			if(hiveMind.issueOrder(path, this)) {
+				pathCache.cachePath(path);
+			}
+		}
+	}	
+	
 	private void init(Field field) {
 		this.viewPoints = new LinkedList<Cell>();