Difference between revisions of "User talk:Navajo"

From Robowiki
Jump to navigation Jump to search
(copy constructor and Clonable interface)
(reply)
 
(14 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{| width="100%" style="background: white; "
+
Just a simple question from Gibbs fifth rewrite: does robocode create a new instance of the robot every round or only once each battle? --[[User:Navajo|Navajo]] 00:40, 5 June 2010 (UTC)
| valign="top" width="60%" style="border: 2px solid #000; padding: .5em 1em; -moz-border-radius: 1em; -webkit-border-radius: 1em" |
 
'''Welcome!'''
 
  
Hello, Navajo, and welcome to [[RoboWiki]]! This place contain a wealth information about [[Robocode]], from [[Head-On Targeting|basic]] to [[Wave Surfing|more advanced]]. I hope you enjoy creating robots and being a robocoder!
+
Every round. If you just use the instance from the first round, some stuff might still work, but it's only a quirk of Robocode's internals that this is so. (And it may not always work, if they change those internals.) --[[User:Voidious|Voidious]] 01:04, 5 June 2010 (UTC)
  
If you are posting a comment on this wiki, please [[wikipedia:Wikipedia:Signatures|sign]] your messages using four tildes (<nowiki>--~~~~</nowiki>); this will automatically insert your username and the date stamp. If you are not familiar with MediaWiki, these links might help you out:
+
As i understand it, as of recent history, the internals are changed so less would work with the old instances. Also, keeping the old instances how has a much higher cost in the engine than it used to (leads a couple old bots that abuse it REALLY bad to have performance issues). The latest version of Robocode (1.7.2.0) also gives a big warning if a running bot has kept an old instance reference. --[[User:Rednaxela|Rednaxela]] 08:10, 5 June 2010 (UTC)
* [[wikipedia:How to edit|How to edit]] on [[wikipedia:|Wikipedia]], [[metawikipedia:Cheatsheet|Cheatsheet]] and [[metawikipedia:File:MediaWikiRefCard.pdf|Reference Card]] of MediaWiki on the [[metawikipedia:|Meta Wikipedia]].
 
* [[RoboWiki:ReadMe|Readme]] page.
 
If you need [[Help:Help|help]], check out the [[Robocode/FAQ|frequently asked questions]] or ask it on this page. Again, welcome!
 
 
 
—— [[User:Voidious|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! --[[User:Voidious|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... --[[User:Navajo|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 [[Special:RecentChanges|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. =) --[[User:Voidious|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 --[[User:Navajo|Navajo]] 23:04, 21 July 2009 (UTC)
 
 
 
: I'm not sure about the one on the old wiki, {{OldWiki|FastMath}} and {{OldWiki|FastMath/SquareRoot}} are all I can find. But at least a few people use this: [[User:Rednaxela/FastTrig]]. --[[User:Voidious|Voidious]] 23:15, 21 July 2009 (UTC)
 
 
 
:Thank you, this was exactly what I was looking for! How did you find it so fast?--[[User:Navajo|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... =) --[[User:Voidious|Voidious]] 23:29, 21 July 2009 (UTC)
 
 
 
: I have some time posted on [[User talk:Rednaxela/FastTrig|talk page of FastTrig page]]. You might want to check it. &raquo; <span style="font-size:0.9em;color:darkgreen;">[[User:Nat|Nat]] | [[User_talk:Nat|Talk]]</span> &raquo; 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? --[[User:Navajo|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. --[[User:Zyx|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? --[[User:Navajo|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. --[[User:Positive|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.
 
<code>
 
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 */
 
  }
 
}
 
</code>
 
::: And the conventional way to do this in Java is to implement the [http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Cloneable.html Clonable] interface '''and''' override the [http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html#clone() Object.clone] method. Hope it helps. --[[User:Zyx|zyx]] 00:00, 24 July 2009 (UTC)
 

Latest revision as of 10:10, 5 June 2010

Just a simple question from Gibbs fifth rewrite: does robocode create a new instance of the robot every round or only once each battle? --Navajo 00:40, 5 June 2010 (UTC)

Every round. If you just use the instance from the first round, some stuff might still work, but it's only a quirk of Robocode's internals that this is so. (And it may not always work, if they change those internals.) --Voidious 01:04, 5 June 2010 (UTC)

As i understand it, as of recent history, the internals are changed so less would work with the old instances. Also, keeping the old instances how has a much higher cost in the engine than it used to (leads a couple old bots that abuse it REALLY bad to have performance issues). The latest version of Robocode (1.7.2.0) also gives a big warning if a running bot has kept an old instance reference. --Rednaxela 08:10, 5 June 2010 (UTC)