I'm struggling to think of the most elegant/simple way of doing this. Perhaps I'm overthinking it a little.
Lets say I've got a 5x5 array of integers that looks like this:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 And another 2x2 array of integers that looks like this:
5 1 2 3 I want to pick a location in the 5x5 array, say [2][2], and place the values from the second array into the first, so it looks like this:
0 0 0 0 0 0 0 0 0 0 0 0 5 1 0 0 0 2 3 0 0 0 0 0 0 My initial thought was to use a for loop after determining the number of rows/columns in the array to be copied, but I can't seem to puzzle out a way in my head to do that this morning.
Any suggestions?
Edit:
Sorry, here's the way I'm doing it currently. Just wondering if there's a better way.
This is actually part of a unity thing I'm doing - "RoomDoors" is our smaller array, and "map" is the larger array it's being moved into. It's part of a random map generator that needs to know which "edges" of tiles in rooms have doors on them that can connect to other rooms. RoomDoors stores 4 booleans, one for each direction telling me if there's a door there.
roomDoors = previousRoom.GetComponent<RoomDataInterface> ().rooms; //2d array of room/door arrangement in new room sizeCol = roomDoors.GetLength (0); sizeRow = roomDoors.GetLength (1); map [10, 10] = roomDoors [0, 0]; // top left of the room goes in the spot for (int i = 0; i < sizeCol; i ++){ for (int j = 0; j < sizeRow; j ++) { map [i + 10,j + 10] = roomDoors[i,j]; }
forloops, one for the columns and one for the rows? Some index checking can also be helpful.