CSC8501_Advanced_Programming_For_Games / MazeGeneration / BinaryTree.cpp
BinaryTree.cpp
Raw
#include "BinaryTree.h"

void BinaryTree::Generate(void)
{
    /* Mersenne Twister 19937 pseudo-random generator. */
    std::mt19937 random_generator(random_device());
    std::uniform_int_distribution<uint32_t> random_dir(vertical, horizontal);

    uint32_t orientation = none;
    for (uint32_t y = 1u; y < (m_areaHeight - 1u); y += 2) {
        for (uint32_t x = 1u; x < (m_areaWidth - 1u); x += 2) {
            if (((m_areaWidth - 2u) == x) && ((m_areaHeight - 2u) == y)) {
                orientation = none;
            } else if ((m_areaWidth - 2u) == x) {
                orientation = horizontal;
            } else if ((m_areaHeight - 2u) == y) {
                orientation = vertical;
            } else {
                orientation = random_dir(random_generator);
            }

            if (vertical == orientation) {
                for (uint32_t i = 0u; i < 3u; i++) {
                    m_area[y][x + i] = Maze_Char_Space;
                }
            } else if (horizontal == orientation) {
                for (uint32_t i = 0u; i < 3u; i++) {
                    m_area[y + i][x] = Maze_Char_Space;
                }
            } else {
            }
        }
    }
}