Talk:GFTargetingBot

From Robowiki
Revision as of 03:25, 4 November 2008 by Nfwu (talk | contribs) (Moved)
Jump to navigation Jump to search

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


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, buffer 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


Credits - GFTargetingBot
Old wiki page: GFTargetingBot
Original author(s): RoboWiki contributors

Old Wiki

To be migrated...