资源简介
玩robocode的话,这个坦克在业余里很厉害
代码片段和文件信息
/*
* Alipay.com Inc.
* Copyright (c) 2004-2005 All Rights Reserved.
*/
package xingyuan;
import java.awt.Color;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import robocode.AdvancedRobot;
import robocode.BulletHitEvent;
import robocode.BulletMissedEvent;
import robocode.Condition;
import robocode.DeathEvent;
import robocode.HitByBulletEvent;
import robocode.HitWallEvent;
import robocode.Rules;
import robocode.ScannedRobotEvent;
import robocode.util.Utils;
/**
*
* 剑齿虎机器人坦克
*
* @author Alcor
* @version $Id: Smilodon.java v 1.0 2009-6-11 下午04:24:38 Alcor Exp $
*/
public class Smilodon extends AdvancedRobot {
private static final double BEST_DISTANCE = 520;
private static final int GF_ZERO = 15;
private static final int GF_ONE = 30;
private static double FIELD_WIDTH;
private static double FIELD_HEIGHT;
private static Rectangle2D.Double FIELD;
private static Point2D.Double enemyLocation;
private static int[][][][][] guessFactors = new int[6][3][2][8][GF_ONE + 1];
private static boolean flat = false;
private int movementDirection = 1;
private double maxPower = 1;
private double lastVChangeTime;
private int menace;
private Point2D.Double location;
private double bodyHeading;
private double distance absBearing;
private double enemyHeading enemyEnergy enemyFirePower;
private int enemyVelocity;
@Override
public void run() {
super.run();
setColors(Color.BLACK Color.WHITE Color.BLACK Color.BLACK Color.BLACK);
setAdjustGunForRobotTurn(true);
setAdjustRadarForGunTurn(true);
setAdjustRadarForRobotTurn(true);
FIELD_WIDTH = getBattleFieldWidth();
FIELD_HEIGHT = getBattleFieldHeight();
FIELD = new Rectangle2D.Double(20 20 FIELD_WIDTH - 40 FIELD_HEIGHT - 40);
while (true) {
turnRadarRightRadians(Double.POSITIVE_INFINITY);
}
}
@Override
public void onScannedRobot(ScannedRobotEvent e) {
super.onScannedRobot(e);
startTurn(e);
radarScan();
moveRadio();
firePredict(e.getVelocity());
}
@Override
public void onDeath(DeathEvent e) {
flat = flat || getRoundNum() < 5;
}
@Override
public void onBulletHit(BulletHitEvent event) {
super.onBulletHit(event);
if (maxPower < 3) {
maxPower += 1;
}
}
@Override
public void onBulletMissed(BulletMissedEvent event) {
super.onBulletMissed(event);
if (maxPower > 1) {
maxPower -= 0.5;
评论
共有 条评论