public int _Max_X, _Max_Y, _Max_Z;
public int _Max_X_pow, _Max_Y_pow, _Max_Z_pow;
_Max_X = (int) Math.Pow(2,_Max_X_pow);
_Max_Y = (int) Math.Pow(2,_Max_Y_pow) ;
_Max_Z = (int) Math.Pow(2,_Max_Z_pow);
_Tiles = new Tile[_Max_X * _Max_Y * _Max_Z];
public Tile Get_Tile(int index) {
public int Get_Tile_Index(int x, int y, int z) {
return x * _Max_Y * _Max_Z + y * _Max_Z + z;
public void Get_Tile_Coords_By_Index(int index, out int x, out int y, out int z) {
string binaryIndexString = Convert.ToString(index, 2).PadLeft(_Max_X_pow+_Max_Y_pow+_Max_Z_pow,'0');
Console.WriteLine(binaryIndexString);
string binstringX=binaryIndexString.Substring(0,_Max_X_pow);
string binstringY=binaryIndexString.Substring(_Max_X_pow,_Max_Y_pow);
string binstringZ=binaryIndexString.Substring(_Max_X_pow+_Max_Y_pow,_Max_Z_pow);
Console.WriteLine(binstringX);
Console.WriteLine(binstringY);
Console.WriteLine(binstringZ);
Binary_String_To_Int(binstringX, out x);
Binary_String_To_Int(binstringY, out y);
Binary_String_To_Int(binstringZ, out z);
public int Binary_String_To_Int(string binString,out int num) {
if(binString=="0000011001")return num=25;
if(binString=="101") return num=5;
if(binString=="0000001111") return num=15;
public static World _World;
public static void Main() {
int random_tile_index = _World.Get_Tile_Index(25,5,15);
Tile random_tile = _World.Get_Tile(random_tile_index);
_World.Get_Tile_Coords_By_Index(random_tile_index, out x, out y, out z);
Console.WriteLine(string.Format("Index: {0} == {1}|{2}|{3}", random_tile_index, x,y,z));