• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Utils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中robocode.util.Utils的典型用法代码示例。如果您正苦于以下问题:Java Utils类的具体用法?Java Utils怎么用?Java Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Utils类属于robocode.util包,在下文中一共展示了Utils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: onScannedRobot

import robocode.util.Utils; //导入依赖的package包/类
/**
 * onScannedRobot: What to do when you see another robot
 */

public void onScannedRobot(ScannedRobotEvent e) {
    if (getGunHeat()>0){
        randMove();
        }
    double absBearing = getHeadingRadians() + e.getBearingRadians();
    double radarTurn = absBearing - getRadarHeadingRadians();
    setTurnRadarRightRadians(2 * Utils.normalRelativeAngle(radarTurn));
    setTurnGunRight(getHeading() - getGunHeading() + e.getBearing());
    double radarLowerBound = getRadarHeadingRadians() - (Math.PI / 6);
    double radarUpperBound = getRadarHeadingRadians() + (Math.PI / 6);
    if (getGunHeadingRadians() < radarUpperBound && getGunHeadingRadians() > radarLowerBound) {
        setFire(Math.min(400 / e.getDistance(), 3));
    }   
    
}
 
开发者ID:pseminatore,项目名称:asda,代码行数:20,代码来源:AlphaBotCorndog.java


示例2: getAngularVelocity

import robocode.util.Utils; //导入依赖的package包/类
public static double getAngularVelocity(double headingBefore,
        double headingAfter, long timeBefore, long timeAfter) {
    if (timeBefore >= timeAfter) {
        return 0;
    }

    if (Utils.isNear(headingBefore, headingAfter)) {
        return 0;
    }

    double ret = getBearing(headingBefore, headingAfter);
    while (ret > Math.PI) {
        ret -= Math.PI * 2;
    }

    return ret / (timeAfter - timeBefore);
}
 
开发者ID:BenDoan,项目名称:OgorSheeptipper,代码行数:18,代码来源:MathUtils.java


示例3: act

import robocode.util.Utils; //导入依赖的package包/类
@Override
public void act() {
    ArrayList<RadialForce> forces = getRobotForces();

    Point2D.Double vector = getTotalForceVector(forces);

    double turnAngle = getTurnAngle(vector);

    if (Math.abs(getTurnAngle(vector)) > (Math.PI / 2)) {// go backwards
        robot.setAhead(-1000);
        robot.setTurnRightRadians(-Utils.normalRelativeAngle(turnAngle));
    } else {//go forwards
        robot.setAhead(1000);
        robot.setTurnRightRadians(Utils.normalRelativeAngle(turnAngle));
    }
}
 
开发者ID:BenDoan,项目名称:OgorSheeptipper,代码行数:17,代码来源:AntigravityWheel.java


示例4: handleScannedRobotEvent

import robocode.util.Utils; //导入依赖的package包/类
@Override
public void handleScannedRobotEvent(final ScannedRobotEvent e)
{


	double gunTurn =
			// Absolute bearing to target
			(this.getRobot().getHeadingRadians() + e.getBearingRadians())
			// Subtract current gun heading to get turn required
			- this.getRobot().getGunHeadingRadians();

	this.getRobot().setTurnGunRightRadians(
			Utils.normalRelativeAngle(gunTurn));

	//getRobot().setFire(Rules.MAX_BULLET_POWER * 75 / e.getDistance());
	this.getRobot().setFire(Rules.MAX_BULLET_POWER);
}
 
开发者ID:philippsander,项目名称:robocode_robot,代码行数:18,代码来源:SimpleDirectionGun.java


示例5: handleScannedRobotEvent

import robocode.util.Utils; //导入依赖的package包/类
public ScannedRobotEvent handleScannedRobotEvent(final ScannedRobotEvent e)
{
    // Absolute angle towards target
    double angleToEnemy = getRobot().getHeadingRadians() + e.getBearingRadians();

    // Subtract current radar heading to get the turn required to face the enemy, be sure it is normalized
    double radarTurn = Utils.normalRelativeAngle( angleToEnemy - getRobot().getRadarHeadingRadians() );

    // Distance we want to scan from middle of enemy to either side
    // The 36.0 is how many units from the center of the enemy robot it scans.
    double extraTurn = Math.min( Math.atan( 36.0 / e.getDistance() ), Rules.RADAR_TURN_RATE_RADIANS );

    // Adjust the radar turn so it goes that much further in the direction it is going to turn
    // Basically if we were going to turn it left, turn it even more left, if right, turn more right.
    // This allows us to overshoot our enemy so that we get a good sweep that will not slip.
    radarTurn += (radarTurn < 0 ? -extraTurn : extraTurn);

    //Turn the radar
    getRobot().setTurnRadarRightRadians(radarTurn);

	return e;
}
 
