User talk:Hapiel

From Robowiki
Jump to navigation Jump to search

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) {
			waitFor(new RadarTurnCompleteCondition(this));


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! —Preceding unsigned comment added by Hapiel (talkcontribs)

Ahh, I misinterpreted what your intended behavior was slightly. Regarding the "easy way to browse talk pages" question you asked before, Pretty sure all of us just go to the recent changes page usually. If you want to see all talk pages though, you can go to Special:AllPages and set namespace to check talk pages. Also there is always Special:Random/Talk and Special:Random/User Talk if one feels like randomly wandering... :) --Rednaxela 03:34, 14 January 2011 (UTC)

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? --Hapiel =) 18:17, 13 January 2011 (UTC)

You are using setTurnRight as if it makes you face the abs bearing you pass it. It needs to be relative to your heading - eg, if you're already facing that direction, you should pass zero. Also, you need to normalize between -180 and 180 (or -Math.PI and Math.PI in radians), otherwise you might do a 360 first. You need something more like: setTurnRight(Math.toDegrees(robocode.util.Utils.normalRelativeAngle(Math.toRadians(absoluteBearing - getHeading())))). I'd also personally recommend switching to radians altogether, but that's up to you. =) Then it would look a lot simpler: setTurnRightRadians(robocode.util.Utils.normalRelativeAngle(absoluteBearing - getHeadingRadians())). --Voidious 20:50, 13 January 2011 (UTC)

Hi guys,, I was just wondering Void, couldn't he use : setTurnRight(robocode.util.Utils.normalRelativeAngleDegrees(absoluteBearing - getHeading())). if he wanted to stick with Degrees? (though I'm not recommending sticking with degrees either).. -Jlm0924 18:33, 14 January 2011 (UTC)
Yeah, but that method's new in 1.7.x I think, so you couldn't use it in the rumble. I was basically just avoiding adding even more confusion to my explanation by bringing that up. =) --Voidious 18:40, 14 January 2011 (UTC)
ahhh... I expected you knew something I didn't :P I mentioned it cause I tried using it recently (I was using 1.6.x) and wasn't sure what the deal was... It's usually my code ;) -Jlm0924 18:50, 14 January 2011 (UTC)

Thanks for the answers guys! I should have of course used e.getBearing instead of absoluteBearing, but I would not have figured out without your help. I looked up on what a radian actually was, and I wonder why you two believe it is better to use it than degrees. Also, why doesn't roborumble use the current version of robocode? I went with the normalrelativeangledegrees code, so I assume I can not enter the robot then if I wanted? --Hapiel =) 20:02, 16 January 2011 (UTC)

Radians just make math (particularly circle math and trig) easier in general. Most science-type environments (Robocode and otherwise) will use radians, so it's also just good to get used to it. Doesn't really matter though. Robocode 1.7.x has enough changes that we wanted to wait and test that there would be negligible effects on scores before moving to it. We had a test RoboRumble server up for a while and I think we will again soon... Once upon a time, in the 1.1.x days, top bots got their scores very inflated from some versions. Yeah, for now, you'd need to modify your code not to use any of the new 1.7.x APIs if you want to enter it in the rumble (it would just get scores of zero). --Voidious 20:31, 16 January 2011 (UTC)

Ill better get used to the Radians then. Thanks for the advice! --Hapiel =) 20:36, 16 January 2011 (UTC)

There are no threads on this page yet.