Tarkyo, the 2D array is a representation of the game-state, "the board". I will try to explain.
OK, so you have been taught "Arrays", and it's just the 2D that is confusing, right?
An array is a single named variable, that holds multiple other variables inside it in order. These internal variables are accessed using the array notation, eg. myarray[4] returns the 5th "slot" from the array myarray (arrays start counting at zero). OK so far?
So, an array can be visualised such as a rack of boxes each box may or may not hold a thing. kinda like this:
Code:
myarray = new Array(6);
looks like:
myarray [ ] [ ] [ ] [ ] [ ] [ ]
0 1 2 3 4 5
An array 6 slots in size - 6 empty boxes. you might use this to store some variables, like characters, or integers. e.g.
Code:
myarray[5] = 't';
myarray[4] = 'a';
myarray[3] = 'w';
now some of the slots are filled, it looks like:
myarray [ ] [ ] [ ] [w] [a] [t]
0 1 2 3 4 5
OK, that's standard 1D array. A 2D array is just the same, no more tricky. just harder to visualize, a little.
It is simply a normal array, but each slot contains
another array. like this:
Code:
myarray = new Array(6);
looks like:
myarray [ ] [ ] [ ] [ ] [ ] [ ]
0 1 2 3 4 5
myarray[0] = new Array(6);
myarray[1] = new Array(6);
myarray[2] = new Array(6);
myarray[3] = new Array(6);
myarray[4] = new Array(6);
myarray[5] = new Array(6);
now each slot holds an array of length 6, looks like:
[ ] [ ] [ ] [ ] [ ] [ ] 5
[ ] [ ] [ ] [ ] [ ] [ ] 4
[ ] [ ] [ ] [ ] [ ] [ ] 3
[ ] [ ] [ ] [ ] [ ] [ ] 2
[ ] [ ] [ ] [ ] [ ] [ ] 1
myarray [ ] [ ] [ ] [ ] [ ] [ ] 0
0 1 2 3 4 5
In a 2d array, they are accessed just the same, but you need to stick another array notation on the end since you are "going two arrays deep" to get at the variable.
e.g. myarray[0][5] would get you the top-left corner, myarray[3][0] would get you near the middle on the bottom row, and so on.
OK, see how this might now provide suitable tool to represent the state of a connect-4 board? Hope so