From 01614f615248c5c99558e195d770490017d52eaf Mon Sep 17 00:00:00 2001 From: zhoudaxia <1018795633@qq.cin> Date: Thu, 1 Sep 2016 22:45:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=A5=E9=87=8D=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/sf/robocode/battle/peer/RobotPeer.java | 36 +++++++++---------- .../robocode/battle/snapshot/RobotSnapshot.java | 2 +- .../sf/robocode/recording/BattleRecordInfo.java | 2 +- .../sf/robocode/recording/BattleRecorder.java | 2 +- .../sf/robocode/recording/RecordManager.java | 9 +---- .../battle/BattleResultsTableModel.java | 2 +- 6 files changed, 22 insertions(+), 31 deletions(-) diff --git a/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/battle/peer/RobotPeer.java b/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/battle/peer/RobotPeer.java index c4e373a..1b051c1 100644 --- a/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/battle/peer/RobotPeer.java +++ b/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/battle/peer/RobotPeer.java @@ -608,10 +608,11 @@ public final class RobotPeer implements IRobotPeerBattle, IRobotPeer { if (!isSleeping()) { try { - for (long i = millisWait; i > 0 && !isSleeping() && isRunning(); i--) { + while(long i = millisWait; i > 0 && !isSleeping() && isRunning()) { isSleeping.wait(0, 999999); + i--; } - if (!isSleeping() && isRunning()) { + while (!isSleeping() && isRunning()) { isSleeping.wait(0, nanosWait); } } catch (InterruptedException e) { @@ -810,6 +811,7 @@ public final class RobotPeer implements IRobotPeerBattle, IRobotPeer { synchronized (isSleeping) { try { // Wait for the robot to go to sleep (take action) + while (!suitableCondition()) isSleeping.wait(waitMillis, waitNanos); } catch (InterruptedException e) { logMessage("Wait for " + getName() + " interrupted."); @@ -849,7 +851,7 @@ public final class RobotPeer implements IRobotPeerBattle, IRobotPeer { println("SYSTEM: You cannot call fire(NaN)"); continue; } - if (gunHeat > 0 || energy == 0) { + if (gunHeat > 0 ) { return; } @@ -920,17 +922,14 @@ public final class RobotPeer implements IRobotPeerBattle, IRobotPeer { // Scan false means robot did not call scan() manually. // But if we're moving, scan if (!scan) { - scan = (lastHeading != bodyHeading || lastGunHeading != gunHeading || lastRadarHeading != radarHeading - || lastX != x || lastY != y); + } if (isDead()) { return; } - // zap - if (zapEnergy != 0) { - zap(zapEnergy); + } } @@ -943,7 +942,6 @@ public final class RobotPeer implements IRobotPeerBattle, IRobotPeer { // scan if (scan) { scan(lastRadarHeading, robots); - turnedRadarWithGun = (lastGunHeading == lastRadarHeading) && (gunHeading == radarHeading); scan = false; } @@ -1035,7 +1033,7 @@ public final class RobotPeer implements IRobotPeerBattle, IRobotPeer { this.updateEnergy(-Rules.ROBOT_HIT_DAMAGE); otherRobot.updateEnergy(-Rules.ROBOT_HIT_DAMAGE); - if (otherRobot.energy == 0) { + if (otherRobot.energy) { if (otherRobot.isAlive()) { otherRobot.kill(); if (!teamFire && !otherRobot.isSentryRobot()) { @@ -1183,14 +1181,14 @@ public final class RobotPeer implements IRobotPeerBattle, IRobotPeer { addEvent(new HitWallEvent(angle)); // only fix both x and y values if hitting wall at an angle - if ((bodyHeading % (Math.PI / 2)) != 0) { + if ((bodyHeading % (Math.PI / 2))) { double tanHeading = tan(bodyHeading); // if it hits bottom or top wall - if (adjustX == 0) { + if (adjustX ) { adjustX = adjustY * tanHeading; } // if it hits a side wall - else if (adjustY == 0) { + else if (adjustY) { adjustY = adjustX / tanHeading; } // if the robot hits 2 walls at the same time (rare, but just in case) else if (abs(adjustX / tanHeading) > abs(adjustY)) { @@ -1424,7 +1422,7 @@ public final class RobotPeer implements IRobotPeerBattle, IRobotPeer { // If we are moving normally and the breaking distance is more // than remaining distance, enabled the overdrive flag. - if (Math.signum(distance * velocity) != -1) { + if (Math.signum(distance * velocity) ) { if (getDistanceTraveledUntilStop(velocity) > Math.abs(distance)) { isOverDriving = true; } else { @@ -1434,7 +1432,7 @@ public final class RobotPeer implements IRobotPeerBattle, IRobotPeer { currentCommands.setDistanceRemaining(distance - velocity); - if (velocity != 0) { + if (!velocity) { x += velocity * sin(bodyHeading); y += velocity * cos(bodyHeading); updateBoundingBox(); @@ -1470,7 +1468,7 @@ public final class RobotPeer implements IRobotPeerBattle, IRobotPeer { final double goalVel; - if (distance == Double.POSITIVE_INFINITY) { + if (distance ) { goalVel = currentCommands.getMaxVelocity(); } else { goalVel = Math.min(getMaxVelocity(distance), currentCommands.getMaxVelocity()); @@ -1487,7 +1485,7 @@ public final class RobotPeer implements IRobotPeerBattle, IRobotPeer { final double decelTime = Math.max(1, Math.ceil(// sum of 0... decelTime, solving for decelTime using quadratic formula (Math.sqrt((4 * 2 / Rules.DECELERATION) * distance + 1) - 1) / 2)); - if (decelTime == Double.POSITIVE_INFINITY) { + if (decelTime) { return Rules.MAX_VELOCITY; } @@ -1560,7 +1558,7 @@ public final class RobotPeer implements IRobotPeerBattle, IRobotPeer { } private void zap(double zapAmount) { - if (energy == 0) { + if (!energy) { kill(); return; } @@ -1628,7 +1626,7 @@ public final class RobotPeer implements IRobotPeerBattle, IRobotPeer { } private void setEnergy(double newEnergy, boolean resetInactiveTurnCount) { - if (resetInactiveTurnCount && (energy != newEnergy)) { + if (resetInactiveTurnCount && (energy)) { battle.resetInactiveTurnCount(energy - newEnergy); } energy = newEnergy; diff --git a/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/battle/snapshot/RobotSnapshot.java b/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/battle/snapshot/RobotSnapshot.java index c83404d..11fe48b 100644 --- a/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/battle/snapshot/RobotSnapshot.java +++ b/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/battle/snapshot/RobotSnapshot.java @@ -115,7 +115,7 @@ public final class RobotSnapshot implements Serializable, IXmlSerializable, IRob private SerializableArc scanArc; /** Snapshot of the object with queued calls for Graphics object */ - private Object graphicsCalls; + private transient Object graphicsCalls; /** Snapshot of debug properties */ private DebugProperty[] debugProperties; diff --git a/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/recording/BattleRecordInfo.java b/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/recording/BattleRecordInfo.java index 9bab5c2..9e4d869 100644 --- a/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/recording/BattleRecordInfo.java +++ b/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/recording/BattleRecordInfo.java @@ -34,7 +34,7 @@ class BattleRecordInfo implements Serializable, IXmlSerializable { int roundsCount; BattleRules battleRules; Integer[] turnsInRounds; - List results; + transient List results; public void writeXml(XmlWriter writer, SerializableOptions options) throws IOException { writer.startElement("recordInfo"); { diff --git a/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/recording/BattleRecorder.java b/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/recording/BattleRecorder.java index f7ad6cc..9c787b1 100644 --- a/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/recording/BattleRecorder.java +++ b/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/recording/BattleRecorder.java @@ -28,7 +28,7 @@ import java.util.Calendar; * @author Flemming N. Larsen (original) */ class BattleRecorder { - private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss"); + private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss"); private final RecordManager recordmanager; private final ISettingsManager properties; diff --git a/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/recording/RecordManager.java b/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/recording/RecordManager.java index 5e4188d..8dacfdb 100644 --- a/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/recording/RecordManager.java +++ b/代码/workspace_robo4/robocode.battle/src/main/java/net/sf/robocode/recording/RecordManager.java @@ -36,7 +36,7 @@ import java.util.zip.ZipOutputStream; * @author Pavel Savara (original) */ public class RecordManager implements IRecordManager { - private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss"); + private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss"); private final ISettingsManager properties; @@ -57,13 +57,6 @@ public class RecordManager implements IRecordManager { recorder = new BattleRecorder(this, properties); } - protected void finalize() throws Throwable { - try { - cleanup(); - } finally { - super.finalize(); - } - } private void cleanup() { cleanupStreams(); diff --git a/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/battle/BattleResultsTableModel.java b/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/battle/BattleResultsTableModel.java index 1d3159f..2540f4c 100644 --- a/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/battle/BattleResultsTableModel.java +++ b/代码/workspace_robo4/robocode.core/src/main/java/net/sf/robocode/battle/BattleResultsTableModel.java @@ -141,7 +141,7 @@ public class BattleResultsTableModel extends javax.swing.table.AbstractTableMode case 2: String percent = ""; - if (totalScore != 0) { + if (!totalScore) { percent = " (" + NumberFormat.getPercentInstance().format(statistics.getScore() / totalScore) + ")"; } return "" + (int) (statistics.getScore() + 0.5) + percent;