开发者ID:philippsander,项目名称:robocode_robot,代码行数:23,代码来源:WidthLock.java


示例6: onScannedRobot

import robocode.util.Utils; //导入依赖的package包/类
public void onScannedRobot(ScannedRobotEvent e) {
	//input = new double[numInputs];
	double radarTurn =
        // Absolute bearing to target
        getHeadingRadians() + e.getBearingRadians()
        // Subtract current radar heading to get turn required
        - getRadarHeadingRadians();
 
    setTurnRadarRightRadians(Utils.normalRelativeAngle(radarTurn));
	
	out.println("Starting a scan");
	input[2] = scaleDown(e.getBearingRadians(),-Math.PI,Math.PI);
	//input[3] = scaleDown(e.getDistance(),0,Rules.RADAR_SCAN_RADIUS);
	//input[4] = scaleDown(e.getVelocity(),0,Rules.MAX_VELOCITY);
	//input[5] = scaleDown(e.getHeadingRadians(),0,2*Math.PI);
	
    
	//run();
    //scan();
    // ...
   // out.println("Finished Scan");
}
 
开发者ID:atyndall,项目名称:cits4404,代码行数:23,代码来源:NeuroTargetingBot.java


示例7: onScannedRobot

import robocode.util.Utils; //导入依赖的package包/类
public void onScannedRobot(ScannedRobotEvent e) {
	//input = new double[numInputs];
	double radarTurn =
        // Absolute bearing to target
        getHeadingRadians() + e.getBearingRadians()
        // Subtract current radar heading to get turn required
        - getRadarHeadingRadians();
 
    setTurnRadarRightRadians(Utils.normalRelativeAngle(radarTurn));
	
	out.println("Starting a scan");
	input[6] = scaleDown(e.getBearing(),0,360);
	input[7] = scaleDown(e.getDistance(),0,Rules.RADAR_SCAN_RADIUS);
	input[8] = scaleDown(e.getEnergy(),0,100);
	input[9] = scaleDown(e.getHeading(),0,360);
	
    
	//run();
    //scan();
    // ...
   // out.println("Finished Scan");
}
 
开发者ID:atyndall,项目名称:cits4404,代码行数:23,代码来源:NeuroBot.java


示例8: onScannedRobot

import robocode.util.Utils; //导入依赖的package包/类
public void onScannedRobot(ScannedRobotEvent e) {
	//input = new double[numInputs];
	double radarTurn =
        // Absolute bearing to target
        getHeadingRadians() + e.getBearingRadians()
        // Subtract current radar heading to get turn required
        - getRadarHeadingRadians();
 
    setTurnRadarRightRadians(Utils.normalRelativeAngle(radarTurn));
	
	out.println("Starting a scan");
	input[0] = scaleDown(e.getDistance(),0,Rules.RADAR_SCAN_RADIUS);
	input[1] = scaleDown(e.getEnergy(),0,Rules.MAX_VELOCITY);
	
	setTurnRight((e.getBearing() + 90)*direction);
    
	//run();
    //scan();
    // ...
   // out.println("Finished Scan");
}
 
开发者ID:atyndall,项目名称:cits4404,代码行数:22,代码来源:NeuroStrafingBot.java


示例9: onScannedRobot

import robocode.util.Utils; //导入依赖的package包/类
public void onScannedRobot(ScannedRobotEvent e) {
    double radarTurn =
        // Absolute bearing to target
        getHeadingRadians() + e.getBearingRadians()
        // Subtract current radar heading to get turn required
        - getRadarHeadingRadians();
    
    double gunTurn =
        // Absolute bearing to target
        getHeadingRadians() + e.getBearingRadians()
        // Subtract current radar heading to get turn required
        - getGunHeadingRadians() + gunTurnVariance;
 
    setTurnRadarRightRadians(Utils.normalRelativeAngle(radarTurn));
    setTurnGunRightRadians(Utils.normalRelativeAngle(gunTurn));
 
    //do other things you want to do per scan
    //you can do them before or after the above scanning code
}
 
开发者ID:atyndall,项目名称:cits4404,代码行数:20,代码来源:GABot.java


示例10: run

import robocode.util.Utils; //导入依赖的package包/类
public void run() {
	setAdjustRadarForGunTurn(true);
	setAdjustGunForRobotTurn(true);
	
	_bfWidth = getBattleFieldWidth();
	_bfHeight = getBattleFieldHeight();

	while (true) {
		turnRadarRightRadians(Double.POSITIVE_INFINITY);
		ahead(1000);

		double nextAngle = wallSmoothing(getX(), getY(), 0, 1, 1);
		turnRight(Utils.normalAbsoluteAngle(nextAngle));
	}
}
 
开发者ID:chips11589,项目名称:robochips,代码行数:16,代码来源:AlphaLead.java


示例11: onScannedRobot

