本文整理汇总了Java中battlecode.common.GameActionException类的典型用法代码示例。如果您正苦于以下问题:Java GameActionException类的具体用法?Java GameActionException怎么用?Java GameActionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GameActionException类属于battlecode.common包,在下文中一共展示了GameActionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
}
示例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();
}
示例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;
}
}
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
}
}
示例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;
}
}
示例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();
}
}
示例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;
}
示例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();
}
}
示例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;
}
}
示例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();
}
}
}
示例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();
}
示例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();
}