Discussion:
Need help getting the OnScannedRobot method to be called
d***@isev.k12.tr
2015-11-19 18:27:38 UTC
Permalink
fnl I tested your robot with my robot cyclops and it only moved didn't
fired!! but in the program it says fire if(getEnergy() > 50){
fire(2);
}
Can you tell why it don't fires

This si my robot cyclops

package legends;
import robocode.*;

import java.awt.Color;
import robocode.AdvancedRobot;
import robocode.ScannedRobotEvent;
import static robocode.util.Utils.normalRelativeAngleDegrees;
//import java.awt.Color;

// API help :
http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html

/**
* Cyclop - a robot by (your name here)
*/
public class Cyclop extends AdvancedRobot
{
double energyEnemy = 100;
double directionToMove = 1;
boolean rightAngle = false;
double turningTime = 1;
/**
* run: Cyclop's default behavior
*/
public void run() {
// Initialization of the robot should be put here
setAdjustGunForRobotTurn(true);
turnGunRight(90);
// After trying out your robot, try uncommenting the import at the top,
// and the next line:

// setColors(Color.red,Color.blue,Color.green); // body,gun,radar
setGunColor(new Color(255, 255, 255));
setBulletColor(new Color(255, 0, 0));
setBodyColor(new Color(220, 160, 122));
setRadarColor(new Color(0, 0, 0));
// Robot main loop
while(true) {
// Replace the next 4 lines with any behavior you would like
turnGunRight(20);
}
}

/**
* onScannedRobot: What to do when you see another robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
// Replace the next line with any behavior you would like
boolean systemUse = true;
double absoluteBearing = getHeading() + e.getBearing();
double bearingFromGun = normalRelativeAngleDegrees(absoluteBearing -
getGunHeading());
double distance = e.getDistance();
if(distance > 600){
setTurnRight(e.getBearing() + 90 - 30 * directionToMove);
systemUse = false;
}
if(distance > 800){
fire(1);
}else if(distance > 500){
fire(2);
}else if(distance > 200){
fire(3);
}else{
fire(3.5);
}
turnGunRight(bearingFromGun);
if(energyEnemy - e.getEnergy() > 0){
if(energyEnemy - e.getEnergy() < 5){
directionToMove = -directionToMove;
setAhead((distance / 4 + 25) * directionToMove);
}
} energyEnemy = e.getEnergy();
scan();
if(systemUse == true){
turnRight(e.getBearing() + 90);
}
}

/**
* onHitByBullet: What to do when you're hit by a bullet
*/
public void onHitByBullet(HitByBulletEvent e) {
// Replace the next line with any behavior you would like
setAhead(75);
}
/**
* onHitWall: What to do when you hit a wall
*/
public void onHitWall(HitWallEvent e) {
// Replace the next line with any behavior you would like
back(200);
ahead(100);
}
}
//A robot that made by Doruk...
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robocode+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...