import robocode.util.Utils; //导入依赖的package包/类
public void onScannedRobot(ScannedRobotEvent e) {
	double targetAbsoluteBearing = getHeadingRadians() + e.getBearingRadians();

	// Absolute bearing to target subtracts current radar heading to get turn
	// required
	double radarTurn = targetAbsoluteBearing - getRadarHeadingRadians();

	setTurnGunRightRadians(Utils.normalRelativeAngle(targetAbsoluteBearing - getGunHeadingRadians()));
	setFire(2);

	setTurnRadarRightRadians(Utils.normalRelativeAngle(radarTurn) * 2);
}
 
开发者ID:chips11589,项目名称:robochips,代码行数:13,代码来源:AlphaLead.java


示例12: checkHit

import robocode.util.Utils; //导入依赖的package包/类
public boolean checkHit(double enemyX, double enemyY, long currentTime){
    if (Point2D.distance(startX, startY, enemyX, enemyY) <= (currentTime - fireTime) * getBulletSpeed()){
        double desiredDirection = Math.atan2(enemyX - startX, enemyY - startY);
        double angleOffset = Utils.normalRelativeAngle(desiredDirection - startBearing);
        double guessFactor = Math.max(-1, Math.min(1, angleOffset / maxEscapeAngle())) * direction;
        int index = (int) Math.round((returnSegment.length - 1) / 2 * (guessFactor + 1));
        returnSegment[index]++;
        return true;
    }
    return false;
}
 
开发者ID:BenDoan,项目名称:OgorSheeptipper,代码行数:12,代码来源:WaveBullet.java


示例13: fireAt

import robocode.util.Utils; //导入依赖的package包/类
private void fireAt(ScannedRobotEvent event) {
    if (event.getName().equals(Observer.TARGET)) {

        if (NearestNeighborSelector.disabledBotExists()) {
            this.bulletPower = Rules.MIN_BULLET_POWER; // set bullet power to min, and snipe disabled robot
        } else if (event.getDistance() < 200) {
            this.bulletPower = Rules.MAX_BULLET_POWER; // set bullet power to max when target is close
        } else if (event.getDistance() < this.range) {
            this.bulletPower = 2;
        } else {
            //this.bulletPower = Rules.MIN_BULLET_POWER; // set bullet power to min when target is far
            return;
        }

        // paint target with a red circle
        Point2D.Double location = MathUtils.getLocation(robot, event.getBearingRadians(), event.getDistance());
        Util.paintCircle(robot, location.getX(), location.getY(), 30, Color.red);

        distanceToTarget = event.getDistance();


        double absoluteBearing = robot.getHeadingRadians()
                + event.getBearingRadians();

        double BulletFudgeFactor = this.bulletPower * 3;

        robot.setTurnGunRightRadians(
            Utils.normalRelativeAngle(
                absoluteBearing - robot.getGunHeadingRadians() + (event.getVelocity() * Math.sin(event.getHeadingRadians() - absoluteBearing) / BulletFudgeFactor)
            )
        );


        System.out.println("Firing with power: " + this.bulletPower);
        robot.setFire(this.bulletPower);
    }
}
 
开发者ID:BenDoan,项目名称:OgorSheeptipper,代码行数:38,代码来源:LinearGun.java


示例14: fireAt

import robocode.util.Utils; //导入依赖的package包/类
private void fireAt(ScannedRobotEvent event) {
    if (event.getName().equals(Observer.TARGET)) {

        // paint target with a red circle
        Point2D.Double location = MathUtils.getLocation(robot, event.getBearingRadians(), event.getDistance());
        Util.paintCircle(robot, location.getX(), location.getY(), 30, Color.red);

        distanceToTarget = event.getDistance();


        double absoluteBearing = robot.getHeadingRadians()
                + event.getBearingRadians();

        double BulletFudgeFactor = this.bulletPower * 3;

        robot.setTurnGunRightRadians(
            Utils.normalRelativeAngle(
                absoluteBearing - robot.getGunHeadingRadians() + (event.getVelocity() * Math.sin(event.getHeadingRadians() - absoluteBearing) / BulletFudgeFactor)
            )
        );

        if (NearestNeighborSelector.disabledBotExists()) {
            this.bulletPower = Rules.MIN_BULLET_POWER; // set bullet power to min, and snipe disabled robot
        } else if (event.getDistance() < this.range) {
            this.bulletPower = Rules.MAX_BULLET_POWER; // set bullet power to max when target is close
        } else {
            //this.bulletPower = Rules.MIN_BULLET_POWER; // set bullet power to min when target is far
            return;
        }

        robot.setFire(this.bulletPower);
    }
}
 
开发者ID:BenDoan,项目名称:OgorSheeptipper,代码行数:34,代码来源:CircularGun.java


示例15: getBearing

