User talk:Hapiel
Hello guys, I see some of you chat around on talk pages, and as there is no real question forum for Robocode or any other kind of community where the beginning programmer (me) can get answers on his stupid questions I am going to try it out here.
I have very little experience programming, not too much. I get demotivated quickly, because small errors or problems have huge impact on your programs, and I have never found a good solution for that ;). However, somehow when I saw robo soccer on tv I thought I should try robocode once more!
waitFor problem
Aaah, I have a question! - Solved :) -
while (true) {
if (getX() <= 100 || getY() <=100 || getBattleFieldWidth() - getX() <= 100 || getBattleFieldHeight() - getY() <= 100) {
reverseDirection();
}
waitFor(new RadarTurnCompleteCondition(this));
setTurnRadarRight(360);
}
So, this is a bit of an edit on one of the samplebots, Crazy. Does not matter much. As you can see I wrote an ugly not working system to detect if my robot is close to a wall. However, it does not work.
It only detects the wall if I replace the waitFor code with execute;, but in that case my radar is constantly spinning (right now my onScannedRobot code prevents it from spinning continiously).
I hoped I would be able to create an IF thingy to check if the radarturn was finished, or create an event on radarturncompletion, but was not able to figure it out! How exactly do conditions work? What does the (this) in the radarturncompletecondition code stand for, and what would be a simple/proper solution to my problem? Please let me know, any help is welcome!!
Hapiel --Hapiel =) 22:29, 12 January 2011 (UTC)
Greetings and welcome to the Robowiki! Lots of chat on talk pages indeed, in fact that's the primary use of this place I'd say. A little different than some other wikis.
Anyway, I haven't tested, but looking at that code, I'm pretty sure what you're missing an 'execute' call after 'setTurnRadarRight'. Without the 'execute' call, your loop will immediately skip to the top again, and run 'setTurnRadarRight' over and over without "telling" the robocode engine "I'm done my turn". Make sense?
--Rednaxela 01:14, 13 January 2011 (UTC)
Thanks for your reply! Is there an easy way to browse talk pages, or do you find the current topics only by going to the recent changes page?
Back to my question: The code runs, I suppose that waitFor is a proper replacement for an execute code. If I add execute to this, nothing visibly changes. Again, the problem is is that the piece of wall detection code is not run constant. It is only run when my scanner has finished turning (which is about never, except for when I just killed a robot.) If I replace the waitfor by execute();, my scanner keeps spinning constantly all the time, while if I use the wait for it is being overwritten by setScannerRight codes in my onScannedRobot event.
What would be the way so that my robot does scan this virtual wall at all time, but does not spin continiously? --Hapiel =) 16:40, 13 January 2011 (UTC)
I have just watched all the supersample bots, and I noticed they have the same problem as I have: they stop doing stuff when they can not scan someone anymore, so when their enemy is killed and noone walks in front of their scanners, they would never get back into action. This would happen here too if I removed my setScannerRight code and replaced the waitfor with execute... --Hapiel =) 17:12, 13 January 2011 (UTC)
Nevermind, I found a code in the API (finally..) that just did what I wanted: getRadarTurnRemaining() Problem solved!
Circling around your enemy
Hi again, Assuming that the enemy robot is firing to your current position, the best way to avoid it would be to move at a 90 degrees angle to the enemy robots location, right? I tried to write some code that would make my robot circle around the enemy, but somehow it does not work. Most of the time it keeps going in small circles, just like spinbot, or it drives in a straight line.
public void onScannedRobot(ScannedRobotEvent e) {
double absoluteBearing = getHeading() + e.getBearing();
if (movingForward){ // moving forward is set to true when setAhead is called, and to false when setBack is called...
setTurnRight(absoluteBearing + 90); // I tried switching the + and the minus, or adding normalRelativeAngleDegrees, but this all had no or no positive effect :/
} else {
setTurnRight(absoluteBearing - 90); // the setturnright code should be overwritten everytime my robot scans a robot right? which is every moment, because I have some tracking code...
}
}
What should I do :o?
- [View source↑]
- [History↑]
You cannot post new threads to this discussion page because it has been protected from new threads, or you do not currently have permission to edit.