Suppose I have an algorithm that can play chess on a chessboard which is n-dimensional, using {1,...,8}^n n-dimensional squares.
The algorithm itself has no problem working in n dimensions, given an n-dimensional array or ArrayList for chessboard representation. The problem is that n is to be specified at runtime.
Is there any elegant way to generate and use such an n-dimensional chessboard?
What came to my mind was a recursive function to create an n-dimensional ArrayList, returning an ArrayList of Integers if n == 1, and returning an ArrayList of ArrayLists where each ArrayList of the second set of ArrayLists has dimension n-1.
But this does not seem to be elegant at all...
[edit]
An answer which seems to have been deleted before I could comment suggested the generation of one List, containing other lists of size 8. If I use 8 ^ numberOfDimensions many list inside the first list, this would probably work, but it would force me to manually keep track of dimensions.