User talk:Navajo
Welcome! Hello, Navajo, and welcome to RoboWiki! This place contain a wealth information about Robocode, from basic to more advanced. I hope you enjoy creating robots and being a robocoder! If you are posting a comment on this wiki, please sign your messages using four tildes (--~~~~); this will automatically insert your username and the date stamp. If you are not familiar with MediaWiki, these links might help you out:
If you need help, check out the frequently asked questions or ask it on this page. Again, welcome! —— Voidious 21:28, 20 July 2009 (UTC) |
Hey, welcome to the wiki. =) Feel free to post if/when you have questions. Best of luck with yours bots! --Voidious 21:28, 20 July 2009 (UTC)
Thank you for the welcome. I believe my best question by now would be where is the right place to ask each question, but I believe I will soon get used to this... --Navajo 17:31, 21 July 2009 (UTC)
- If there's a page for the topic of your question, its Talk page is a good place. This page (your Talk page) would also be fine. Most of us watch the Recent changes page, so you really can ask anywhere and it will be noticed.
- As for English, it's no problem. There are quite a lot of non-native English speakers on this wiki. It actually quite impresses me. Sometimes I forget. =) --Voidious 18:23, 21 July 2009 (UTC)
If I remember correctly there was a topic in the old wiki about fast trig, something like a class that had its own sine and cosine methods and was suppose to be faster than the standart functions from java. I have been unsuccessfully looking for this topic for a few days now, so I was wondering if someone here would know where it is --Navajo 23:04, 21 July 2009 (UTC)
- I'm not sure about the one on the old wiki, FastMath and FastMath/SquareRoot are all I can find. But at least a few people use this: User:Rednaxela/FastTrig. --Voidious 23:15, 21 July 2009 (UTC)
- Thank you, this was exactly what I was looking for! How did you find it so fast?--Navajo 23:25, 21 July 2009 (UTC)
- Well, I remembered Rednaxela had written that, and I thought it was called "FastTrig", so I searched for "FastTrig" and that was the first result... =) --Voidious 23:29, 21 July 2009 (UTC)
- I have some time posted on talk page of FastTrig page. You might want to check it. » Nat | Talk » 10:32, 22 July 2009 (UTC)
Just a silly java question: if I have an instance of an object, like a wave and it contains an instance of another object (as one of its fields/variables) like a scan, then, when I set this scan to be one of those I have in my log of scans, does it create a new instance of the object or just store a reference to the original scan? --Navajo 21:41, 23 July 2009 (UTC)
- A reference, every object in Java is a reference to an object in the heap, that is why you can't call it's constructor in the definition and have to call new when you want to create it, so the actual object is created in the heap. --zyx 22:36, 23 July 2009 (UTC)
- So every instance of an object that I create is stored in the heap. Does this means that, for example, every instance of my scan object is stored in the heap, and a log of scans contains only references to these objects, and an instance of the wave object contains only a reference to that same instance of the scan? So in this sense, if I change some atribute of this scan, both the one avaible through the log and the one avaible through the wave will suffer the same change? I mean, if I change the position of the robot stored in the scan, if I try to get the position from either the wave or the log I will get the same value? --Navajo 23:15, 23 July 2009 (UTC)
- Hey Navajo, that's correct. If you code something like "Scan a = new Scan(); Scan b = a; a.attribute=3" then b.attribute is 3 too. a & b point to the same thing. To change this, you need to code something like: "Scan a = new Scan(); Scan b = new Scan(); a.attribute=3; b.attribute=4;". In this case a.attribute is not equal to b.attribute. --Positive 23:28, 23 July 2009 (UTC)
- As Positive said, both reference the same objects and both suffer the same changes in their state. The way I like to overcome this, is to create a copy constructor as C++ would. Although is easy to come up for yourself and there is no reason to think this is the best way from any point of view, except that I like it :), here is some code to show you my way to do it.
class A {
/* some attributes */
public A(A a) {
/* copy state from a, using new when appropriate */
}
}
class B extends A {
/* some attributes */
public B(B b) {
super(b); /* call copy constructor for superclass A */
/* copy state for class B specific attributes */
}
}
- And the conventional way to do this in Java is to implement the Clonable interface and override the Object.clone method. Hope it helps. --zyx 00:00, 24 July 2009 (UTC)
- Thank you both, this was very helpful. My problem is not to create 2 distinc instances of the same object, I just want to be sure that I'm only storing references, after all I don't want to have 50 copies of the same thing if I can have only 1. Besides, it is essential to me that all changes I make to an instance are global. I believe your explanations pretty much solved my problem --Navajo 02:13, 24 July 2009 (UTC)
Just another silly question. I'm using eclipse to develop my robots, is there anyway I can package my files through eclipse so that robocode will later recognize the jar as my robot? I already export my files to a jar everytime I have a new version, but robocode never recognizes those files as my robot. --Navajo 02:33, 25 July 2009 (UTC)
Well, you need a RobotName.properties file in the jar. See some other bots for examples. However, I strongly suggest you use Robocode itself to package it. There is a very easy to use wizard in the "Robot->Package Robot for Upload". It's by far the easiest/quickest way, and also does useful things like only including class files currently in use in your robot, and telling you the codesize. --Rednaxela 03:10, 25 July 2009 (UTC)
- Thank you, it worked. I like packaging through eclipse because I find it easier, and there are several class files that I don't use but are part of my development project. --Navajo 19:51, 26 July 2009 (UTC)
Do I need to do any thing besides launching 2 clients on my computer if I want run to both? It used to work for me, but recently the computer shuts down both clients after a while... Besides, is there any way I can get a stack trace when RoboResearch catches an exception? I mean, the current version of my robot throwns an exception somewhere, but it is very rare, I only see it when running many, many tests on RoboResearch, but it doesn't print a stack trace, and it never happens when I'm watching robocode console, so I still don't know what is wrong... --Navajo 23:33, 25 August 2009 (UTC)
No, you don't need anything more than two installations of Robocode. Could you provide more information regarding to this? I don't know the answer to second question, so please wait for the others. » Nat | Talk » 13:13, 26 August 2009 (UTC)
I thought I remembered hearing of people manually associating certain Robocode/Java processes with one of their processors (cores) on Windows. I know that on the Mac, you can just fire up two Robocodes and it works. Not sure about Linux or Windows, really... As for the RoboResearch errors, you might be able to modify the robocode.control related stuff in the source to make it log the errors. But the easier route would probably be big try/catch's that print any exceptions to a file in your data dir, which you could manually check when you hit an error. --Voidious 13:42, 26 August 2009 (UTC)
Well, my rumble problem is happening even with only one client, but I won't wory because I will format my computer soon, and I believe this problem will disapear... Regarding the exception, I thought of using the big try/catch, but if I understand java correctly, if my classes and methods are not throwable I would either need to insert the try/catch inside each method or make all my classes and methods throwable, what is quite inconvenient when you have something like a hundred classes... Anyway, I will try to revert to the last bug free version and rewrite the changes... --Navajo 20:40, 26 August 2009 (UTC)
- No, you wouldn't need to make methods throwable or put the try/catch inside of everything. That only applies to 'checked' exceptions. Most exceptions are 'unchecked'. For more information see here :) --Rednaxela 20:47, 26 August 2009 (UTC)
Great!! This is really usefull. So, I can put a try/catch in the robots run method for example and it will catch unchecked exceptions from anywhere on my bot, even those thrown by static methods? Sometimes it is good to not to understand java correctly, such pleasant surprises can make life much easier. Thanks for your help. --Navajo 21:38, 26 August 2009 (UTC)
- That's correct. When static code (or any code) throws exception, if it isn't fatal (i.e. isn't subclass of Error) and not caught, it will be moved up the JVM stack, i.e. return exception to the method that call the method which throw the exception. If the exception doesn't get caught when it has been passed to the top of stack trace i.e. no more method left in the JVM stack, JVM exceptions handler will come into action. So you can just big
try { ... } catch(Throwable e) { e.printStackTrace(FileOutputStream); }
in your run() method. Hope you understand, I don't know how to tell this. » Nat | Talk » 11:43, 27 August 2009 (UTC)
I've ran into a situation I cannot understand, maybe someone here can help me with this. When predicting precise max escape angle, at first I don't wall smooth. If the robot hits a wall I just stop moving it and run the time untill the wave passes and I can get the angle. I tried to change this and just get the biggest angle with one of the robot's corners, what should give me the same results. However, the results are a little different. Here is some code:
//What I used to do
double min = Utils.minDistToRobot(w.getSource(), r.getLocation());
double max = Utils.maxDistToRobot(w.getSource(), r.getLocation()) + w.getSpeed() + .5;
double dist = timeDelta*w.getSpeed();
while(dist < max){
if(dist > min){
Point2D.Double[] intersections = w.getWaveIntersections(r.getLocation(), timeDelta*w.getSpeed());
for(int x = 0; x < intersections.length; x++){
if(intersections[x] != null){
double a = Utils.absBearing(w.getSource(), intersections[x]) - w.getDirectAngle();
a = dir*Utils.normalRelativeAngle(a);
noSmoothingAngle = Math.max(noSmoothingAngle, a);
}
}
}
timeDelta++;
dist = w.getSpeed()*timeDelta;
}
//What I've just implemented
Point2D.Double[] corners = Utils.getRoboCorners(r.getLocation());
for(Point2D.Double corner : corners){
double c = Utils.absBearing(w.getSource(), corner) - w.getDirectAngle();
c = dir*Utils.normalRelativeAngle(c);
noSmoothingAngle = Math.max(noSmoothingAngle, c);
}
This is all inside my precise MEA simulation, so w is the wave, dir is the direction, r is the predicted robot state and timeDelta is the time since the wave was fired until the robot hit the wall. All methods do just what their names say they do, any doubts just ask. --Navajo 02:23, 31 August 2009 (UTC)
- [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.