public static Dictionary <string, int> GetCubeNewPos(int[] pos, int[][] cubesOccupation, Direction.Cube _direction) { var _value = new Dictionary <string, int> { { "x", pos[1] }, { "y", pos[0] }, { "cubeID", cubesOccupation[pos[0]][pos[1]] }, { "newX", pos[1] }, { "newY", pos[0] }, }; if (Cubes.CheckBoundaries(pos, _direction)) { return(_value); } if (Cubes.CheckBlockOverTarget(cubesOccupation, pos)) { return(_value); } int[] nextPos = (int[])pos.Clone(); var directionValue = GetDirectionValue(_direction); if (cubesOccupation[pos[0]][pos[1] + directionValue] <= 0) { if (pos[0] >= 1) { if (cubesOccupation[pos[0] - 1][pos[1] + directionValue] > 0) { nextPos[1] += directionValue; } else if (pos[0] >= 2) { if (cubesOccupation[pos[0] - 2][pos[1] + directionValue] > 0) { nextPos[0] += -1; nextPos[1] += directionValue; } } else if (pos[0] - 1 == 0) { nextPos[0] += -1; nextPos[1] += directionValue; } } else if (pos[0] == 0) { nextPos[1] += directionValue; } } else if (nextPos[0] < 3) { if (cubesOccupation[pos[0] + 1][pos[1] + directionValue] <= 0) { nextPos[1] += directionValue; nextPos[0] += 1; } } _value["newX"] = nextPos[1]; _value["newY"] = nextPos[0]; return(_value); }