import robocode.util.Utils; //导入依赖的package包/类
public static double getBearing(double from, double to) {
    double ret = Utils.normalAbsoluteAngle(to - from);
    while (ret > Math.PI) {
        ret -= Math.PI * 2;
    }
    return ret;
}
 
开发者ID:BenDoan,项目名称:OgorSheeptipper,代码行数:8,代码来源:MathUtils.java


示例16: handleScannedRobotEvent

import robocode.util.Utils; //导入依赖的package包/类
@Override
public ScannedRobotEvent handleScannedRobotEvent(final ScannedRobotEvent e) {
	double radarTurn =
	// Absolute bearing to target
	(getRobot().getHeadingRadians() + e.getBearingRadians())
	// Subtract current radar heading to get turn required
			- getRobot().getRadarHeadingRadians();

	getRobot().setTurnRadarRightRadians(
			Utils.normalRelativeAngle(radarTurn));

	return e;
}
 
开发者ID:philippsander,项目名称:robocode_robot,代码行数:14,代码来源:TurnMultiplierLock.java


示例17: move

import robocode.util.Utils; //导入依赖的package包/类
@Override
public void move() {
	double bearing = Utils.normalRelativeAngle(getRobot()
			.getRadarHeadingRadians() - getRobot().getHeadingRadians());

	getRobot().setTurnRightRadians(bearing);

	getRobot().setAhead(40000);

	getRobot().waitFor(new TurnCompleteCondition(getRobot()));
}
 
开发者ID:philippsander,项目名称:robocode_robot,代码行数:12,代码来源:RamTracks.java


示例18: onScannedRobot

import robocode.util.Utils; //导入依赖的package包/类
/**
 * Tracks, records energy levels of, and fires upon enemy robots.
 * 
 * @param evt The event that is generated when this robot scans another robot.
 */
@Override
public void onScannedRobot(ScannedRobotEvent evt) {
  if (!nearWall) {
    // Square off against enemy
    // From http://mark.random-article.com/robocode/basic_movement.html
    this.setTurnRight(evt.getBearing() + 90);

    // If we havn't scanned this robot before, add it to known robots.
    if (!this.scannedRobots.containsKey(evt.getName())) {
      this.scannedRobots.put(evt.getName(), new ArrayList<Double>());
    }

    // Store the robots energy
    this.scannedRobots.get(evt.getName()).add(evt.getEnergy());

    // Determine relative angles needed to turn radar and gun, and then turn them.
    double radarTurnAngle =
        RobotUtilities.getTargetTurnAngle(super.getHeading(), this.getRadarHeading(),
            evt.getBearing());
    double gunTurnAngle =
        RobotUtilities.getTargetTurnAngle(super.getHeading(), this.getGunHeading(),
            evt.getBearing());

    this.setTurnRadarRight(Utils.normalRelativeAngleDegrees(radarTurnAngle));
    this.setTurnGunRight(Utils.normalRelativeAngleDegrees(gunTurnAngle));
    
    // Make sure our gun is actually pointing at the robot before firing
    // Also ensure that the gun is cool before firing
    // Inspired from http://mark.random-article.com/robocode/basic_targeting.html
    if (Math.abs(this.getGunTurnRemaining()) < 5 && this.getGunHeat() == 0) {
      this.setFire(utils.getProportionalFirePower(evt.getDistance()));
    }
    this.execute();
  }
}
 
开发者ID:anthonyjchriste,项目名称:robocode-ajc-wrathofpele,代码行数:41,代码来源:WrathOfPele.java


示例19: onScannedRobot

import robocode.util.Utils; //导入依赖的package包/类
public void onScannedRobot(ScannedRobotEvent e) {
    double radarTurn =
        // Absolute bearing to target
        getHeadingRadians() + e.getBearingRadians()
        // Subtract current radar heading to get turn required
        - getRadarHeadingRadians();
 
    setTurnRadarRightRadians(Utils.normalRelativeAngle(radarTurn));
 
    //do other things you want to do per scan
    //you can do them before or after the above scanning code
}
 
开发者ID:atyndall,项目名称:cits4404,代码行数:13,代码来源:ScanningBot.java


示例20: backoff

import robocode.util.Utils; //导入依赖的package包/类
/**
 * We do a little set of "safety" moves if something bad happens, to prevent complete system failure
 */
private void backoff() {
	int half = (int)Math.min(getBattleFieldHeight(), getBattleFieldWidth()) / 2;
	setStop();
	setBack(Utils.getRandom().nextInt(half) + 36);
	setTurnRight(Utils.getRandom().nextInt(360));
	setResume();
	setAhead(30);
}
 
开发者ID:atyndall,项目名称:cits4404,代码行数:12,代码来源:GABot.java



注:本文中的robocode.util.Utils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java QualifiedTypeReference类代码示例发布时间:2022-05-23
下一篇:
Java IHyperlinkHelper类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap