本文整理汇总了Java中battlecode.common.GameActionException类的典型用法代码示例。如果您正苦于以下问题:Java GameActionException类的具体用法?Java GameActionException怎么用?Java GameActionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GameActionException类属于battlecode.common包,在下文中一共展示了GameActionException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: circulate
import battlecode.common.GameActionException; //导入依赖的package包/类
private void circulate(MapLocation center) {
int distance = myLoc.distanceSquaredTo(center);
if (distance >= MIN_CIRCULATE && distance <= MAX_CIRCULATE) {
doRandomMove();
} else {
if (distance < MIN_CIRCULATE) {
pathFinderGreedy
.setTarget(myLoc.add(center.directionTo(myLoc)));
try {
pathFinderGreedy.move();
} catch (GameActionException e) {
e.printStackTrace();
}
} else {
doAStarMoveTo(center);
}
}
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:19,代码来源:Soldier.java
示例2: run
import battlecode.common.GameActionException; //导入依赖的package包/类
public static void run(RobotController rc) throws GameActionException {
AbstractRobotType robot;
switch (rc.getType()) {
case NOISETOWER:
robot = new NoiseTower(rc);
break;
case PASTR:
robot = new Pastr(rc);
break;
case SOLDIER:
if (!Channel.isAlive(rc, Core.id)) {
robot = new Core(rc);
} else {
robot = new Soldier(rc);
}
break;
// case HQ:
default:
robot = new HQ(rc);
}
robot.run();
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:23,代码来源:RobotPlayer.java
示例3: move
import battlecode.common.GameActionException; //导入依赖的package包/类
@Override
public boolean move() throws GameActionException {
if (path.isEmpty()) {
return false;
} else {
MapLocation myLoc = rc.getLocation();
while (myLoc.equals(path.peek())) {
// we are already here due to some movement performed outside of
// this class
path.pop();
}
if (!myLoc.isAdjacentTo(path.peek())) {
path = aStar(myLoc, target);
}
MapLocation next = path.peek();
Direction dir = rc.getLocation().directionTo(next);
if (rc.canMove(dir)) {
rc.move(dir);
path.pop();
return true;
} else {
return false;
}
}
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:26,代码来源:PathFinderAStar.java
示例4: init
import battlecode.common.GameActionException; //导入依赖的package包/类
@Override
protected void init() throws GameActionException {
height = rc.getMapHeight();
width = rc.getMapWidth();
myHq = rc.senseHQLocation();
otherHq = rc.senseEnemyHQLocation();
// location between our HQ and opponent's HQ:
MapLocation temporaryTarget = new MapLocation(
(myHq.x * 3 / 4 + otherHq.x / 4),
(myHq.y * 3 / 4 + otherHq.y / 4));
Channel.broadcastBestPastrLocation(rc, temporaryTarget);
mapAnalyzer = new MapAnalyzer(rc, myHq, otherHq, height, width);
// mapAnalyzer.generateRealDistanceMap();
// mapAnalyzer.printMapAnalysisDistance();
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:19,代码来源:HQ.java
示例5: run
import battlecode.common.GameActionException; //导入依赖的package包/类
public static void run(RobotController rc) throws GameActionException {
AbstractRobotType robot;
switch (rc.getType()) {
case NOISETOWER:
robot = new NoiseTower(rc);
break;
case PASTR:
robot = new Pastr(rc);
break;
case SOLDIER:
robot = new Soldier(rc);
break;
// case HQ:
default:
robot = new HQ(rc);
}
robot.run();
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:19,代码来源:RobotPlayer.java
示例6: broadcastFailure
import battlecode.common.GameActionException; //导入依赖的package包/类
/**
* broadcast based on current end state. Does nothing for -1 (uninit-ed) and
* 0 (success). Also clears pasture point after.
*
* @throws GameActionException
*/
public void broadcastFailure() throws GameActionException {
switch (endState) {
case 1:
hqResponse.broadcastMsg(MessageType.PROBLEM_BUGGING,
rc.getLocation());
break;
case 2:
case 3:
hqResponse.broadcastMsg(MessageType.INTERCEPTED_BY_ENEMY,
rc.getLocation()); // TODO difference for aggressive
// intercept
break;
case 4:
hqResponse.broadcastMsg(MessageType.LOCATION_HAS_ENEMY, buildPoint);
break;
default:
break;
}
clear();
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:27,代码来源:NoiseTowerBuilder.java
示例7: act
import battlecode.common.GameActionException; //导入依赖的package包/类
/**
* Returns whether we want to stay in this state
*
* On returning false, stores reason in endState as an int
*
* @return whether we want to stay in pasture building state
* @throws GameActionException
*/
public boolean act() throws GameActionException {
if (buildPoint == null) {
clear();
endState = -1;
return false;
}
MapLocation curLoc = rc.getLocation();
if (nearedPoint) {
// Trying to build pasture
return actClose(curLoc);
} else {
if (curLoc.distanceSquaredTo(buildPoint) <= senseRadiusSquared) {
// switch states
nearedPoint = true;
return actClose(curLoc);
} else {
// Trying to get to location
return actFar(curLoc);
}
}
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:32,代码来源:NoiseTowerBuilder.java
示例8: attackWeakest
import battlecode.common.GameActionException; //导入依赖的package包/类
public MapLocation attackWeakest() throws GameActionException {
if (enemyRobotsInAttackRange.length == 0) {
return null;
}
if (enemyRobotsInAttackRange.length == 1) {
RobotInfo rInfo = rc.senseRobotInfo(enemyRobotsInAttackRange[0]);
if (rInfo.type == RobotType.HQ) {
return null;
}
return rInfo.location;
} else {
Robot currWeakest = enemyRobotsInAttackRange[0];
for (Robot r : enemyRobotsInAttackRange) {
if (rc.senseRobotInfo(r).health < rc
.senseRobotInfo(currWeakest).health) {
currWeakest = r;
}
}
return rc.senseRobotInfo(currWeakest).location;
}
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:22,代码来源:SoldierAttacker.java
示例9: announceSoldierRole
import battlecode.common.GameActionException; //导入依赖的package包/类
/**
* this method should be used by soldiers. They have to announce the
* {@link SoldierRole} that they incorporate.
*
* @param rc
* @param role
*/
public static void announceSoldierRole(RobotController rc, SoldierRole role) {
int chCurrent;
switch (role) {
case ATTACKER:
chCurrent = chCurrentAttackerCount;
break;
case NOISE_TOWER_BUILDER:
chCurrent = chCurrentNoiseTowerBuilderCount;
break;
case PASTR_BUILDER:
chCurrent = chCurrentPastrBuilderCount;
break;
default: // case PROTECTOR
chCurrent = chCurrentProtectorCount;
}
try {
rc.broadcast(chCurrent, rc.readBroadcast(chCurrent) + 1);
} catch (GameActionException e) {
e.printStackTrace();
}
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:29,代码来源:Channel.java
示例10: chase
import battlecode.common.GameActionException; //导入依赖的package包/类
public Direction chase() throws GameActionException {
cur = rc.getLocation();
// (r+2)^2 ~= r^2 + 20 if r ~ 4
if (m.inDangerRadius(cur)) {
// too close to splash range
return Direction.NONE;
}
Robot[] en = sensor.getBots(Sensor.ATTACK_RANGE_ENEMIES);
if (en.length > 0) {
return chaseClosest(en);
}
en = sensor.getBots(Sensor.SENSE_RANGE_ENEMIES);
if (en.length > 0) {
return chaseClosest(en);
}
// no enemies
return Direction.OMNI;
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:21,代码来源:Chaser.java
示例11: announceSoldierType
import battlecode.common.GameActionException; //导入依赖的package包/类
/**
* this method should be used by any robot. They have to announce the
* {@link RobotType} that they incorporate.
*
* @param rc
* @param role
*/
public static void announceSoldierType(RobotController rc, RobotType type) {
int chCurrent;
switch (type) {
case SOLDIER:
chCurrent = chCurrentSoldierCount;
break;
case NOISETOWER:
chCurrent = chCurrentNoiseTowerCount;
break;
case PASTR:
chCurrent = chCurrentPastrCount;
break;
default: // case HQ
// should never happen... otherwise misc channel
chCurrent = chMisc;
}
try {
rc.broadcast(chCurrent, rc.readBroadcast(chCurrent) + 1);
} catch (GameActionException e) {
e.printStackTrace();
}
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:30,代码来源:Channel.java
示例12: needSelfDestruction
import battlecode.common.GameActionException; //导入依赖的package包/类
public static boolean needSelfDestruction(RobotController rc) {
int data = 0;
try {
data = rc.readBroadcast(chSelfDestruction);
MapLocation selfDestruction = new MapLocation(data / 1000,
data % 1000);
if (rc.canSenseSquare(selfDestruction)) {
GameObject stillAlive = rc
.senseObjectAtLocation(selfDestruction);
if (stillAlive == null) {
rc.broadcast(chSelfDestruction, 0);
data = 0;
}
}
} catch (GameActionException e) {
e.printStackTrace();
}
if (data == 0) {
return false;
} else {
return true;
}
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:25,代码来源:Channel.java
示例13: construct
import battlecode.common.GameActionException; //导入依赖的package包/类
static void construct(RobotType t) throws GameActionException {
switch (t) {
case NOISETOWER:
add(-1, casteChannel + NTREQ);
rc.construct(RobotType.NOISETOWER);
while (true) {
add(1, QUEUEDNOISETOWER);
rc.yield();
}
default:
add(-1, casteChannel + PASTRREQ);
rc.construct(RobotType.PASTR);
while (true) {
add(1, QUEUEDPASTR);
rc.yield();
}
}
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:19,代码来源:Soldier.java
示例14: turn
import battlecode.common.GameActionException; //导入依赖的package包/类
private static void turn() throws GameActionException {
updateStrategicInfo();
// First turn gets special treatment: spawn then do a bunch of
// computation
// (which we devoutly hope will finished before the spawn timer is up
// and before anyone attacks us).
if (Clock.getRoundNum() == 0) {
doFirstTurn();
return;
}
if (rc.isActive())
attackEnemies();
if (rc.isActive() && !wearingHat && Clock.getBytecodeNum() < 3000) {
rc.wearHat();
wearingHat = true;
}
if (rc.isActive())
spawnSoldier();
directStrategy();
pathfindWithSpareBytecodes();
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:26,代码来源:BotHQ.java
示例15: broadcastFailure
import battlecode.common.GameActionException; //导入依赖的package包/类
/**
* broadcast based on current end state. Does nothing for -1 (uninit-ed) and
* 0 (success). Also clears pasture point after.
*
* @throws GameActionException
*/
public void broadcastFailure() throws GameActionException {
switch (endState) {
case 1:
hqResponse.broadcastMsg(MessageType.PROBLEM_BUGGING,
rc.getLocation());
break;
case 2:
case 3:
hqResponse.broadcastMsg(MessageType.INTERCEPTED_BY_ENEMY,
rc.getLocation()); // TODO difference for aggressive
// intercept
break;
case 4:
hqResponse.broadcastMsg(MessageType.LOCATION_HAS_ENEMY,
rc.getLocation());
break;
default:
break;
}
clear();
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:28,代码来源:DisrupterBuilder.java
示例16: act
import battlecode.common.GameActionException; //导入依赖的package包/类
/**
* Returns whether we want to stay in this state
*
* On returning false, stores reason in endState as an int
*
* @return whether we want to stay in pasture building state
* @throws GameActionException
*/
public boolean act() throws GameActionException {
if (pasturePoint == null) {
// Wasn't given a place
clear();
endState = -1;
return false;
}
MapLocation curLoc = rc.getLocation();
if (!far) {
// Trying to go out
if (curLoc.distanceSquaredTo(pasturePoint) >= noiseTowerRange / 4) { // MAGIC
// CONSTANT
// switch states
initFar(curLoc);
return actFar(curLoc);
}
return actClose(curLoc);
} else {
return actFar(curLoc);
}
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:32,代码来源:DisrupterBuilder.java
示例17: act
import battlecode.common.GameActionException; //导入依赖的package包/类
@Override
protected void act() throws GameActionException {
Channel.signalAlive(rc, id);
myLoc = rc.getLocation();
updateTask();
if (inactive || !rc.isActive()) {
return;
}
if (rc.isConstructing()) {
if (task.equals(Task.BUILD_PASTR))
Channel.broadcastTask(rc, Task.BUILD_NOISETOWER, target, teamId);
else if (task.equals(Task.BUILD_NOISETOWER)) {
MapLocation newTarget = target.add(target.directionTo(enemyHq),
3);
Channel.broadcastTask(rc, Task.ACCUMULATE, newTarget, teamId);
}
inactive = true;
return;
}
actMicro(target, task);
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:22,代码来源:Soldier.java
示例18: defendClose
import battlecode.common.GameActionException; //导入依赖的package包/类
public boolean defendClose(Robot[] enemies) throws GameActionException {
// back up cause they gonna blow
MapLocation enemy = rc.senseRobotInfo(enemies[0]).location;
MapLocation cur = rc.getLocation();
Direction desired = enemy.directionTo(cur);
Direction moveAway = m.moveInDir(desired);
if (moveAway != Direction.NONE) {
rc.move(moveAway);
return true;
}
// move up to meet them.
Direction moveTowards = m.moveInDir(desired.opposite());
if (moveTowards != Direction.NONE) {
rc.move(moveTowards);
return true;
}
RobotInfo targetInfo = attacker.attackOptimal();
if (targetInfo != null) {
rc.attackSquare(targetInfo.location);
}
// reposition
return true;
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:27,代码来源:Defender.java
示例19: denyPasture
import battlecode.common.GameActionException; //导入依赖的package包/类
/**
* Check if pasture is 1 hit. Will attack square if in range. No check on if
* we can attack
*
* @return whether pasture was attacked.
* @throws GameActionException
*/
public boolean denyPasture() throws GameActionException {
if (myPasture != null) {
if (rc.canAttackSquare(pastureLoc)) {
if (rc.senseRobotInfo(myPasture).health <= c.attackPower) {
rc.attackSquare(pastureLoc);
deniedPasture = true;
myPasture = null;
pastureLoc = null;
localCmd.clearChannel();
return true;
}
}
}
return false;
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:23,代码来源:Defender.java
示例20: willDie
import battlecode.common.GameActionException; //导入依赖的package包/类
public boolean willDie(Robot[] attackRangeEnemies)
throws GameActionException {
if (!sensor.infoInitSenseEnemies) {
sensor.initSenseEnemyInfo();
}
RobotInfo[] infos = sensor.getInfo(attackRangeEnemies);
int numEns = 0;
for (int i = infos.length; --i >= 0;) {
if (infos[i].actionDelay <= 1) {
numEns++;
}
}
if (numEns >= rc.getHealth() / c.attackPower) {
return true;
}
return false;
}
开发者ID:fabian-braun,项目名称:reignOfDke,代码行数:18,代码来源:Defender.java
注:本文中的battlecode.common.GameActionException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论