Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package customBots;
- import shared.Planet;
- import shared.PlanetWars;
- public class Check {
- public static Planet closest(PlanetWars game, Planet source){
- Planet target = game.neutralPlanets().get(0) ;
- for(int i = 0 ; i < game.myPlanets().size() ; i++){
- int bestDistance = 999999;
- for (Planet p : game.neutralPlanets()) {
- int dist = game.distance(source, p);
- if (dist < bestDistance) {
- bestDistance = dist;
- target = p;
- }
- }
- }
- return target;
- }
- public static void play(PlanetWars game) {
- if(game.numShips(1) + (game.production(1)) > game.numShips(2) + (game.production(2))){
- } else{
- /*
- * If they are producing more ships than us:
- *
- * send a fleet from our biggest planet
- * to their high production planet
- * to capture it
- */
- if (game.numShips(1) < 1000){
- for(int i = 0; i < game.myPlanets().size(); i++){
- Planet target = closest(game, game.myPlanets().get(i)) ;
- game.issueOrder(game.myPlanets().get(i), target, game.myPlanets().get(i).numShips()/2);
- }
- } else {
- for(int i = 0 ; i < game.myPlanets().size() ; i++){
- Planet src = game.myPlanets().get(i) ;
- Planet target = game.neutralPlanets().get(0);
- if(game.neutralPlanets().size() < 5){
- target = game.enemyPlanets().get(0);
- }else{
- target = game.neutralPlanets().get(0) ;
- }
- int numShips = src.numShips()/2 ;
- if(target.numShips() < numShips){
- numShips = target.numShips() + 3;
- }
- game.issueOrder(src, target, numShips);
- }
- }
- game.finishTurn();
- }
- }
- public static void main(String[] args) {
- String line = "";
- String message = "";
- int c;
- try {
- while ((c = System.in.read()) >= 0) {
- switch (c) {
- case '\n':
- if (line.equals("go")) {
- PlanetWars game = new PlanetWars(message);
- play(game);
- game.finishTurn();
- message = "";
- } else {
- message += line + "\n";
- }
- line = "";
- break;
- default:
- line += (char) c;
- break;
- }
- }
- } catch (Exception e) {
- // Owned.
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement