修改严重问题

This commit is contained in:
zhoudaxia 2016-09-01 22:45:59 +08:00
parent 711da1c2e4
commit 01614f6152
6 changed files with 22 additions and 31 deletions

View File

@ -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;

View File

@ -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;

View File

@ -34,7 +34,7 @@ class BattleRecordInfo implements Serializable, IXmlSerializable {
int roundsCount;
BattleRules battleRules;
Integer[] turnsInRounds;
List<BattleResults> results;
transient List<BattleResults> results;
public void writeXml(XmlWriter writer, SerializableOptions options) throws IOException {
writer.startElement("recordInfo"); {

View File

@ -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;

View File

@ -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();

View File

@ -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;