package exe; import robocode.*; import baseRobot.*; /** * 壁との衝突回避クラス * * @author Fumi Iseki * @version 1.0 */ public class WallCondition { private final double wallFactor = 1.6; private double xMax, yMax, xMin, yMin; private double width, height; private double robosz; private double nwdist, fldist; private BaseRobot myRobo; /** * コンストラクタ */ public WallCondition(BaseRobot robo) { myRobo = robo; robosz = robo.getRoboTool().getRoboSize(); width = robo.getBattleFieldWidth(); height = robo.getBattleFieldHeight(); xMax = width; yMax = height; xMin = 0.0; yMin = 0.0; nwdist = robosz*wallFactor; fldist = robosz*wallFactor; } /** * ロボットが競技場の中央部分にいる */ public Condition inField = new Condition("InField") { public boolean test() { double x = myRobo.getX(); double y = myRobo.getY(); if (x-fldist>xMin && y-fldist>yMin && x+fldist=xMax || y+nwdist>=yMax) return true; else return false; }; }; /** * 壁際の衝突回避処理..... でも時々あたる(;_;) */ public boolean checkCollision() { boolean ret = false; if (nearWall.test()) { //System.out.println("Near Wall"); double kd = myRobo.getRoboTool().getRelAngle((xMin+xMax)/2, (yMin+yMax)/2, myRobo.getHeading()); myRobo.setTurnShortest(kd, RoboConst.faraway); ret = true; } return ret; } /** * 行動範囲の設定 */ public void setField() { if (myRobo.getVsOthers()) { double xx = myRobo.getX(); double yy = myRobo.getY(); /* if (xx