Efficiency int [,] Arrays versus Dictionary <> for constant updates

I am creating a game space in Unity (which is only slightly relevant) in C #, which supposedly is .NET, since it is in Unity. The playback space is two-dimensional and is generated through cellular automata with refining methods that make the shape of the playing space “usable” for my purposes.

Currently, data on the base playback space (living cells or dead, open or closed, tracks or walls) is stored as a binary value in the array int[,]. In the end, additional data will also be stored in the array or potentially in the secondary collection associated with this array int[,].

Additional data will include information on such things as: the player visited this cell, can the player see this cell at present (LoS), is there an opponent or an object / element in this cell.

LoS, hasVisited, and enemy data will be dynamic, obviously as the player moves and enemies move along their paths.

, , - , .

:

, ? , mapA - [80,80], mapB - [160,160], mapB 4x ? - , int[,]?

, - Dictionary<int[,], Dictionary<string, string>>. , , - , , , Dictionary<> . , , , , . , , , .

!

+4
3

. . -, , .

, int[,] , , , , . , , . .

int[,] , . .

+3

, , .

1000x1000, , 1,000,000 , "" 10% . , , , . 10x10 ( , ).

, 100%. , , , .

0

:. , int [,], -, #, ++ int [] [], , . , , int [,] , .

, , , int [] . :

int[] myArray = new int[width * height];

int x, y; // suppose you want to reach the cell at (x, y) coordinates
int cell = myArray[x + y * width];

for(int i=0 ; i<myArray.Length ; ++i) // suppose you want to iterate through the array
{
    int x = i % width;
    int y = i / width; // be sure that width is an int here, we want the auto-flooring

    int cell = myArray[x + y * width] // like above ;)

    int cell = myArray[i] // or of course for simplicity
}

, , [] , [,] #, , ++.

:

-2

Source: https://habr.com/ru/post/1624462/


All Articles