On Thu, 22 Jul 2010 16:57:59 -0400, dcoder <dco...@devenull.dev> wrote:
== Quote from dcoder (dco...@devnull.com)'s article
Hello. I want to use associative arrays, but have a 2-d int array as my
index. so something like:
string[int[][]] chessboard;
chessboard[[0,0]] = "Rook";
chessboard[[0,1]] = "Knight";
Is this possible? I can declare chessboard without any compiler
complaints,
but I haven't figured out how to assign anything to it.
Any help would be appreciated.
thanks!
dcoder
Ooops, I just realized that int[someX][someY] needs to evaluate to an
int, so that
my statement above doesn't make any sense.
Still, is there anyway I can keep the spirit of a double index to a
chessboard
without having to create a Coordinate object and define relational
orderings?
This is what I think you should use:
string[int[2]]
Although, I'm not sure if you can then do something like:
chessboard[[0,1]] = "Rook";
as the [0, 1] is typed as a dynamic array. If it does work, it may
actually create [0,1] on the heap and then pass it as an int[2], which
would suck.
Or, if you know how big your chessboard is (8x8 isn't a lot of memory),
then:
string[8][8] chessboard;
is pretty straightforward :)
-Steve