I am drawing this simple grid on my NodeJS server:
var grid = [];
for(var x = 0; x < 20; x++){
grid[x] = [];
for(var y = 0; y < 20; y++){
grid[x][y] = 0;
}
}
console.log(grid);
The outcome looks like this:
I know, pretty right?!
0 is supposed to indicate FREE, thus if a player requests to move to a field with 0, he will!
The problems come when I want to add more then just Free/Occupied, for instance I would like to give each Array Element an ID number for the Client Updates, or certain features on the field to be stored.
I tried to assign { something: N, something2: N}
But thought it looked rather performance expensive in the long run. (On a big Grid)
I read about using a single Object for several elements, but I cannot find this any more..
Should I perhaps use an Array of Objects, or an Additional Array inside each X,Y element?
Any performance / convenience / anything goes tips are welcome :D
Edit: Thank you for the ideas so far, I was now thinking to perhaps using Strings. Storing Variable_A + "," + Variable_B and then later using the .split to use the information. Any thoughts on this?