Difference between revisions of "GFTargetingBot"

From Robowiki
Jump to navigation Jump to search
m (Move to talk page)
Line 1: Line 1:
I'm new to java, and my lack of understanding Java has me hung up on this key peice of code:
+
If you were looking for the discussion between Martin and Justin, it's on the [[Talk:GFTargetingBot|talk page]].
  buffer = statBuffers[distanceIndex][velocityIndex][lastVelocityIndex];
 
from my understanding;  buffer is an array of 25 (ints), each bin being a counter of times visted.
 
And statBuffers is a 4dimesional array of size: 5(int),  5(int), 5(int),and  25(int) :
 
private static int[][][][] statBuffers = new int[DISTANCE_INDEXES][VELOCITY_INDEXES][VELOCITY_INDEXES][BINS];
 
so back to the problem code :
 
buffer = statBuffers[distanceIndex][velocityIndex][lastVelocityIndex];
 
  
so the above "indexes" (0-4) should retrieve  the values in thoses locations in the statBuffers arrays..
+
----
Am I wrong so Far ?
 
It seems to me were  assigning apples to oranges here? How does it work ? ..
 
- Justin
 
  
<code>int single[] = new int[ 5 ];</code>
+
Article migration from old wiki required.
<br><i>single</i> is "an array of integers".
 
<br><code>int double[][] = new int[ 5 ][ 5 ];</code>
 
<br><i>double</i> is "an array of 5 arrays of 5 integers".
 
 
 
This means that each element in double[ n ] is itself "an array of 5 integers".
 
 
 
<br>Let's change <i>int</i> to <i>apple</i>.
 
<br><code>apple double[][] = new apple[ 5 ][ 5 ];</code>
 
<br><i>double</i> is now "an array of 5 arrays of 5 apples."
 
 
 
This means that every double[ n ] is a container, and each container holds 5 apples.  The container is not an apple.  It is 'a container of one or more apples'.  You can visualize it as a paper bag if you like.
 
 
 
<br><code>apple triple[][][] = new apple[ 5 ][ 5 ][ 5 ];</code>
 
<br><i>triple</i> is "an array of 5 arrays of 5 arrays of apples" or perhaps "5 containers of 'containers of apples'".
 
 
 
Going back to your original question, here is the situation:  <i>buffer</I> is 'an array of integers'.  (I deliberately did not state the size, because <i>buffer</i> can be assigned an array of any size of the same dimensions.)  <i>statBuffers</i> is 'an array of arrays of arrays of arrays of integers'.  Each element in statBuffers[][][] is itself an 'array of integers', and that is why the assignment works.
 
 
 
I hope that helped.  If not, best thing is to just practice with arrays it until it sinks in. -- [[User:Pedersen|Martin]]
 
 
 
<i>Addendum:</i>  Above you mentioned "statBuffers is a 4dimesional array of size: 5(int),  5(int), 5(int),and  25(int)", and therein lies the misconception.  The "5(int)" sections are not arrays of integers.  They are "arrays of arrays".  The integers only exist in the final array. -- [[User:Pedersen|Martin]]
 
 
 
 
 
 
 
yes I wasn't thinking dimesionally :), in the case of GFTargengBot code: buffer ends up being the 4 dimension of statBuffer that corisponds to the first 3 dimensions..correct?
 
-justin
 
 
 
Correct.  Also, <i>buffer</i> doesn't get its own copy of the data.  It just refers to the same memory location for the data that that branch of statBuffer does.  I doubt that's really relevant, but it may become relevant in some other application, and just saying "Correct." alone seemed silly. -- Martin
 
 
 
thx Martin :) -justin
 

Revision as of 03:24, 4 November 2008

If you were looking for the discussion between Martin and Justin, it's on the talk page.


Article migration from old wiki required.