From 6776eeccd06cb922401d3054421145032b4cb59e Mon Sep 17 00:00:00 2001 From: Tyler Arehart Date: Sat, 24 Aug 2019 09:13:23 -0700 Subject: [PATCH 01/10] Adding a ball prediction helper, and removing dropshot code since we lost support. --- src/main/java/rlbotexample/SampleBot.java | 23 ++-- .../rlbotexample/dropshot/DropshotTile.java | 42 -------- .../dropshot/DropshotTileManager.java | 100 ------------------ .../dropshot/DropshotTileState.java | 8 -- src/main/java/rlbotexample/dropshot/Hex.java | 61 ----------- .../prediction/BallPredictionHelper.java | 30 ++++++ 6 files changed, 39 insertions(+), 225 deletions(-) delete mode 100644 src/main/java/rlbotexample/dropshot/DropshotTile.java delete mode 100644 src/main/java/rlbotexample/dropshot/DropshotTileManager.java delete mode 100644 src/main/java/rlbotexample/dropshot/DropshotTileState.java delete mode 100644 src/main/java/rlbotexample/dropshot/Hex.java create mode 100644 src/main/java/rlbotexample/prediction/BallPredictionHelper.java diff --git a/src/main/java/rlbotexample/SampleBot.java b/src/main/java/rlbotexample/SampleBot.java index b4a116f..1639980 100644 --- a/src/main/java/rlbotexample/SampleBot.java +++ b/src/main/java/rlbotexample/SampleBot.java @@ -3,17 +3,17 @@ import rlbot.Bot; import rlbot.ControllerState; import rlbot.cppinterop.RLBotDll; +import rlbot.cppinterop.RLBotInterfaceException; +import rlbot.flat.BallPrediction; import rlbot.flat.GameTickPacket; import rlbot.flat.QuickChatSelection; import rlbot.manager.BotLoopRenderer; import rlbot.render.Renderer; import rlbotexample.boost.BoostManager; -import rlbotexample.dropshot.DropshotTile; -import rlbotexample.dropshot.DropshotTileManager; -import rlbotexample.dropshot.DropshotTileState; import rlbotexample.input.CarData; import rlbotexample.input.DataPacket; import rlbotexample.output.ControlsOutput; +import rlbotexample.prediction.BallPredictionHelper; import rlbotexample.vector.Vector2; import java.awt.*; @@ -75,17 +75,13 @@ private void drawDebugLines(DataPacket input, CarData myCar, boolean goLeft) { renderer.drawString3d(goLeft ? "left" : "right", Color.WHITE, myCar.position, 2, 2); - for (DropshotTile tile: DropshotTileManager.getTiles()) { - if (tile.getState() == DropshotTileState.DAMAGED) { - renderer.drawCenteredRectangle3d(Color.YELLOW, tile.getLocation(), 4, 4, true); - } else if (tile.getState() == DropshotTileState.DESTROYED) { - renderer.drawCenteredRectangle3d(Color.RED, tile.getLocation(), 4, 4, true); - } + try { + // Draw 3 seconds of ball prediction + BallPrediction ballPrediction = RLBotDll.getBallPrediction(); + BallPredictionHelper.drawTillMoment(ballPrediction, myCar.elapsedSeconds + 3, Color.CYAN, renderer); + } catch (RLBotInterfaceException e) { + e.printStackTrace(); } - - // Draw a rectangle on the tile that the car is on - DropshotTile tile = DropshotTileManager.pointToTile(myCar.position.flatten()); - if (tile != null) renderer.drawCenteredRectangle3d(Color.green, tile.getLocation(), 8, 8, false); } @@ -108,7 +104,6 @@ public ControllerState processInput(GameTickPacket packet) { // Update the boost manager and tile manager with the latest data BoostManager.loadGameTickPacket(packet); - DropshotTileManager.loadGameTickPacket(packet); // Translate the raw packet data (which is in an unpleasant format) into our custom DataPacket class. // The DataPacket might not include everything from GameTickPacket, so improve it if you need to! diff --git a/src/main/java/rlbotexample/dropshot/DropshotTile.java b/src/main/java/rlbotexample/dropshot/DropshotTile.java deleted file mode 100644 index a81f553..0000000 --- a/src/main/java/rlbotexample/dropshot/DropshotTile.java +++ /dev/null @@ -1,42 +0,0 @@ -package rlbotexample.dropshot; - - -import rlbotexample.vector.Vector3; - -/** - * Representation of one of the floor tiles in dropshot mode. - * - * This class is here for your convenience, it is NOT part of the framework. You can change it as much - * as you want, or delete it. - */ -public class DropshotTile { - - public static final double TILE_SIZE = 443.405; // side length and length from center to corner - public static final double TILE_WIDTH = 768; // length from side to opposite side - public static final double TILE_HEIGHT = 886.81; // length from corner to opposite corner - - private final Vector3 location; - private final int team; - private DropshotTileState state; - - public DropshotTile(Vector3 location) { - this.location = location; - this.team = location.y < 0 ? 0 : 1; - } - - public void setState(DropshotTileState state) { - this.state = state; - } - - public Vector3 getLocation() { - return location; - } - - public DropshotTileState getState() { - return state; - } - - public int getTeam() { - return team; - } -} diff --git a/src/main/java/rlbotexample/dropshot/DropshotTileManager.java b/src/main/java/rlbotexample/dropshot/DropshotTileManager.java deleted file mode 100644 index fcd82dd..0000000 --- a/src/main/java/rlbotexample/dropshot/DropshotTileManager.java +++ /dev/null @@ -1,100 +0,0 @@ -package rlbotexample.dropshot; - -import rlbot.cppinterop.RLBotDll; -import rlbot.flat.FieldInfo; -import rlbot.flat.GameTickPacket; -import rlbotexample.vector.Vector2; -import rlbotexample.vector.Vector3; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import static rlbotexample.dropshot.DropshotTile.TILE_HEIGHT; -import static rlbotexample.dropshot.DropshotTile.TILE_WIDTH; - -/** - * Information about where dropshot tiles are located in the arena and what state they have. Can also convert a - * vector2 point to a tile, which is useful for checking the state of the tile where the ball lands. - * - * This class is here for your convenience, it is NOT part of the framework. You can change it as much - * as you want, or delete it. - */ -public class DropshotTileManager { - - private static final ArrayList tiles = new ArrayList<>(); - private static final HashMap blueTileMap = new HashMap<>(); - private static final HashMap orangeTileMap = new HashMap<>(); - - public static List getTiles() { - return tiles; - } - - private static void loadFieldInfo(FieldInfo fieldInfo) { - - synchronized (tiles) { - - tiles.clear(); - - for (int i = 0; i < fieldInfo.goalsLength(); i++) { - rlbot.flat.GoalInfo goalInfo = fieldInfo.goals(i); - Vector3 location = new Vector3(goalInfo.location()); - DropshotTile tile = new DropshotTile(location); - tiles.add(new DropshotTile(location)); - - Hex hex = pointToHex(location.flatten()); - if (location.y < 0) { - blueTileMap.put(hex, tile); - } else { - orangeTileMap.put(hex, tile); - } - } - } - } - - public static void loadGameTickPacket(GameTickPacket packet) { - - if (packet.tileInformationLength() > tiles.size()) { - try { - loadFieldInfo(RLBotDll.getFieldInfo()); - } catch (IOException e) { - e.printStackTrace(); - return; - } - } - - for (int i = 0; i < packet.tileInformationLength(); i++) { - rlbot.flat.DropshotTile tile = packet.tileInformation(i); - DropshotTile existingTile = tiles.get(i); - existingTile.setState(DropshotTileState.values()[tile.tileState()]); - } - } - - /** - * Returns the tile under the point, or null if none is. - */ - public static DropshotTile pointToTile(Vector2 point) { - Hex hex = pointToHex(point); - if (point.y < 0) return blueTileMap.get(hex); - else return orangeTileMap.get(hex); - } - - /** - * Converts a point to a hex. - */ - private static Hex pointToHex(Vector2 point) { - - // Apply offset - if (point.y < 0) { - point = point.plus(new Vector2(0, 128)); - } else { - point = point.plus(new Vector2(0, -128)); - } - - // Calculate q and r component - double q = point.x / TILE_WIDTH - point.y * 2 / (3 * TILE_HEIGHT); - double r = point.y * 4 / (3 * TILE_HEIGHT); - return Hex.fromRounding(q, r); - } -} diff --git a/src/main/java/rlbotexample/dropshot/DropshotTileState.java b/src/main/java/rlbotexample/dropshot/DropshotTileState.java deleted file mode 100644 index b2dba3f..0000000 --- a/src/main/java/rlbotexample/dropshot/DropshotTileState.java +++ /dev/null @@ -1,8 +0,0 @@ -package rlbotexample.dropshot; - -public enum DropshotTileState { - UNKNOWN, - FRESH, - DAMAGED, - DESTROYED -} diff --git a/src/main/java/rlbotexample/dropshot/Hex.java b/src/main/java/rlbotexample/dropshot/Hex.java deleted file mode 100644 index eef320e..0000000 --- a/src/main/java/rlbotexample/dropshot/Hex.java +++ /dev/null @@ -1,61 +0,0 @@ -package rlbotexample.dropshot; - -import java.util.Objects; - -/** - * This class is used to convert a 2d point to a hex grid in the DropshotTileManager. Look here for more information: - * https://www.redblobgames.com/grids/hexagons/ - * - * This class is here for your convenience, it is NOT part of the framework. You can add to it as much - * as you want, or delete it. - */ -public class Hex { - - // For a hex the following must always be true: q + r + s == 0 - public final int q, r, s; - - public Hex(int q, int r) { - this.q = q; - this.r = r; - this.s = -q - r; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Hex that = (Hex) o; - return q == that.q && - r == that.r; - } - - @Override - public int hashCode() { - return Objects.hash(q, r); - } - - /** - * Construct a Hex from rounding two floating point q and r coordinates. - */ - public static Hex fromRounding(double fq, double fr) { - double fs = -fq - fr; - - int rx = (int)Math.round(fq); - int ry = (int)Math.round(fr); - int rz = (int)Math.round(fs); - - // Find how much each component was rounded - double x_diff = Math.abs(rx - fq); - double y_diff = Math.abs(ry - fr); - double z_diff = Math.abs(rz - fs); - - // We reset the component with the largest change back to what the constraint rx + ry + rz = 0 requires - if (x_diff > y_diff && x_diff > z_diff) { - rx = -ry - rz; - } else if (y_diff > z_diff) { - ry = -rx - rz; - } - - return new Hex(rx, ry); - } -} diff --git a/src/main/java/rlbotexample/prediction/BallPredictionHelper.java b/src/main/java/rlbotexample/prediction/BallPredictionHelper.java new file mode 100644 index 0000000..77b56c7 --- /dev/null +++ b/src/main/java/rlbotexample/prediction/BallPredictionHelper.java @@ -0,0 +1,30 @@ +package rlbotexample.prediction; + +import rlbot.flat.BallPrediction; +import rlbot.flat.PredictionSlice; +import rlbot.render.Renderer; +import rlbotexample.vector.Vector3; + +import java.awt.*; + +/** + * This class can help you get started with ball prediction. Feel free to change it as much as you want, + * this is part of your bot, not part of the framework! + */ +public class BallPredictionHelper { + + public static void drawTillMoment(BallPrediction ballPrediction, float gameSeconds, Color color, Renderer renderer) { + Vector3 previousLocation = null; + for (int i = 0; i < ballPrediction.slicesLength(); i += 4) { + PredictionSlice slice = ballPrediction.slices(i); + if (slice.gameSeconds() > gameSeconds) { + break; + } + Vector3 location = new Vector3(slice.physics().location()); + if (previousLocation != null) { + renderer.drawLine3d(color, previousLocation, location); + } + previousLocation = location; + } + } +} From 98babb46a5534433e512b5f6f07f934b43b58452 Mon Sep 17 00:00:00 2001 From: Tyler Arehart Date: Tue, 27 Aug 2019 10:26:15 -0700 Subject: [PATCH 02/10] Getting rid of unused port.cfg file. --- port.cfg | Bin 8 -> 0 bytes src/main/python/README_Tournament.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 port.cfg diff --git a/port.cfg b/port.cfg deleted file mode 100644 index 1256cfb1817cf7effe298709bcf1c94f4cf727fd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8 PcmXpsH#Rlr Date: Sun, 6 Oct 2019 22:39:37 +0100 Subject: [PATCH 03/10] Add a BallTouch class (#16) --- src/main/java/rlbotexample/SampleBot.java | 8 ++++- .../java/rlbotexample/input/DataPacket.java | 2 ++ .../input/{ => ball}/BallData.java | 6 +++- .../rlbotexample/input/ball/BallTouch.java | 29 +++++++++++++++++++ .../rlbotexample/input/{ => car}/CarData.java | 2 +- .../input/{ => car}/CarOrientation.java | 2 +- 6 files changed, 45 insertions(+), 4 deletions(-) rename src/main/java/rlbotexample/input/{ => ball}/BallData.java (70%) create mode 100644 src/main/java/rlbotexample/input/ball/BallTouch.java rename src/main/java/rlbotexample/input/{ => car}/CarData.java (98%) rename src/main/java/rlbotexample/input/{ => car}/CarOrientation.java (98%) diff --git a/src/main/java/rlbotexample/SampleBot.java b/src/main/java/rlbotexample/SampleBot.java index 1639980..80c5e3d 100644 --- a/src/main/java/rlbotexample/SampleBot.java +++ b/src/main/java/rlbotexample/SampleBot.java @@ -10,8 +10,8 @@ import rlbot.manager.BotLoopRenderer; import rlbot.render.Renderer; import rlbotexample.boost.BoostManager; -import rlbotexample.input.CarData; import rlbotexample.input.DataPacket; +import rlbotexample.input.car.CarData; import rlbotexample.output.ControlsOutput; import rlbotexample.prediction.BallPredictionHelper; import rlbotexample.vector.Vector2; @@ -75,6 +75,12 @@ private void drawDebugLines(DataPacket input, CarData myCar, boolean goLeft) { renderer.drawString3d(goLeft ? "left" : "right", Color.WHITE, myCar.position, 2, 2); + if(input.ball.hasBeenTouched) { + float lastTouchTime = myCar.elapsedSeconds - input.ball.latestTouch.gameSeconds; + Color touchColor = input.ball.latestTouch.team == 0 ? Color.BLUE : Color.ORANGE; + renderer.drawString3d((int)lastTouchTime + "s", touchColor, input.ball.position, 2, 2); + } + try { // Draw 3 seconds of ball prediction BallPrediction ballPrediction = RLBotDll.getBallPrediction(); diff --git a/src/main/java/rlbotexample/input/DataPacket.java b/src/main/java/rlbotexample/input/DataPacket.java index 7001897..a61b69c 100644 --- a/src/main/java/rlbotexample/input/DataPacket.java +++ b/src/main/java/rlbotexample/input/DataPacket.java @@ -1,6 +1,8 @@ package rlbotexample.input; import rlbot.flat.GameTickPacket; +import rlbotexample.input.ball.BallData; +import rlbotexample.input.car.CarData; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/rlbotexample/input/BallData.java b/src/main/java/rlbotexample/input/ball/BallData.java similarity index 70% rename from src/main/java/rlbotexample/input/BallData.java rename to src/main/java/rlbotexample/input/ball/BallData.java index c7f042f..8dffab4 100644 --- a/src/main/java/rlbotexample/input/BallData.java +++ b/src/main/java/rlbotexample/input/ball/BallData.java @@ -1,4 +1,4 @@ -package rlbotexample.input; +package rlbotexample.input.ball; import rlbot.flat.BallInfo; @@ -14,10 +14,14 @@ public class BallData { public final Vector3 position; public final Vector3 velocity; public final Vector3 spin; + public final BallTouch latestTouch; + public final boolean hasBeenTouched; public BallData(final BallInfo ball) { this.position = new Vector3(ball.physics().location()); this.velocity = new Vector3(ball.physics().velocity()); this.spin = new Vector3(ball.physics().angularVelocity()); + this.hasBeenTouched = ball.latestTouch() != null; + this.latestTouch = this.hasBeenTouched ? new BallTouch(ball.latestTouch()) : null; } } diff --git a/src/main/java/rlbotexample/input/ball/BallTouch.java b/src/main/java/rlbotexample/input/ball/BallTouch.java new file mode 100644 index 0000000..d0af1bb --- /dev/null +++ b/src/main/java/rlbotexample/input/ball/BallTouch.java @@ -0,0 +1,29 @@ +package rlbotexample.input.ball; + + +import rlbot.flat.Touch; +import rlbotexample.vector.Vector3; + +/** + * Basic information about the ball's latest touch. + * + * This class is here for your convenience, it is NOT part of the framework. You can change it as much + * as you want, or delete it. + */ +public class BallTouch { + public final Vector3 position; + public final Vector3 normal; + public final String playerName; + public final float gameSeconds; + public final int playerIndex; + public final int team; + + public BallTouch(final Touch touch) { + this.position = new Vector3(touch.location()); + this.normal = new Vector3(touch.normal()); + this.playerName = touch.playerName(); + this.gameSeconds = touch.gameSeconds(); + this.playerIndex = touch.playerIndex(); + this.team = touch.team(); + } +} diff --git a/src/main/java/rlbotexample/input/CarData.java b/src/main/java/rlbotexample/input/car/CarData.java similarity index 98% rename from src/main/java/rlbotexample/input/CarData.java rename to src/main/java/rlbotexample/input/car/CarData.java index 87fbfa9..1023e73 100644 --- a/src/main/java/rlbotexample/input/CarData.java +++ b/src/main/java/rlbotexample/input/car/CarData.java @@ -1,4 +1,4 @@ -package rlbotexample.input; +package rlbotexample.input.car; import rlbotexample.vector.Vector3; diff --git a/src/main/java/rlbotexample/input/CarOrientation.java b/src/main/java/rlbotexample/input/car/CarOrientation.java similarity index 98% rename from src/main/java/rlbotexample/input/CarOrientation.java rename to src/main/java/rlbotexample/input/car/CarOrientation.java index 84a0fa3..68370ec 100644 --- a/src/main/java/rlbotexample/input/CarOrientation.java +++ b/src/main/java/rlbotexample/input/car/CarOrientation.java @@ -1,4 +1,4 @@ -package rlbotexample.input; +package rlbotexample.input.car; import rlbot.flat.PlayerInfo; From 23c698fb1a2ab4c7b0c43299dc939378bc6c30e7 Mon Sep 17 00:00:00 2001 From: Antoine Tran <31257370+Tran-Antoine@users.noreply.github.com> Date: Tue, 19 Nov 2019 21:27:35 +0100 Subject: [PATCH 04/10] Minor improvements (#17) Minor changes, such as: - Usage of primitives instead of wrappers - Generified type declarations + added missing @Override annotations - Added method displayWindow --- src/main/java/rlbotexample/JavaExample.java | 8 ++++++-- src/main/java/rlbotexample/SampleBot.java | 1 + src/main/java/rlbotexample/SamplePythonInterface.java | 1 + src/main/java/rlbotexample/boost/BoostManager.java | 11 ++++++----- src/main/java/rlbotexample/output/ControlsOutput.java | 2 +- src/main/java/rlbotexample/vector/Vector2.java | 5 +++++ src/main/java/rlbotexample/vector/Vector3.java | 5 +++++ 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main/java/rlbotexample/JavaExample.java b/src/main/java/rlbotexample/JavaExample.java index c188933..d3d7230 100644 --- a/src/main/java/rlbotexample/JavaExample.java +++ b/src/main/java/rlbotexample/JavaExample.java @@ -18,12 +18,12 @@ */ public class JavaExample { - private static final Integer DEFAULT_PORT = 17357; + private static final int DEFAULT_PORT = 17357; public static void main(String[] args) { BotManager botManager = new BotManager(); - Integer port = PortReader.readPortFromArgs(args).orElseGet(() -> { + int port = PortReader.readPortFromArgs(args).orElseGet(() -> { System.out.println("Could not read port from args, using default!"); return DEFAULT_PORT; }); @@ -31,6 +31,10 @@ public static void main(String[] args) { SamplePythonInterface pythonInterface = new SamplePythonInterface(port, botManager); new Thread(pythonInterface::start).start(); + displayWindow(botManager, port); + } + + private static void displayWindow(BotManager botManager, int port) { JFrame frame = new JFrame("Java Bot"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); diff --git a/src/main/java/rlbotexample/SampleBot.java b/src/main/java/rlbotexample/SampleBot.java index 80c5e3d..0a82f17 100644 --- a/src/main/java/rlbotexample/SampleBot.java +++ b/src/main/java/rlbotexample/SampleBot.java @@ -121,6 +121,7 @@ public ControllerState processInput(GameTickPacket packet) { return controlsOutput; } + @Override public void retire() { System.out.println("Retiring sample bot " + playerIndex); } diff --git a/src/main/java/rlbotexample/SamplePythonInterface.java b/src/main/java/rlbotexample/SamplePythonInterface.java index 829aa93..aa679bc 100644 --- a/src/main/java/rlbotexample/SamplePythonInterface.java +++ b/src/main/java/rlbotexample/SamplePythonInterface.java @@ -10,6 +10,7 @@ public SamplePythonInterface(int port, BotManager botManager) { super(port, botManager); } + @Override protected Bot initBot(int index, String botType, int team) { return new SampleBot(index); } diff --git a/src/main/java/rlbotexample/boost/BoostManager.java b/src/main/java/rlbotexample/boost/BoostManager.java index a9fa1bf..b93d7a6 100644 --- a/src/main/java/rlbotexample/boost/BoostManager.java +++ b/src/main/java/rlbotexample/boost/BoostManager.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.List; /** * Information about where boost pads are located on the field and what status they have. @@ -17,15 +18,15 @@ */ public class BoostManager { - private static final ArrayList orderedBoosts = new ArrayList<>(); - private static final ArrayList fullBoosts = new ArrayList<>(); - private static final ArrayList smallBoosts = new ArrayList<>(); + private static final List orderedBoosts = new ArrayList<>(); + private static final List fullBoosts = new ArrayList<>(); + private static final List smallBoosts = new ArrayList<>(); - public static ArrayList getFullBoosts() { + public static List getFullBoosts() { return fullBoosts; } - public static ArrayList getSmallBoosts() { + public static List getSmallBoosts() { return smallBoosts; } diff --git a/src/main/java/rlbotexample/output/ControlsOutput.java b/src/main/java/rlbotexample/output/ControlsOutput.java index ace5d65..9cdbd2b 100644 --- a/src/main/java/rlbotexample/output/ControlsOutput.java +++ b/src/main/java/rlbotexample/output/ControlsOutput.java @@ -146,4 +146,4 @@ public boolean holdHandbrake() { public boolean holdUseItem() { return useItemDepressed; } -} +} \ No newline at end of file diff --git a/src/main/java/rlbotexample/vector/Vector2.java b/src/main/java/rlbotexample/vector/Vector2.java index 2197505..dad1633 100644 --- a/src/main/java/rlbotexample/vector/Vector2.java +++ b/src/main/java/rlbotexample/vector/Vector2.java @@ -98,4 +98,9 @@ public double correctionAngle(Vector2 ideal) { public static double angle(Vector2 a, Vector2 b) { return Math.abs(a.correctionAngle(b)); } + + @Override + public String toString() { + return String.format("(%s, %s)", x, y); + } } diff --git a/src/main/java/rlbotexample/vector/Vector3.java b/src/main/java/rlbotexample/vector/Vector3.java index b359c52..506ab21 100644 --- a/src/main/java/rlbotexample/vector/Vector3.java +++ b/src/main/java/rlbotexample/vector/Vector3.java @@ -99,4 +99,9 @@ public Vector3 crossProduct(Vector3 v) { double tz = x * v.y - y * v.x; return new Vector3(tx, ty, tz); } + + @Override + public String toString() { + return String.format("(%s, %s, %s)", x, y, z); + } } From f12ed427db7f84122561f9041a10dfd788622333 Mon Sep 17 00:00:00 2001 From: Tyler Arehart Date: Sat, 30 Nov 2019 02:24:11 -0800 Subject: [PATCH 05/10] Updating run.py to avoid https://github.com/RLBot/RLBot/issues/462. --- run.py | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/run.py b/run.py index 89b5a0e..60af312 100644 --- a/run.py +++ b/run.py @@ -1,36 +1,46 @@ +import sys + # https://stackoverflow.com/a/51704613 try: from pip import main as pipmain except ImportError: from pip._internal import main as pipmain +# More pip changes breaking us. +main_fn = pipmain +if hasattr(pipmain, 'main'): + main_fn = pipmain.main + +DEFAULT_LOGGER = 'rlbot' -# https://stackoverflow.com/a/24773951 -def install_and_import(package): - import importlib +if __name__ == '__main__': try: - importlib.import_module(package) - except ImportError: - pipmain(['install', package]) - finally: - globals()[package] = importlib.import_module(package) + from rlbot.utils import public_utils, logging_utils + logger = logging_utils.get_logger(DEFAULT_LOGGER) + if not public_utils.have_internet(): + logger.log(logging_utils.logging_level, + 'Skipping upgrade check for now since it looks like you have no internet') + elif public_utils.is_safe_to_upgrade(): + main_fn(['install', '-r', 'requirements.txt', '--upgrade', '--upgrade-strategy=eager']) -if __name__ == '__main__': - install_and_import('rlbot') - from rlbot.utils import public_utils + # https://stackoverflow.com/a/44401013 + rlbots = [module for module in sys.modules if module.startswith('rlbot')] + for rlbot_module in rlbots: + sys.modules.pop(rlbot_module) - if public_utils.is_safe_to_upgrade(): - pipmain(['install', '-r', 'requirements.txt', '--upgrade', '--upgrade-strategy=eager']) + except ImportError: + main_fn(['install', '-r', 'requirements.txt', '--upgrade', '--upgrade-strategy=eager']) try: - import sys if len(sys.argv) > 1 and sys.argv[1] == 'gui': from rlbot.gui.qt_root import RLBotQTGui + RLBotQTGui.main() else: from rlbot import runner + runner.main() except Exception as e: print("Encountered exception: ", e) From c5a016a2e829eca6da9727c566d46e7ab7f2009c Mon Sep 17 00:00:00 2001 From: Viliam Vadocz Date: Mon, 20 Jan 2020 11:47:13 +0100 Subject: [PATCH 06/10] Updated outdated comment --- rlbot.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rlbot.cfg b/rlbot.cfg index 80411c4..930f607 100644 --- a/rlbot.cfg +++ b/rlbot.cfg @@ -5,7 +5,7 @@ # Visit https://github.com/RLBot/RLBot/wiki/Config-File-Documentation to see what you can put here. [Match Configuration] -# Number of bots/players which will be spawned. We support up to max 10. +# Number of bots/players which will be spawned. We support up to max 64. num_participants = 2 game_mode = Soccer game_map = Mannfield From 3a47339772324f34bb01fb90992b57bfa8763c37 Mon Sep 17 00:00:00 2001 From: Tyler Arehart Date: Mon, 23 Mar 2020 20:02:47 -0700 Subject: [PATCH 07/10] Upgrading to RLBot Java framework 2.0 and cleaning some obsolete gradle tasks. --- build.gradle | 40 ++-------------------------------------- run-bot.bat | 6 ------ 2 files changed, 2 insertions(+), 44 deletions(-) diff --git a/build.gradle b/build.gradle index 0124827..8f55dc7 100644 --- a/build.gradle +++ b/build.gradle @@ -19,54 +19,18 @@ applicationDefaultJvmArgs = ["-Djna.library.path=" + dllDirectory] dependencies { // Fetch the framework jar file - compile 'org.rlbot.commons:framework:1.+' + compile 'org.rlbot.commons:framework:2.+' // This is makes it easy to find the dll when running in intellij, where JVM args don't get passed from gradle. runtime files(dllDirectory) } -task checkPipUpgradeSafety { - doLast { - new ByteArrayOutputStream().withStream { os -> - def exitValue = exec { - commandLine "python", "-c", "from rlbot.utils import public_utils; print(public_utils.is_safe_to_upgrade());" - standardOutput = os - ignoreExitValue = true - }.exitValue - - // If the exit value is nonzero, the command probably failed because rlbot is not installed at all. - ext.isSafe = exitValue != 0 || os.toString().trim() == "True" - } - } -} - - -// Uses pip (the python package manager) to install all the python packages needed for this bot, as defined -// in requirements.txt. -task pipInstallRequirements { - dependsOn 'checkPipUpgradeSafety' - - doLast { - if (checkPipUpgradeSafety.isSafe) { - exec { - commandLine "python", "-m", "pip", "install", "-r", "requirements.txt", "--upgrade" - } - } else { - println 'Skipping upgrade attempt because files are in use.' - } - } -} task createDllDirectory { mkdir dllDirectory } -// Installs or updates RLBot. Empty task for now. It still does stuff because it "dependsOn" tasks that do things. -task updateRLBot { - dependsOn 'pipInstallRequirements' - dependsOn 'createDllDirectory' -} -updateRLBot.dependsOn pipInstallRequirements +run.dependsOn createDllDirectory applicationDistribution.exclude(dllDirectory) diff --git a/run-bot.bat b/run-bot.bat index 4508712..fd7a00b 100644 --- a/run-bot.bat +++ b/run-bot.bat @@ -1,12 +1,6 @@ @rem Change the working directory to the location of this file so that relative paths will work cd /D "%~dp0" -@rem Make sure the environment variables are up-to-date. This is useful if the user installed python a moment ago. -call ./RefreshEnv.cmd - -@rem Install or update rlbot and related python packages. -call ./gradlew.bat --no-daemon updateRLBot - @rem Start running the bot. call ./gradlew.bat --no-daemon run From 9b4c363dff8bc0b130f82b914c76adbed7c56a3b Mon Sep 17 00:00:00 2001 From: Tyler Date: Sun, 17 May 2020 18:33:26 -0700 Subject: [PATCH 08/10] Setting enable_rendering and enable_state_setting to true --- rlbot.cfg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rlbot.cfg b/rlbot.cfg index 930f607..7944055 100644 --- a/rlbot.cfg +++ b/rlbot.cfg @@ -5,10 +5,13 @@ # Visit https://github.com/RLBot/RLBot/wiki/Config-File-Documentation to see what you can put here. [Match Configuration] +# Visit https://github.com/RLBot/RLBot/wiki/Config-File-Documentation to see what you can put here. # Number of bots/players which will be spawned. We support up to max 64. num_participants = 2 game_mode = Soccer game_map = Mannfield +enable_rendering = True +enable_state_setting = True [Mutator Configuration] # Visit https://github.com/RLBot/RLBot/wiki/Config-File-Documentation to see what you can put here. From cb4db9648293b028861dc10596bc376786d08010 Mon Sep 17 00:00:00 2001 From: Tyler Arehart Date: Sun, 12 Jul 2020 15:09:57 -0700 Subject: [PATCH 09/10] Removing references to legacy GUI. --- README.md | 12 +++++------- run-gui.bat | 11 ----------- run.py | 27 ++++++--------------------- 3 files changed, 11 insertions(+), 39 deletions(-) delete mode 100644 run-gui.bat diff --git a/README.md b/README.md index e7c2910..d354da3 100644 --- a/README.md +++ b/README.md @@ -3,23 +3,21 @@ An example bot implemented in Java ## Video Guide -https://youtu.be/mPfYqKe_KRs +https://youtu.be/mPfYqKe_KRs (slightly outdated because it uses the old GUI) ## Usage Instructions: -1. Make sure you've installed Python 3.6.5 or newer. Here's [Python 3.7 64 bit](https://www.python.org/ftp/python/3.7.0/python-3.7.0-amd64.exe). Some older versions like 3.6.0 will not work. During installation: - - Select "Add Python to PATH" - - Make sure pip is included in the installation 1. Make sure you've installed the Java 8 JDK or newer. Here's the [Java 8 JDK](https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html). 1. Make sure you've [set the JAVA_HOME environment variable](https://javatutorial.net/set-java-home-windows-10). 1. Download this repository 1. Double click on run-bot.bat and leave it running. It's supposed to stay open and it's OK if it says something like "75%". -1. Double click on run-gui.bat -1. Click the 'Run' button + - Alternatively you can launch the bot from inside an IDE +1. Get RLBotGUI (see https://youtu.be/lPkID_IH88U for instructions). +1. Use Add -> Load folder in RLBotGUI on the current directory. This bot should appear in the list. +1. In RLBotGUI, put the bot on a team and start the match. - Bot behavior is controlled by `src/main/java/rlbotexample/SampleBot.java` -- Bot appearance is controlled by `src/main/python/javaExampleAppearance.cfg` See the [wiki](https://github.com/RLBot/RLBotJavaExample/wiki) for tips to improve your programming experience. diff --git a/run-gui.bat b/run-gui.bat deleted file mode 100644 index a1c00d9..0000000 --- a/run-gui.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off - -@rem Change the working directory to the location of this file so that relative paths will work -cd /D "%~dp0" - -@rem Make sure the environment variables are up-to-date. This is useful if the user installed python a moment ago. -call ./RefreshEnv.cmd - -python run.py gui - -pause diff --git a/run.py b/run.py index 60af312..23ea98a 100644 --- a/run.py +++ b/run.py @@ -1,16 +1,6 @@ +import subprocess import sys -# https://stackoverflow.com/a/51704613 -try: - from pip import main as pipmain -except ImportError: - from pip._internal import main as pipmain - -# More pip changes breaking us. -main_fn = pipmain -if hasattr(pipmain, 'main'): - main_fn = pipmain.main - DEFAULT_LOGGER = 'rlbot' if __name__ == '__main__': @@ -23,7 +13,8 @@ logger.log(logging_utils.logging_level, 'Skipping upgrade check for now since it looks like you have no internet') elif public_utils.is_safe_to_upgrade(): - main_fn(['install', '-r', 'requirements.txt', '--upgrade', '--upgrade-strategy=eager']) + subprocess.call([sys.executable, "-m", "pip", "install", '-r', 'requirements.txt']) + subprocess.call([sys.executable, "-m", "pip", "install", 'rlbot', '--upgrade']) # https://stackoverflow.com/a/44401013 rlbots = [module for module in sys.modules if module.startswith('rlbot')] @@ -31,17 +22,11 @@ sys.modules.pop(rlbot_module) except ImportError: - main_fn(['install', '-r', 'requirements.txt', '--upgrade', '--upgrade-strategy=eager']) + subprocess.call([sys.executable, "-m", "pip", "install", '-r', 'requirements.txt', '--upgrade', '--upgrade-strategy=eager']) try: - if len(sys.argv) > 1 and sys.argv[1] == 'gui': - from rlbot.gui.qt_root import RLBotQTGui - - RLBotQTGui.main() - else: - from rlbot import runner - - runner.main() + from rlbot import runner + runner.main() except Exception as e: print("Encountered exception: ", e) print("Press enter to close.") From ffed34b232f5349fb81dd05c66fd63839ce8f5cd Mon Sep 17 00:00:00 2001 From: Tyler Arehart Date: Sun, 17 Oct 2021 17:45:14 -0700 Subject: [PATCH 10/10] Switching from jcenter to mavenCentral. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 8f55dc7..e4bda5e 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ apply plugin: 'application' sourceCompatibility = 1.8 repositories { - jcenter() + mavenCentral() } mainClassName = 'rlbotexample.JavaExample'