Commits

INADA Naoki committed 0367fcc

調整

Comments (0)

Files changed (1)

src/net/javachallenge/players/Methane1Player.java

                 System.err.println("Warn: too big squad size.");
                 squadSize = robots;
             }
+            //List<TrianglePoint> route = makeRoute(location, target.getLocation());
+//            List<TrianglePoint> route = location.getShortestPath(target.getLocation());
+//            if (route == null) return;
+            
             robots -= squadSize;
             commands.add(Commands.launch(squadSize, location, target.getLocation()));
+            //commands.add(Commands.launchWithPath(squadSize, route));
             saveTemporalCommands(commands);
             System.err.println("INFO: Attack from " + location + " to " + target.getLocation() + " with " + squadSize
                     + " robots.");
+            //System.err.println("Route:" + route);
         }
 
         public boolean equals(Object other) {
     }
 
     void doTrade() {
-        if (self.getMoney() < 5000) {
-            if (stone > 600) {
-                commands.add(Commands.sellToAlienTrade(Material.Stone, stone - 600));
-            }
-            if (gas > 600) {
-                commands.add(Commands.sellToAlienTrade(Material.Gas, gas - 600));
-            }
-            if (metal > 800) {
-                commands.add(Commands.sellToAlienTrade(Material.Metal, metal - 800));
-            }
+        if (stone > 1200) {
+            commands.add(Commands.sellToAlienTrade(Material.Stone, stone - 1200));
+        }
+        if (gas > 1200) {
+            commands.add(Commands.sellToAlienTrade(Material.Gas, gas - 1200));
+        }
+        if (metal > 1600) {
+            commands.add(Commands.sellToAlienTrade(Material.Metal, metal - 1600));
+        }
+        if (metal < 400) {
+            commands.add(Commands.buyFromAlienTrade(Material.Metal, 400));
+        }
+        if (gas < 300) {
+            commands.add(Commands.buyFromAlienTrade(Material.Gas, 300));
         }
         if (metal < 400) {
             commands.add(Commands.buyFromAlienTrade(Material.Metal, 400));
         }
     }
 
+    private boolean _makeRouteSub(TrianglePoint from, TrianglePoint to, List<TrianglePoint> route, int t) {
+        int x = from.getX();
+        int y = from.getY();
+        
+        if (from.equals(to)) return true;
+
+        if (t > 0) {
+            for (Squad s: game.getField().getSquads()) {
+                int now;
+                TrianglePoint cur=s.getCurrentLocation();
+                List<TrianglePoint> sp = s.getPath();
+                for (now=0; now<sp.size(); ++now) {
+                    if (sp.get(now).equals(cur)) {
+                        break;
+                    }
+                }
+ //               System.err.println("now="+now+" path="+sp.size() + " t="+t);
+                if (now + t - 1 < sp.size()) {
+                    if (sp.get(now + t -1).equals(from)) {
+                        System.err.println("Boom: " + from);
+                        return false;
+                    }
+                }
+                if (now + t < sp.size()) {
+                    if (sp.get(now + t).equals(from)) {
+                        System.err.println("Boom: " + from);
+                        return false;
+                    }
+                }
+            }
+        }
+        
+        int dist = from.getDistance(to);
+
+        TrianglePoint next = Make.point(x-1, y);
+        if (next.getDistance(to) < dist) {
+            route.add(next);
+            if (_makeRouteSub(next, to, route, t+1)) {
+                return true;
+            }
+            route.remove(t+1);
+        }
+
+        next = Make.point(x+1, y);
+        if (next.getDistance(to) < dist) {
+            route.add(next);
+            if (_makeRouteSub(next, to, route, t+1)) {
+                return true;
+            }
+            route.remove(t+1);
+        }
+
+        if ((x+y) % 2 == 0) {
+        //if (from.isUpwardTriangle()) {
+            next = Make.point(x, y+1);
+        } else {
+            next = Make.point(x, y-1);
+        }
+        if (next.getDistance(to) < dist) {
+            route.add(next);
+            if (_makeRouteSub(next, to, route, t+1)) {
+                return true;
+            }
+            route.remove(t+1);
+        }
+        return false;
+    }
+
     /** 攻撃するときのルート計算 */
+    List<TrianglePoint> makeRoute(TrianglePoint from, TrianglePoint to) {
+        List<TrianglePoint> route = new ArrayList<>();
+        route.add(from);
+        if (_makeRouteSub(from, to, route, 0)) {
+            return route;
+        }
+        return null;
+    }
 
     /** 攻撃を行う */
     private void doAttack() {
                 if (enemyId != game.getNeutralPlayerId()) {
                     enemyRobots += (dist - t) * enemyVein.getCurrentRobotProductivity();
                 }
+                enemyRobots += dist;
 
                 // ターゲットの周辺の敵基地の強さを勘案する. 取ってすぐ取り返されるなら最初から取らない.
                 if (turn > 4 || dist > 6 || enemyVein.getOwnerId() == game.getNeutralPlayerId()) {