Difference between revisions of "GFTargetingBot"

From Robowiki
Jump to navigation Jump to search
(New page: I'm new to java, and my lack of understanding Java has me hung up on this key peice of code: buffer = statBuffers[distanceIndex][velocityIndex][lastVelocityIndex]; from my understanding...)
 
(apples and 'containers of apples')
Line 11: Line 11:
 
It seems to me were  assigning apples to oranges here? How does it work ? ..
 
It seems to me were  assigning apples to oranges here? How does it work ? ..
 
- Justin
 
- Justin
 +
 +
<code>int single[] = new int[ 5 ];</code>
 +
<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".
 +
 +
<br>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."
 +
 +
<br>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'".
 +
 +
<br>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.
 +
 +
<br>I hope that helped.  If not, best thing is to just practice with arrays it until it sinks in. -- [[User:Pedersen|Martin]]

Revision as of 20:16, 22 February 2008

I'm new to java, and my lack of understanding Java has me hung up on this key peice of code:

  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

int single[] = new int[ 5 ];
single is "an array of integers".
int double[][] = new int[ 5 ][ 5 ];
double is "an array of 5 arrays of 5 integers".


This means that each element in double[ n ] is itself "an array of 5 integers".


Let's change int to apple.
apple double[][] = new apple[ 5 ][ 5 ];
double 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.


apple triple[][][] = new apple[ 5 ][ 5 ][ 5 ];
triple 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: buffer is 'an array of integers'. (I deliberately did not state the size, because buffer can be assigned an array of any size of the same dimensions.) statBuffers 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. -- Martin