#Java 8, Butter
Spreads itself as evenly possible. Smothers a town if the town is sufficiently small.
import java.util.ArrayList;
import java.util.List;
public class Butter {
int round;
int playerID;
int thisTownID;
List<Town> towns;
List<Town> myTowns;
List<Town> otherTowns;
Town thisTown;
public static void main(String[] args){
if (args.length == 0){
System.out.println("34 34 34");
return;
}
new Butter().spread(args[0].split(";"));
}
private void spread(String[] args) {
round = Integer.parseInt(args[0]);
playerID = Integer.parseInt(args[1]);
thisTownID = Integer.parseInt(args[2]);
towns = new ArrayList<>();
myTowns = new ArrayList<>();
otherTowns = new ArrayList<>();
for (int i = 3; i < args.length; i++){
towns.add(new Town(args[i]));
}
for (Town town : towns){
if (town.isMine()){
myTowns.add(town);
if (town.isThisTown()){
thisTown = town;
}
} else {
otherTowns.add(town);
}
}
Town mySmallestTown = myTowns.stream().min((a, b) -> a.getFreeKnights() - b.getFreeKnights()).get();
Town smallestEnemyTown = otherTowns.stream().min((a,b) -> a.knights - b.knights).get();
if ((thisTown.getFreeKnights() - mySmallestTown.getFreeKnights())/2 > 0) {
System.out.println("S " + mySmallestTown.getId() + " " + (thisTown.getFreeKnights() - mySmallestTown.getFreeKnights()) / 2);
} else if (thisTown.getFreeKnights() / 2 > smallestEnemyTown.numberOfKnightsToConquer()){
System.out.println("A " + smallestEnemyTown.getId() + " " + smallestEnemyTown.numberOfKnightsToConquer());
} else {
System.out.println("W");
}
}
private class Town {
private final int ownerId;
private final int id;
private final int knights;
private final int lowborns;
private Town(String string){
String[] args = string.split("_");
ownerId = Integer.parseInt(args[0]);
id = Integer.parseInt(args[1]);
knights = Integer.parseInt(args[2]);
lowborns = Integer.parseInt(args[3]);
}
private int getId() {
return id;
}
private int getOwner() {
return ownerId;
}
private int knightCount() {
return knights;
}
private int lowbornCount() {
return lowborns;
}
private boolean isMine(){
return ownerId == playerID;
}
private boolean isThisTown(){
return id == thisTownID;
}
private int getFreeKnights() {
return knights - lowborns / 2 - 1;
}
private int numberOfKnightsToConquer(){
return ((knights * 6) / 5) + (lowborns / 2) + 1;
}
}
}
Compile: javac Butter.java
Run: java Butter