js conversion to C# for dungeon generator algorithm