I am trying to create a matrix to represent the diagonal options in a scalable board game where the number of rows and number of columns are defined by the player. The objective of the game is to beat your opponent to connect a string of your piece of a variable length defined by the players.
I have created horizontal and vertical matrix to represent the board, using loops to push rows into the respective matrix, however, I am having trouble dynamically creating a diagonal rule.
The purpose of these diagonal arrays is for checking against a win condition. ie X,X,X,X. I have given the elements within the array the value of the index within the vertical array for sense checking.
Here is an example of what I need from a 4 X 4 board;
verticalArray = [
['0,0', '1,0', '2,0', '3,0'],
['0,1', '1,1', '2,1', '3,1'],
['0,2', '1,2', '2,2', '3,2'],
['0,3', '1,3', '2,3', '3,3']
];
diagonalArray = [
['2,0', '3,1'],
['1,0', '2,1', '3,2'],
['0,0', '1,1', '2,2', '3,3'],
['0,1', '1,2', '2,3'],
['0,1', '1,3']
];
I am only able to use Javascript/jQuery at this point.