From ab3cef0475ee9eb8bd8ffaa7ffcefe373225c576 Mon Sep 17 00:00:00 2001 From: Kelvin Lu Date: Fri, 11 Jan 2019 13:34:20 -0500 Subject: [PATCH 1/4] make my own point --- bots/example_java/MyRobot.java | 44 +++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/bots/example_java/MyRobot.java b/bots/example_java/MyRobot.java index 04b845f..e4d8f85 100644 --- a/bots/example_java/MyRobot.java +++ b/bots/example_java/MyRobot.java @@ -1,5 +1,4 @@ package bc19; -import java.awt.Point; public class MyRobot extends BCAbstractRobot { public int turn; @@ -10,9 +9,15 @@ public Action turn() { if (me.unit == SPECS.CASTLE) { if (turn == 1) { - log("Building a pilgrim."); - return buildUnit(SPECS.PILGRIM,1,0); + log("Building a Crusader."); + return buildUnit(SPECS.CRUSADER,1,0); } + } + + if (me.unit == SPECS.CRUSADER) { + if (turn == 1) { + log("I am a Crusader."); + } Robot[] visibleRobots = getVisibleRobots(); for(Robot r: visibleRobots) { @@ -25,23 +30,30 @@ public Action turn() { Point myLocation = new Point(me.x, me.y); - if (destination == null) { - destination = Navigation.reflect(myLocation, getPassableMap(), me.id % 2 == 0); - } - - Point movementDirection = Navigation.goTo(myLocation, destination, getPassableMap(), getVisibleRobotMap()); - return move(movementDirection.x, movementDirection.y); - } + // if (destination == null) { + // destination = Navigation.reflect(myLocation, getPassableMap(), me.id % 2 == 0); + // } - if (me.unit == SPECS.PILGRIM) { - if (turn == 1) { - log("I am a pilgrim."); - - //log(Integer.toString([0][getVisibleRobots()[0].castle_talk])); - } + // Point movementDirection = Navigation.goTo(myLocation, destination, getPassableMap(), getVisibleRobotMap()); + // return move(movementDirection.x, movementDirection.y); } return null; } +} + +class Point { + public int x; + public int y; + Point(int x, int y) { + this.x = x; + this.y = y; + } + + int getSquaredDist(Point other) { + int dx = x - other.x; + int dy = y - other.y; + return dx * dx + dy * dy; + } } \ No newline at end of file From 6131a7958a46f0acc81c4abe558ed3c59843686d Mon Sep 17 00:00:00 2001 From: Kelvin Lu Date: Fri, 11 Jan 2019 13:41:28 -0500 Subject: [PATCH 2/4] it doesn't compile error but does all sorts of weird things --- bots/example_java/MyRobot.java | 16 ++++++++++------ bots/example_java/Navigation.java | 3 +-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/bots/example_java/MyRobot.java b/bots/example_java/MyRobot.java index e4d8f85..6fe1b73 100644 --- a/bots/example_java/MyRobot.java +++ b/bots/example_java/MyRobot.java @@ -8,7 +8,7 @@ public Action turn() { turn++; if (me.unit == SPECS.CASTLE) { - if (turn == 1) { + if (turn < 3) { log("Building a Crusader."); return buildUnit(SPECS.CRUSADER,1,0); } @@ -30,12 +30,12 @@ public Action turn() { Point myLocation = new Point(me.x, me.y); - // if (destination == null) { - // destination = Navigation.reflect(myLocation, getPassableMap(), me.id % 2 == 0); - // } + if (destination == null) { + destination = Navigation.reflect(myLocation, getPassableMap(), me.id % 2 == 0); + } - // Point movementDirection = Navigation.goTo(myLocation, destination, getPassableMap(), getVisibleRobotMap()); - // return move(movementDirection.x, movementDirection.y); + Point movementDirection = Navigation.goTo(myLocation, destination, getPassableMap(), getVisibleRobotMap()); + return move(movementDirection.x, movementDirection.y); } return null; @@ -56,4 +56,8 @@ int getSquaredDist(Point other) { int dy = y - other.y; return dx * dx + dy * dy; } + + Point applyDir(Point dir) { + return new Point(x + dir.x, y + dir.y); + } } \ No newline at end of file diff --git a/bots/example_java/Navigation.java b/bots/example_java/Navigation.java index 9527f28..a01e94a 100644 --- a/bots/example_java/Navigation.java +++ b/bots/example_java/Navigation.java @@ -1,5 +1,4 @@ package bc19; -import java.awt.Point; import java.util.*; @@ -12,7 +11,7 @@ public static Point goTo(Point start, Point target, boolean[][] fullMap, int[][] if (direction.x == 0 && direction.y == 0) { return direction; } - while(!isPassable(new Point(start.x + direction.x, start.y + direction.y), fullMap, robotMap)) { + while(!isPassable(start.applyDir(direction), fullMap, robotMap)) { direction = rotate(direction, 1); } From 6cf185fbbbdd52e5393615e58a84cb03e7e2a663 Mon Sep 17 00:00:00 2001 From: Kelvin Lu Date: Fri, 11 Jan 2019 13:42:06 -0500 Subject: [PATCH 3/4] it doesn't compile error but does all sorts of weird things --- bots/example_java/Navigation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bots/example_java/Navigation.java b/bots/example_java/Navigation.java index a01e94a..df839c9 100644 --- a/bots/example_java/Navigation.java +++ b/bots/example_java/Navigation.java @@ -90,7 +90,7 @@ public static boolean isPassable(Point loc, boolean[][] fullMap, int[][] robotMa if (y < 0 || y >= mapLength) { return false; } - if (fullMap[y][x] || robotMap[y][x] > 0) { + if (!fullMap[y][x] || robotMap[y][x] > 0) { return false; } return true; From 99b5615daef69cff230d648bf86e5dc87ed12c80 Mon Sep 17 00:00:00 2001 From: Kelvin Lu Date: Fri, 11 Jan 2019 13:52:31 -0500 Subject: [PATCH 4/4] working java (mostly) --- bots/example_java/MyRobot.java | 9 ++++++--- bots/exampy/robot.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/bots/example_java/MyRobot.java b/bots/example_java/MyRobot.java index 6fe1b73..9c0f868 100644 --- a/bots/example_java/MyRobot.java +++ b/bots/example_java/MyRobot.java @@ -16,7 +16,7 @@ public Action turn() { if (me.unit == SPECS.CRUSADER) { if (turn == 1) { - log("I am a Crusader."); + log("I am a Crusader."); } Robot[] visibleRobots = getVisibleRobots(); @@ -24,7 +24,10 @@ public Action turn() { if (r.team != me.team) { int diffX = r.x - me.x; int diffY = r.y - me.y; - return attack(diffX, diffY); + int dist = diffX * diffX + diffY * diffY; + if (dist >= SPECS.UNITS[SPECS.CRUSADER].ATTACK_RADIUS[0] && dist <= SPECS.UNITS[SPECS.CRUSADER].ATTACK_RADIUS[1]) { + return attack(diffX, diffY); + } } } @@ -51,7 +54,7 @@ class Point { this.y = y; } - int getSquaredDist(Point other) { + int getSquaredDistTo(Point other) { int dx = x - other.x; int dy = y - other.y; return dx * dx + dy * dy; diff --git a/bots/exampy/robot.py b/bots/exampy/robot.py index b0844e4..873f245 100644 --- a/bots/exampy/robot.py +++ b/bots/exampy/robot.py @@ -31,7 +31,7 @@ def turn(self): continue # now all in vision range, can see x, y etc dist = (r['x'] - self.me['x'])**2 + (r['y'] - self.me['y'])**2 - if r['team'] != self.me['team'] and SPECS['UNITS'][SPECS["CRUSADER"]]['ATTACK_RADIUS'][0] <= dist <= SPECS['UNITS'][SPECS["CRUSADER"]]['ATTACK_RADIUS'][1]: + if r['team'] != self.me['team'] and SPECS["UNITS"][SPECS["CRUSADER"]]["ATTACK_RADIUS"][0] <= dist <= SPECS["UNITS"][SPECS["CRUSADER"]]["ATTACK_RADIUS"][1]: attackable.append(r) if attackable: