Darkyere - a robot by (your name here)
*/
public class Darkyere extends AdvancedRobot
{
double gunTurnAmt;
int Count = 0;
String trackName;
Boolean haveTarget;
Boolean lowOnEnergy;
/**
run: Darkyere's default behavior
*/
public void run() {
// After trying out your robot, try uncommenting the import at the top,
// and the next line:
//setColors(Color.red,Color.blue,Color.green);
trackName = null; // Initialize to not tracking anyone
setAdjustGunForRobotTurn(false);
haveTarget= false;
lowOnEnergy = false;
while(true) {
// Replace the next 4 lines with any behavior you would like
onScannedRobot: What to do when you see another robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
if (trackName != null && !e.getName().equals(trackName)) {return;}
if (trackName == null){trackName = e.getName();}
Count = 0;
if (e.getEnergy() <= 30){
lowOnEnergy = true;
}else{
if (e.getEnergy() >= 50) {lowOnEnergy = false;}
The code you use to track your energy is correct. But about the other part you want, I think you need to figure them out yourselves. There are many techniques invented over the eight years of Robocode. You might want to join the RoboWiki (http://robowiki.net/) for further information on this.
The energy is lost when you hit a wall, hit by bullet, fire a bullet or hit other robot. There are quite many strategies on this. Please join the RoboWIki and enjoyed becoming a Robocoder!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
i thought the code to track my energy would be correct but actually it tracks my current targets energy, so when my robot has all most killed it's target it back's up and move wildly around.
I have tried reading through the robocode API but i cant find a way to track my energy only shows me way's to see the targets energy.
im currently only online to check any replies to the thread, so i am gonna wait joining RoboWiki for now. But i will take your advise and most definitely look around and becoming a member probably as soon as tomorrow.
im gonna go to bed and have a look at it all tomorrow. ty for your help so far and best regards to you and all the people reading this post.
Have a good night,
Mark
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
this is my 3. time i make a threadin this forum and i have been glad for the help i received so far.
But this is a bit of a bigger topic. my last 2 was concerning the compiling of the custom robot.
This is some programming questions i have been unable to figure out myself.
How do i found out how much energy is left in "my" robot and how can i escape around whit out using up all the remaining energy.
This is the code so far;
package mp;
import robocode.*;
//import java.awt.Color;
/**
Darkyere - a robot by (your name here)
*/
public class Darkyere extends AdvancedRobot
{
double gunTurnAmt;
int Count = 0;
String trackName;
Boolean haveTarget;
Boolean lowOnEnergy;
/**
run: Darkyere's default behavior
*/
public void run() {
// After trying out your robot, try uncommenting the import at the top,
// and the next line:
//setColors(Color.red,Color.blue,Color.green);
trackName = null; // Initialize to not tracking anyone
setAdjustGunForRobotTurn(false);
haveTarget= false;
lowOnEnergy = false;
while(true) {
// Replace the next 4 lines with any behavior you would like
}
}
/**
onScannedRobot: What to do when you see another robot
*/
public void onScannedRobot(ScannedRobotEvent e) {
if (trackName != null && !e.getName().equals(trackName)) {return;}
if (trackName == null){trackName = e.getName();}
Count = 0;
if (e.getEnergy() <= 30){
lowOnEnergy = true;
}else{
if (e.getEnergy() >= 50) {lowOnEnergy = false;}
}
}
scan();
}
}
}
Hope its not to much to ask, its a bit of some code to go through.
The code you use to track your energy is correct. But about the other part you want, I think you need to figure them out yourselves. There are many techniques invented over the eight years of Robocode. You might want to join the RoboWiki (http://robowiki.net/) for further information on this.
The energy is lost when you hit a wall, hit by bullet, fire a bullet or hit other robot. There are quite many strategies on this. Please join the RoboWIki and enjoyed becoming a Robocoder!
i thought the code to track my energy would be correct but actually it tracks my current targets energy, so when my robot has all most killed it's target it back's up and move wildly around.
I have tried reading through the robocode API but i cant find a way to track my energy only shows me way's to see the targets energy.
im currently only online to check any replies to the thread, so i am gonna wait joining RoboWiki for now. But i will take your advise and most definitely look around and becoming a member probably as soon as tomorrow.
im gonna go to bed and have a look at it all tomorrow. ty for your help so far and best regards to you and all the people reading this post.
Have a good night,
Mark
Sorry, I misread your code. It should call getEnergy(), not e.getEnergy();
A bit more, you should look for a API at AdvancedRobot class ,not ScannedRobotEvent class.