/** onScannedRobot: Here's the good stuff */ @Override public void onScannedRobot_(solomon s, ScannedRobotEvent e) { // If we have a target, and this isn't it, return immediately // so we can get more ScannedRobotEvents. if (trackName != null && !e.getName().equals(trackName)) { return; } // If we don't have a target, well, now we do! if (trackName == null) { trackName = e.getName(); // out.println("Tracking " + trackName); } // This is our target. Reset count (see the run method) count = 0; // If our target is too far away, turn and move torward it. if (e.getDistance() > 150) { gunTurnAmt = normalRelativeAngle(e.getBearing() + (s.getHeading() - s.getRadarHeading())); s.turnGunRight(gunTurnAmt); // Try changing these to setTurnGunRight, s.turnRight(e.getBearing()); // and see how much Tracker improves... // (you'll have to make Tracker an AdvancedRobot) s.ahead(e.getDistance() - 135); return; } // Our target is close. gunTurnAmt = normalRelativeAngle(e.getBearing() + (s.getHeading() - s.getRadarHeading())); s.turnGunRight(gunTurnAmt); s.fire(3); // Our target is too close! Back up. if (e.getDistance() < 100) { if (e.getBearing() > -90 && e.getBearing() <= 90) { s.back(30); } else { s.ahead(40); } } s.scan(); }
/** onScannedRobot: What to do when you see another robot */ public void onScannedRobot(ScannedRobotEvent e) { if (isFriend(e.getName())) { return; } Enemy en; if (targets.containsKey(e.getName())) { en = (Enemy) targets.get(e.getName()); } else { en = new Enemy(); targets.put(e.getName(), en); } // the next line gets the absolute bearing to the point where the bot is double absbearing_rad = (getHeadingRadians() + e.getBearingRadians()) % (2 * PI); // this section sets all the information about our target en.name = e.getName(); double h = normaliseBearing(e.getHeadingRadians() - en.heading); h = h / (getTime() - en.ctime); en.changehead = h; en.x = getX() + Math.sin(absbearing_rad) * e.getDistance(); // works out // the x // coordinate // of where // the // target is en.y = getY() + Math.cos(absbearing_rad) * e.getDistance(); // works out // the y // coordinate // of where // the // target is en.bearing = e.getBearingRadians(); en.heading = e.getHeadingRadians(); en.ctime = getTime(); // game time at which this scan was produced en.speed = e.getVelocity(); en.distance = e.getDistance(); en.live = true; if ((en.distance < target.distance) || (target.live == false)) { target = en; } }
/** * When scanning a robot we need to add it to the collection of scanned objects so it can be used * later for updates to the bots movement. */ public void onScannedRobot(ScannedRobotEvent e) { double targetBearing = getHeading() + e.getBearing(); double tmpX = getX() + e.getDistance() * Math.sin(Math.toRadians(targetBearing)); double tmpY = getY() + e.getDistance() * Math.cos(Math.toRadians(targetBearing)); String name = e.getName(); if (name.equals(GOAL_NAME)) { foundGoal = true; } obstacles.put(name, new Enemy(tmpX, tmpY, e.getBearing())); setTurnRadarRight(getRadarTurnRemaining()); }
public void update(ScannedRobotEvent sre, double self_h, double self_x, double self_y) { if (sre.getName().equals(name)) { tc.update( sre.getTime(), sre.getEnergy(), tm.predict_gun_heading(sre, tc), tm.predict_gun_heat(sre, tc), correct_angle(sre.getHeadingRadians()), sre.getVelocity(), getX(sre, self_h, self_x), getY(sre, self_h, self_y)); mm.update(sre); } }
public RobotModel(ScannedRobotEvent fs, AdvancedRobot parent) { // firstScan this( fs.getName(), parent.getHeight(), parent.getWidth(), fs.getEnergy(), // TODO update parent. if a more intelligent method is found parent.getGunCoolingRate(), parent.getGunHeadingRadians(), parent.getGunHeat(), parent.getRadarHeadingRadians(), fs.getHeadingRadians(), fs.getVelocity(), // adjusted locations getX(fs, parent.getHeadingRadians(), parent.getX()), getY(fs, parent.getHeadingRadians(), parent.getY())); this.parent = parent; }
public void onScannedRobot(ScannedRobotEvent e) { // track if we have no enemy, the one we found is significantly // closer, or we scanned the one we've been tracking. if (enemy.none() || e.getDistance() < enemy.getDistance() - 70 || e.getName().equals(enemy.getName())) { // track him enemy.update(e); // if the gun is cool and we're pointed at the target, shoot! // Note: we can put the firing code before the turning code // because we're testing to see if we're aiming at our enemy if (getGunHeat() == 0 && Math.abs(getGunTurnRemaining()) < 10) setFire(Math.min(400 / enemy.getDistance(), 3)); // calculate gun turn toward enemy double turn = getHeading() - getGunHeading() + e.getBearing(); // normalize the turn to take the shortest path there setTurnGunRight(normalizeBearing(turn)); } }
@Override public void onScannedRobot(ScannedRobotEvent event) { info = new EnemyInfo(en, getTime()); Enemy enemy = enemies.get(event.getName()); if (enemy == null) { enemy = new Enemy(event, this); enemies.put(enemy.getName(), enemy); storages.put(enemy.getName(), new VisitCountStorage()); } if (getTime() - enemy.getLastUpdated() < Costants.TIME_THRESHOLD && (enemy.getEnergy() - event.getEnergy()) > 0. && (enemy.getEnergy() - event.getEnergy()) < 3.1) { GBulletFiredEvent gBulletFiredEvent = new GBulletFiredEvent(); gBulletFiredEvent.setFiringRobot(enemy); gBulletFiredEvent.setEnergy(enemy.getEnergy() - event.getEnergy()); gBulletFiredEvent.setVelocity(20 - 3 * (enemy.getEnergy() - event.getEnergy())); gBulletFiredEvent.setFiringTime(getTime() - 1); gBulletFiredEvent.setFiringPosition(enemy.getPosition()); // TODO this or the updated one? gBulletFiredEvent.setTargetPosition(new Point2D.Double(getX(), getY())); org.pattern.utils.Utils.setWaveMAE(gBulletFiredEvent, getHeading(), getVelocity(), this); waves.addWave(gBulletFiredEvent); } enemy.updateEnemy(event, this); enemies.put(enemy.getName(), enemy); if (!meleeRadar) { Double radarTurn = getHeading() - getRadarHeading() + enemy.getBearing(); setTurnRadarRight(Utils.normalRelativeAngleDegrees(radarTurn)); } doShooting(); }
public void onScannedRobot(ScannedRobotEvent e) { /*-------- setup data -----*/ if (enemyName == null) { enemyName = e.getName(); } Point2D.Double robotLocation = new Point2D.Double(bot.getX(), bot.getY()); double theta; final double enemyAbsoluteBearing = bot.getHeadingRadians() + e.getBearingRadians(); final double enemyDistance = e.getDistance(); enemyLocation = projectMotion(robotLocation, enemyAbsoluteBearing, enemyDistance); final double enemyEnergy = e.getEnergy(); Rectangle2D.Double BF = new Rectangle2D.Double(18, 18, 764, 564); /* To explain the below; if the enemy's absolute acceleration is zero then we segment on time since last velocity change, lateral acceleration and lateral velocity. If their absolute acceleration is non zero then we segment on absolute acceleration and absolute velocity. Regardless we segment on walls (near/far approach to walls) and distance. I'm trying to have my cake and eat it, basically. :-) */ MicroWave w = new MicroWave(); final double lastLatVel = enemyLatVel; double lastVelocity = enemyVelocity; enemyLatVel = (enemyVelocity = e.getVelocity()) * Math.sin(e.getHeadingRadians() - enemyAbsoluteBearing); int distanceIndex = (int) enemyDistance / 140; double bulletPower = distanceIndex == 0 ? 3 : 2; theta = Math.min(bot.getEnergy() / 4, Math.min(enemyEnergy / 4, bulletPower)); if (theta == bulletPower) bot.addCustomEvent(w); bulletPower = theta; w.bulletVelocity = 20D - 3D * bulletPower; int accelIndex = (int) Math.round(Math.abs(enemyLatVel) - Math.abs(lastLatVel)); if (enemyLatVel != 0) bearingDirection = enemyLatVel > 0 ? 1 : -1; w.bearingDirection = bearingDirection * Math.asin(8D / w.bulletVelocity) / GF_ZERO; double moveTime = w.bulletVelocity * lastVChangeTime++ / enemyDistance; int bestGF = moveTime < .1 ? 1 : moveTime < .3 ? 2 : moveTime < 1 ? 3 : 4; int vIndex = (int) Math.abs(enemyLatVel / 3); if (Math.abs(Math.abs(enemyVelocity) - Math.abs(lastVelocity)) > .6) { lastVChangeTime = 0; bestGF = 0; accelIndex = (int) Math.round(Math.abs(enemyVelocity) - Math.abs(lastVelocity)); vIndex = (int) Math.abs(enemyVelocity / 3); } if (accelIndex != 0) accelIndex = accelIndex > 0 ? 1 : 2; w.firePosition = robotLocation; w.enemyAbsBearing = enemyAbsoluteBearing; // now using PEZ' near-wall segment w.waveGuessFactors = guessFactors[accelIndex][bestGF][vIndex][ BF.contains( projectMotion( robotLocation, enemyAbsoluteBearing + w.bearingDirection * GF_ZERO, enemyDistance)) ? 0 : BF.contains( projectMotion( robotLocation, enemyAbsoluteBearing + .5 * w.bearingDirection * GF_ZERO, enemyDistance)) ? 1 : 2][ distanceIndex]; bestGF = GF_ZERO; for (int gf = GF_ONE; gf >= 0 && enemyEnergy > 0; gf--) if (w.waveGuessFactors[gf] > w.waveGuessFactors[bestGF]) bestGF = gf; bot.setTurnGunRightRadians( Utils.normalRelativeAngle( enemyAbsoluteBearing - bot.getGunHeadingRadians() + w.bearingDirection * (bestGF - GF_ZERO))); if (bot.getEnergy() > 1 || distanceIndex == 0) bot.setFire(bulletPower); bot.setTurnRadarRightRadians( Utils.normalRelativeAngle(enemyAbsoluteBearing - bot.getRadarHeadingRadians()) * 2); }
/** onScannedRobot: What to do when you see another robot */ public void onScannedRobot(ScannedRobotEvent e) { System.out.println("START at : " + getTime() + " onScannedRobot----------------------------"); String nnn = e.getName(); System.out.println("scan " + nnn); double eneX = getX() + Math.sin(e.getBearingRadians() + Math.toRadians(getHeading())) * e.getDistance(); double eneY = getY() + Math.cos(e.getBearingRadians() + Math.toRadians(getHeading())) * e.getDistance(); Enemy_info enem = null; if (!isTeammate(nnn)) { // 味方への情報送信 try { broadcastMessage( nnn + ", " + e.getBearing() + ", " + e.getBearingRadians() + ", " + e.getDistance() + ", " + e.getEnergy() + ", " + e.getHeading() + ", " + e.getHeadingRadians() + ", " + e.getVelocity() + ", " + eneX + ", " + eneY); } catch (IOException ignored) { } // スキャンした車両がLocal敵リストにいるかどうかのフラグ boolean flag = false; System.out.println("send scanned info"); // スキャンした敵がLocal敵リストの中に存在するか for (Enemy_info temp : enes) { if (nnn.equals(temp.get_en_name())) { flag = true; enem = temp; // Local敵リストのアップデート temp.updateInformation( e.getBearing(), e.getBearingRadians(), e.getDistance(), e.getEnergy(), e.getHeading(), e.getHeadingRadians(), e.getVelocity(), eneX, eneY); System.out.println(" update scanned Info"); } } // スキャンした敵がLocal敵リストの中に存在しない場合 if (!flag) { // Local敵リストに新規追加 enem = new Enemy_info( nnn, e.getBearing(), e.getBearingRadians(), e.getDistance(), e.getEnergy(), e.getHeading(), e.getHeadingRadians(), e.getVelocity(), eneX, eneY); enes.add(enem); System.out.println(" add scanned info"); } if (enemy_detected == false) { // 共通の敵が設定されていない場合 enemy_detected = true; target_enemy = enem; try { broadcastMessage("Kill , " + target_enemy.get_en_name() + ", !!"); } catch (IOException ignored) { } } if (enemy_detected == true) { try { double enemyX = target_enemy.get_en_expX(); double enemyY = target_enemy.get_en_expY(); setTurnRadarLeftRadians(getRadarTurnRemainingRadians()); System.out.println("abs : eX " + enemyX + " : " + "eY " + enemyY); // 共通の敵が設定されている場合 double enemyBearing = Math.atan((enemyX - getX()) / (enemyY - getY())); // if(enemyBearing<0){ // System.out.println("change"); // enemyBearing = Math.PI*2 + enemyBearing; // }else if (enemyBearing < Math.PI){ // } // System.out.println("atan " + Math.atan((eneY-getY())/(eneX-getX()))); // System.out.println("atan1 " + Math.atan((eneX-getX())/(eneY-getY()))); // System.out.println("trueeee " + (e.getBearingRadians() + this.getHeadingRadians())); System.out.println( "enerad" + enemyBearing + " ?= " + "enemyBearing " + (this.getHeadingRadians() + e.getBearingRadians())); System.out.println(enemyBearing + Math.PI); double enemyHeading = target_enemy.get_en_heading(); // 敵の向き System.out.println("enemy heading:" + enemyHeading); // double enemyBearing = this.getHeadingRadians() + // target_enemy.get_en_bearingRadians();// 自分と敵の角度 // double enemyX = target_enemy.get_en_distance() * Math.sin(enemyBearing); // double enemyY = target_enemy.get_en_distance() * Math.cos(enemyBearing); enemyX = enemyX - getX(); enemyY = enemyY - getY(); System.out.println("Relative : eX " + enemyX + " : " + "eY " + enemyY); double battlefieldWidh = getBattleFieldWidth(); // フィールド幅 double battlefieldHeight = getBattleFieldHeight(); // フィールド高さ boolean isHeadingToCenter = (int) enemyHeading % 90 == 0; // 中心を向いている boolean isOnWall = nearlyEquals(enemyX, 18) || nearlyEquals(enemyX + 18, battlefieldWidh) || nearlyEquals(enemyY, 18) || nearlyEquals(enemyY + 18, battlefieldHeight); // 壁に張り付いている // 中心を向いている&&壁際にいる(=Walls)なら射撃 if (isHeadingToCenter && isOnWall) { System.out.println("Walls!!"); } double dis = 0; double heading = lastEnemyHeading; do { dis += Rules.getBulletSpeed(power); heading += target_enemy.get_en_headingRadians() - lastEnemyHeading; enemyX += target_enemy.get_en_velocity() * Math.sin(heading); enemyY += target_enemy.get_en_velocity() * Math.cos(heading); } while (dis < Point2D.distance(0, 0, enemyX, enemyY)); // // 相対角度に変換した上で砲塔の向きを変える setTurnGunRightRadians( Utils.normalRelativeAngle(Math.atan2(enemyX, enemyY) - getGunHeadingRadians())); setFire(power); // lastEnemyHeading = e.getHeadingRadians(); lastEnemyHeading = target_enemy.get_en_headingRadians(); System.out.println("lastEnemyHeading " + e.getHeadingRadians()); System.out.println(lastEnemyHeading); // 敵の居る方向へターンする // setTurnRightRadians(e.getBearingRadians()); setTurnRightRadians(enemyBearing - this.getHeadingRadians()); System.out.println("setTurnRightRadians " + e.getBearingRadians()); System.out.println(enemyBearing - this.getHeadingRadians()); // 前進する setAhead(moveAmount); } catch (NullPointerException ee) { System.out.println("NullPointerException"); System.out.println(target_enemy); } } } System.out.println("enemy_detected = " + enemy_detected); System.out.println("target is " + target_enemy.get_en_name()); System.out.println(target_enemy.get_en_expX() + " " + target_enemy.get_en_expY()); System.out.println("END at : " + getTime() + " onScannedRobot----------------------------"); }