Probably something object-oriented wise I am not understanding here.
I have a 3d array called old_cube
. I want to apply modify this array to obtain new_cube
.
old_cube
:
[[[w, w], [w, w]],
[[o, o], [o, o]],
[[g, g], [g, g]],
[[r, r], [r, r]],
[[b, b], [b, b]],
[[y, y], [y, y]]]
Code:
char[][][] old_cube = state.cube;
char[][][] new_cube = old_cube.clone();
new_cube[0][0][0] = old_cube[0][1][0];
new_cube[0][0][1] = old_cube[0][0][0];
new_cube[0][1][0] = old_cube[0][1][1];
new_cube[0][1][1] = old_cube[0][0][1];
new_cube[1][0][0] = old_cube[2][0][0];
new_cube[1][0][1] = old_cube[2][0][1];
new_cube[2][0][0] = old_cube[3][0][0];
new_cube[2][0][1] = old_cube[3][0][1];
new_cube[3][0][0] = old_cube[4][0][0];
new_cube[3][0][1] = old_cube[4][0][1];
new_cube[4][0][0] = old_cube[1][0][0];
new_cube[4][0][1] = old_cube[1][0][1];
Output:
new_cube
[[[w, w], [w, w]],
[[g, g], [o, o]],
[[r, r], [g, g]],
[[b, b], [r, r]],
[[g, g], [b, b]],
[[y, y], [y, y]]]
Expected:
new_cube
[[[w, w], [w, w]],
[[g, g], [o, o]],
[[r, r], [g, g]],
[[b, b], [r, r]],
[[o, o], [b, b]],
[[y, y], [y, y]]]
The issue is something that I thought clone()
would fix, but I must have done something wrong.