diff --git a/.java-version b/.java-version new file mode 100644 index 0000000..012e496 --- /dev/null +++ b/.java-version @@ -0,0 +1 @@ +openjdk64-1.8.0.275 diff --git a/README.md b/README.md index 5d1486e..eb9024b 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,4 @@ This is the Battlecode 2021 scaffold, containing an `examplefuncsplayer`. Read h - `./gradlew update` Update to the newest version! Run every so often +# MinneCal diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index d6e2637..736fb7d 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9492014..52dd1f0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.2-bin.zip diff --git a/gradlew b/gradlew index 2fe81a7..cccdd3d 100755 --- a/gradlew +++ b/gradlew @@ -1,21 +1,5 @@ #!/usr/bin/env sh -# -# Copyright 2015 the original author or authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - ############################################################################## ## ## Gradle start up script for UN*X @@ -44,7 +28,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +DEFAULT_JVM_OPTS="" # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -125,8 +109,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` @@ -154,19 +138,19 @@ if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then else eval `echo args$i`="\"$arg\"" fi - i=`expr $i + 1` + i=$((i+1)) done case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi @@ -175,9 +159,14 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=`save "$@"` +APP_ARGS=$(save "$@") # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 9618d8d..e95643d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,100 +1,84 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/maps/DefaultMap.map17 b/maps/DefaultMap.map17 new file mode 100644 index 0000000..439937a Binary files /dev/null and b/maps/DefaultMap.map17 differ diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..496ee2c --- /dev/null +++ b/src/.gitignore @@ -0,0 +1 @@ +.DS_Store \ No newline at end of file diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..ef26768 --- /dev/null +++ b/src/README.md @@ -0,0 +1,14 @@ +# MIT BattleCode 2021 + +## Stored test robots + +- Ash --> src/ashTest + - Capabailities: + - pathfinding, based on Twitch stream +- +- +- + +## Main Robot +- Under... + - diff --git a/src/ashTest/RobotPlayer.java b/src/ashTest/RobotPlayer.java new file mode 100644 index 0000000..f236ffc --- /dev/null +++ b/src/ashTest/RobotPlayer.java @@ -0,0 +1,299 @@ +package ashTest; +import battlecode.common.*; + +public strictfp class RobotPlayer { + static RobotController rc; + + static final RobotType[] spawnableRobot = { + RobotType.POLITICIAN, + RobotType.SLANDERER, + RobotType.MUCKRAKER, + }; + + static final Direction[] directions = { + Direction.NORTH, + Direction.NORTHEAST, + Direction.EAST, + Direction.SOUTHEAST, + Direction.SOUTH, + Direction.SOUTHWEST, + Direction.WEST, + Direction.NORTHWEST, + }; + + static int turnCount; + + /** + * run() is the method that is called when a robot is instantiated in the Battlecode world. + * If this method returns, the robot dies! + **/ + @SuppressWarnings("unused") + + //MARK:- method will create robots + public static void run(RobotController rc) throws GameActionException { + + // This is the RobotController object. You use it to perform actions from this robot, + // and to get information on its current status. + RobotPlayer.rc = rc; + + turnCount = 0; + +// System.out.println("I'm a " + rc.getType() + " and I just got created!"); + while (true) { + turnCount += 1; + // Try/catch blocks stop unhandled exceptions, which cause your robot to freeze + try { + // Here, we've separated the controls into a different method for each RobotType. + // You may rewrite this into your own control structure if you wish. +// System.out.println("I'm a " + rc.getType() + "! Location " + rc.getLocation()); + switch (rc.getType()) { + case ENLIGHTENMENT_CENTER: runEnlightenmentCenter(); break; + case POLITICIAN: runPolitician(); break; + case SLANDERER: runSlanderer(); break; + case MUCKRAKER: runMuckraker(); break; + } + + // Clock.yield() makes the robot wait until the next turn, then it will perform this loop again + Clock.yield(); + + } catch (Exception e) { +// System.out.println(rc.getType() + " Exception"); + e.printStackTrace(); + } + } + } + + static void runEnlightenmentCenter() throws GameActionException { + + // create a random robot that it will build next + RobotType toBuild = randomSpawnableRobotType(); + int influence = 50; + for (Direction dir : directions) { + if (rc.canBuildRobot(toBuild, dir, influence)) { + rc.buildRobot(toBuild, dir, influence); + } else { + break; + } + } + } + + static void runPolitician() throws GameActionException { + Team enemy = rc.getTeam().opponent(); + int actionRadius = rc.getType().actionRadiusSquared; + RobotInfo[] attackable = rc.senseNearbyRobots(actionRadius, enemy); + if (attackable.length != 0 && rc.canEmpower(actionRadius)) { +// System.out.println("empowering..."); + rc.empower(actionRadius); +// System.out.println("empowered"); + return; + } + + // will move directly after empowering whatever pieces are nearby it + if (tryMove(randomDirection())) { +// System.out.println("I moved!"); + } + } + + //TODO: is there anything else the slanderer should be trying? + // congregate nearby the e'mnt center and make them not move around as much... + static void runSlanderer() throws GameActionException { + if (tryMove(randomDirection())) { +// System.out.println("I moved!"); + } + } + + static void runMuckraker() throws GameActionException { + Team enemy = rc.getTeam().opponent(); + int actionRadius = rc.getType().actionRadiusSquared; + + + // TODO: setup a flag + // sense any nearby robots... exposes the location of a slanderer + // returns the location... what if I place a flag where it was found and this directs politicians there? + for (RobotInfo robot : rc.senseNearbyRobots(actionRadius, enemy)) { + System.out.println(enemy); + if (robot.type.canBeExposed()) { + // It's a slanderer... go get them! + if (rc.canExpose(robot.location)) { +// System.out.println("e x p o s e d"); + rc.expose(robot.location); + return; + } + } + } + if (tryMove(randomDirection())) { +// System.out.println("I moved!"); + } + } + + /** + * Returns a random Direction. + * + * @return a random Direction + */ + + // MARK:- TODO: implement path finding functionality right here + //******* + static Direction randomDirection() { + return directions[(int) (Math.random() * directions.length)]; + } + + /** + * Returns a random spawnable RobotType + * + * @return a random RobotType + */ + + //MARK:- Spawns a random robot + // ****** + // create ratio algorithm for determining how many of each unit is necessary + static RobotType randomSpawnableRobotType() { // spawns a random robot + return spawnableRobot[(int) (Math.random() * spawnableRobot.length)]; + } + + /** + * Attempts to move in a given direction. + * + * @param dir The intended direction of movement + * @return true if a move was performed + * @throws GameActionException + */ + static boolean tryMove(Direction dir) throws GameActionException { +// System.out.println("I am trying to move " + dir + "; " + rc.isReady() + " " + rc.getCooldownTurns() + " " + rc.canMove(dir)); + if (rc.canMove(dir)) { + rc.move(dir); + return true; + } else return false; + } + + // MARK:- Location finding algorithm!! + static void sendLocation() throws GameActionException { + MapLocation location = rc.getLocation(); + int x = location.x, y = location.y; + int encodedLocation = (x % 128) * 128 + (y % 128); + if (rc.canSetFlag(encodedLocation)) { + rc.setFlag(encodedLocation); + } + } + + // inserts NBITS # of 0's to make a 7 bit number + static final int NBITS = 7; + static final int BITMASK = (1 << NBITS) - 1; + + // if desire to use last 10 bits to send more info + static void sendLocation(int extraInformation) throws GameActionException { + MapLocation location = rc.getLocation(); + int x = location.x, y = location.y; + + // * 128 is shifting 7 bits to the left + // 6 bits tells a location and the last bit tells you the map boundary. + int encodedLocation = (x % 128) * 128 + (y % 128) + extraInformation * 128 + 128; + if (rc.canSetFlag(encodedLocation)) { + rc.setFlag(encodedLocation); + } + } + + static MapLocation getLocationFromFlag(int flag) throws GameActionException { + int y = flag % 128; + int x = (flag / 128) % 128; + int extraInformation = flag / 128 / 128; + + // figure out where in relation to our current offset, so compare to current location + MapLocation currentLocation = rc.getLocation(); + // we know x, will get close to offset + int offsetX128 = currentLocation.x / 128; + int offsetY128 = currentLocation.y / 128; + + // multiply by x then divide by 128 so java throws away the remainder + // offsetX128 now definitely has 0 remainder, could find exact location that matched the flag + MapLocation actualLocation = new MapLocation(offsetX128 * 128 + x, offsetY128 + 128 + y); + + // this part could be coded more efficiently + MapLocation alternative = actualLocation.translate(-128, 0); + if (rc.getLocation().distanceSquaredTo(alternative) < rc.getLocation().distanceSquaredTo(actualLocation)) { + actualLocation = alternative; + } + + alternative = actualLocation.translate(128, 0); + if (rc.getLocation().distanceSquaredTo(alternative) < rc.getLocation().distanceSquaredTo(actualLocation)) { + actualLocation = alternative; + } + + alternative = actualLocation.translate(0, -128); + if (rc.getLocation().distanceSquaredTo(alternative) < rc.getLocation().distanceSquaredTo(actualLocation)) { + actualLocation = alternative; + } + + alternative = actualLocation.translate(0, 128); + if (rc.getLocation().distanceSquaredTo(alternative) < rc.getLocation().distanceSquaredTo(actualLocation)) { + actualLocation = alternative; + } + return actualLocation; + } + // actual location would be retrieved from the flag placed + + public static void run() { +// while (true) { +// //TODO: determine flag +// MapLocation target = getLocationFromFlag(flag); +// try { +// basicBug(target); +// } catch (GameActionException e) { +// // TODO +// } +// Clock.yield(); +// } + } + + // we can almost always move so lets make a threshold + static final double passabilityThreshold = 0.7; // sqaure that we're happy to walk on and above + static Direction bugDirection = null; + + + static void basicBug(MapLocation target) throws GameActionException { + Direction d = rc.getLocation().directionTo(target); + if (rc.getLocation().equals(target)) { + // do something else + } else if (!rc.isReady()) { + if (rc.canMove(d) && rc.sensePassability(rc.getLocation().add(d)) >= passabilityThreshold) { + rc.move(d); + bugDirection = null; // reset after every move + } else { + // if it can't move start going around obstacles + // code a left handed bug + if (bugDirection == null) { + bugDirection = d.rotateRight(); + } + for (int i = 8; i < 8; i ++) { // at most 8 dirs + if (rc.canMove(bugDirection) && rc.sensePassability(rc.getLocation().add(bugDirection)) >= passabilityThreshold) { + rc.move(bugDirection); + break; + } + // if you can't rotate again + bugDirection = bugDirection.rotateRight(); + } + bugDirection = bugDirection.rotateLeft(); + } + + Clock.yield(); + } + } + static int expensive = 0; + static void somethingExpensive() { + for (int i = 0; i < 10000 && Clock.getBytecodesLeft() >= 1500; i ++) { + // does some hard work + + + } + } + + // NOTES + // x2 % 128, then you can do (x2- x1) % 128 + // Then need to figure out if x1 or x2 is bigger, only differ by at most 64 then x2 > x1 if the value is < 64 + // And vise versa + // then you can figure out exactly what x2 - x1 is (problem with the 4 corners and not having an exact spot) + + // can combine three values of the x, y, and extra information into a flag. + // Bit shifting: x % 128 by 7 bits and the extra information is shifted by 7 bits, they're all therefore stored in the flag + +} diff --git a/src/examplefuncsplayer/RobotPlayer.java b/src/examplefuncsplayer/RobotPlayer.java index ca48ca7..186ef04 100644 --- a/src/examplefuncsplayer/RobotPlayer.java +++ b/src/examplefuncsplayer/RobotPlayer.java @@ -36,14 +36,14 @@ public static void run(RobotController rc) throws GameActionException { turnCount = 0; - System.out.println("I'm a " + rc.getType() + " and I just got created!"); +// System.out.println("I'm a " + rc.getType() + " and I just got created!"); while (true) { turnCount += 1; // Try/catch blocks stop unhandled exceptions, which cause your robot to freeze try { // Here, we've separated the controls into a different method for each RobotType. // You may rewrite this into your own control structure if you wish. - System.out.println("I'm a " + rc.getType() + "! Location " + rc.getLocation()); +// System.out.println("I'm a " + rc.getType() + "! Location " + rc.getLocation()); switch (rc.getType()) { case ENLIGHTENMENT_CENTER: runEnlightenmentCenter(); break; case POLITICIAN: runPolitician(); break; @@ -55,7 +55,7 @@ public static void run(RobotController rc) throws GameActionException { Clock.yield(); } catch (Exception e) { - System.out.println(rc.getType() + " Exception"); +// System.out.println(rc.getType() + " Exception"); e.printStackTrace(); } } @@ -78,18 +78,20 @@ static void runPolitician() throws GameActionException { int actionRadius = rc.getType().actionRadiusSquared; RobotInfo[] attackable = rc.senseNearbyRobots(actionRadius, enemy); if (attackable.length != 0 && rc.canEmpower(actionRadius)) { - System.out.println("empowering..."); +// System.out.println("empowering..."); rc.empower(actionRadius); - System.out.println("empowered"); +// System.out.println("empowered"); return; } - if (tryMove(randomDirection())) - System.out.println("I moved!"); + if (tryMove(randomDirection())) { +// System.out.println("I moved!"); + } } static void runSlanderer() throws GameActionException { - if (tryMove(randomDirection())) - System.out.println("I moved!"); + if (tryMove(randomDirection())) { +// System.out.println("I moved!"); + } } static void runMuckraker() throws GameActionException { @@ -99,14 +101,15 @@ static void runMuckraker() throws GameActionException { if (robot.type.canBeExposed()) { // It's a slanderer... go get them! if (rc.canExpose(robot.location)) { - System.out.println("e x p o s e d"); +// System.out.println("e x p o s e d"); rc.expose(robot.location); return; } } } - if (tryMove(randomDirection())) - System.out.println("I moved!"); + if (tryMove(randomDirection())) { +// System.out.println("I moved!"); + } } /** @@ -135,7 +138,7 @@ static RobotType randomSpawnableRobotType() { * @throws GameActionException */ static boolean tryMove(Direction dir) throws GameActionException { - System.out.println("I am trying to move " + dir + "; " + rc.isReady() + " " + rc.getCooldownTurns() + " " + rc.canMove(dir)); +// System.out.println("I am trying to move " + dir + "; " + rc.isReady() + " " + rc.getCooldownTurns() + " " + rc.canMove(dir)); if (rc.canMove(dir)) { rc.move(dir); return true; diff --git a/src/mainRobot/RobotPlayer.java b/src/mainRobot/RobotPlayer.java new file mode 100644 index 0000000..a36586e --- /dev/null +++ b/src/mainRobot/RobotPlayer.java @@ -0,0 +1,186 @@ +package mainRobot; +import battlecode.common.*; + +public strictfp class RobotPlayer { + static RobotController rc; + + static final RobotType[] spawnableRobot = { + RobotType.POLITICIAN, + RobotType.SLANDERER, + RobotType.MUCKRAKER, + }; + + static final Direction[] directions = { + Direction.NORTH, + Direction.NORTHEAST, + Direction.EAST, + Direction.SOUTHEAST, + Direction.SOUTH, + Direction.SOUTHWEST, + Direction.WEST, + Direction.NORTHWEST, + }; + + static int turnCount; + + /** + * run() is the method that is called when a robot is instantiated in the Battlecode world. + * If this method returns, the robot dies! + **/ + @SuppressWarnings("unused") + public static void run(RobotController rc) throws GameActionException { + + // This is the RobotController object. You use it to perform actions from this robot, + // and to get information on its current status. + RobotPlayer.rc = rc; + + turnCount = 0; + +// System.out.println("I'm a " + rc.getType() + " and I just got created!"); + while (true) { + turnCount += 1; + // Try/catch blocks stop unhandled exceptions, which cause your robot to freeze + try { + // Here, we've separated the controls into a different method for each RobotType. + // You may rewrite this into your own control structure if you wish. +// System.out.println("I'm a " + rc.getType() + "! Location " + rc.getLocation()); + switch (rc.getType()) { + case ENLIGHTENMENT_CENTER: runEnlightenmentCenter(); break; + case POLITICIAN: runPolitician(); break; + case SLANDERER: runSlanderer(); break; + case MUCKRAKER: runMuckraker(); break; + } + + // Clock.yield() makes the robot wait until the next turn, then it will perform this loop again + Clock.yield(); + + } catch (Exception e) { +// System.out.println(rc.getType() + " Exception"); + e.printStackTrace(); + } + } + } + + static void runEnlightenmentCenter() throws GameActionException { + RobotType toBuild = randomSpawnableRobotType(); + int influence = 50; + for (Direction dir : directions) { + if (rc.canBuildRobot(toBuild, dir, influence)) { + rc.buildRobot(toBuild, dir, influence); + } else { + break; + } + } + } + + static void runPolitician() throws GameActionException { + Team enemy = rc.getTeam().opponent(); + int actionRadius = rc.getType().actionRadiusSquared; + RobotInfo[] attackable = rc.senseNearbyRobots(actionRadius, enemy); + if (attackable.length != 0 && rc.canEmpower(actionRadius)) { +// System.out.println("empowering..."); + rc.empower(actionRadius); +// System.out.println("empowered"); + return; + } + if (tryMove(randomDirection())) { +// System.out.println("I moved!"); + } + } + + static void runSlanderer() throws GameActionException { + if (tryMove(randomDirection())) { +// System.out.println("I moved!"); + } + } + + static void runMuckraker() throws GameActionException { + Team enemy = rc.getTeam().opponent(); + int actionRadius = rc.getType().actionRadiusSquared; + for (RobotInfo robot : rc.senseNearbyRobots(actionRadius, enemy)) { + if (robot.type.canBeExposed()) { + // It's a slanderer... go get them! + if (rc.canExpose(robot.location)) { +// System.out.println("e x p o s e d"); + rc.expose(robot.location); + return; + } + } + } + if (tryMove(randomDirection())) { +// System.out.println("I moved!"); + } + } + + /** + * Returns a random Direction. + * + * @return a random Direction + */ + static Direction randomDirection() { + return directions[(int) (Math.random() * directions.length)]; + } + + /** + * Returns a random spawnable RobotType + * + * @return a random RobotType + */ + static RobotType randomSpawnableRobotType() { + return spawnableRobot[(int) (Math.random() * spawnableRobot.length)]; + } + + /** + * Attempts to move in a given direction. + * + * @param dir The intended direction of movement + * @return true if a move was performed + * @throws GameActionException + */ + static boolean tryMove(Direction dir) throws GameActionException { +// System.out.println("I am trying to move " + dir + "; " + rc.isReady() + " " + rc.getCooldownTurns() + " " + rc.canMove(dir)); + if (rc.canMove(dir)) { + rc.move(dir); + return true; + } else return false; + } + + + //////////////////////////////////////////////////////////////////////////// + // BASIC BUG - just follow the obstacle while it's in the way + // not the best bug, but works for "simple" obstacles + // for better bugs, think about Bug 2! + + static final double passabilityThreshold = 0.7; + static Direction bugDirection = null; + + static void basicBug(MapLocation target) throws GameActionException { + Direction d = rc.getLocation().directionTo(target); + if (rc.getLocation().equals(target)) { + // do something else, now that you're there + // here we'll just explode + if (rc.canEmpower(1)) { + rc.empower(1); + } + } else if (rc.isReady()) { + if (rc.canMove(d) && rc.sensePassability(rc.getLocation().add(d)) >= passabilityThreshold) { + rc.move(d); + bugDirection = null; + } else { + if (bugDirection == null) { + bugDirection = d; + } + for (int i = 0; i < 8; ++i) { + if (rc.canMove(bugDirection) && rc.sensePassability(rc.getLocation().add(bugDirection)) >= passabilityThreshold) { + rc.setIndicatorDot(rc.getLocation().add(bugDirection), 0, 255, 255); + rc.move(bugDirection); + bugDirection = bugDirection.rotateLeft(); + break; + } + rc.setIndicatorDot(rc.getLocation().add(bugDirection), 255, 0, 0); + bugDirection = bugDirection.rotateRight(); + } + } + } + } +} diff --git a/version.txt b/version.txt index 4b27b79..b625f1e 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2021.1.0.0 \ No newline at end of file +2021.2.0.2 \ No newline at end of file