Difference between revisions of "GFTargetingBot"

From Robowiki
Jump to navigation Jump to search
(addendum)
m (typo)
Line 32: Line 32:
 
I hope that helped.  If not, best thing is to just practice with arrays it until it sinks in. -- [[User:Pedersen|Martin]]
 
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.  That are "arrays of arrays".  The integers only exist in the final array. -- [[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]]

Revision as of 20:29, 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

Addendum: 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. -- Martin