»Ë»Ñ Æ÷·³

java ÄÚµå Çؼ®(robocode) Áú¹®ÀÌ¿ä

  • naldo
  • µî·ÏÀÏ 2018-12-05 16:17
  • Á¶È¸¼ö 398
java ¹è¿ì°í ÀÖ´Â ÇлýÀε¥ robocode¿¡ Á¢¸ñÇÏ·Á°íÇÏ´Ï Çؼ®ÀÌ ¾ÈµÇ³×¿ä ¤Ì¤Ì 
¾î¶»°Ô ¿òÁ÷ÀÓ°¡Á®°¡´Â°ÇÁö ¾Ë°í½Í½À´Ï´Ù..
 
 
public class Lib extends AdvancedRobot
{
static final int PATTERN_LENGTH = 8;
//These are the coordinates of our corner movement (if it was in the lower-left corner).
//The length of these strings should be PATTERN_LENGTH and Lib should have to change
//directions (as in forward or reverse) for each point.
static final String xcoords = ("" + (char)30 + (char)30 + (char)90 + (char)30 + (char)150 + (char)150 + (char)30 + (char)210);
static final String ycoords = ("" + (char)30 + (char)210 + (char)30 + (char)150 + (char)150 + (char)30 + (char)90 + (char)30);
//this will normalize to PI/2, but it is big enough that I can use it for setAhead, too.
static double direction = 41*Math.PI/2;
//this variation is based loosely off of SandboxMiniMelee:
//static final int PATTERN_LENGTH = 10;
//static final String xcoords = ("" + (char)50 + (char)150 + (char)50 + (char)150 + (char)50 + (char)150 + (char)200 + (char)250 + (char)200 + (char)150);
//static final String ycoords = ("" + (char)150 + (char)200 + (char)250 + (char)200 + (char)150 + (char)50 + (char)150 + (char)50 + (char)150 + (char)50);
public void run()
{
setAdjustGunForRobotTurn(true);
setTurnRadarRight(Double.POSITIVE_INFINITY);
int index=0;
do
{
double goaly = ycoords.charAt(index);
double myy;
if ((myy = getY()) > 500)
goaly = getBattleFieldHeight()-goaly;
double goalx = xcoords.charAt(index);
double myx;
if ((myx = getX()) > 500)
goalx = getBattleFieldWidth()-goalx;
if (Point2D.distance(goalx, goaly, myx, myy) < 10)
{
direction = -direction;
index = (index+1)%PATTERN_LENGTH;
}
setAhead(direction);
//the SandboxMiniMelee version of the movement is buggy without this in there, the default movement is fine without it:
 //setAhead(getTurnRemainingRadians()==0 ? direction : 0);
setTurnRightRadians(robocode.util.Utils.normalRelativeAngle(Math.atan2(goalx-myx, goaly-myy) + Math.PI/2-direction - getHeadingRadians()));
execute();
}
while (true);
}
public void onScannedRobot(ScannedRobotEvent e)
{
double energy;
if ((energy = getEnergy()) > 1 && setFireBullet(20*getOthers()*energy/e.getDistance()) == null)
//this lets my radar slip when I fire so that people can't sneak up on me for locking my radar.
setTurnRadarLeft(getRadarTurnRemaining());
setTurnGunRightRadians(robocode.util.Utils.normalRelativeAngle(e.getBearingRadians()+getHeadingRadians()-getGunHeadingRadians()));
clearAllEvents();
}
public void onHitRobot(HitRobotEvent e)
{
if (e.isMyFault())
direction = -direction;
}
}

0
ÃßõÇϱ⠴ٸ¥ÀÇ°ß 0
|
°øÀ¯¹öÆ°
  • ¾Ë¸² ¿å¼³, »óó ÁÙ ¼ö ÀÖ´Â ¾ÇÇÃÀº »ï°¡ÁÖ¼¼¿ä.
©¹æ »çÁø  
¡â ÀÌÀü±Û¡ä ´ÙÀ½±Û