기타

디펜스게임 맵 사방으로 한칸씩 확장하는 알고리즘

도라몬즈 2023. 5. 10. 13:14
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>

#define MAX_MAP_SIZE 128 // 무조건 짝수, 최소 6
#define weighted_num 0   // 가중치 0~1 실수

using namespace std;
/*
    <direction>
    0 - left
    1 - top
    2 - right
    3 - bottom

    사분면
    0 1
    2 3
*/
class map
{
private:
    bool map_array[MAX_MAP_SIZE][MAX_MAP_SIZE]; // true = 길
    int start_point[3];                         // 시작포인터 [0]=x,[1]=y,[2]=direction (주의: 길 끝을 나타내는 것임(길 끝 다음 블럭이 아님))
    int end_point[3];                           // end포인터 [0]=x,[1]=y,[2]=direction
    int current_map_size;
    int map_corner[MAX_MAP_SIZE][MAX_MAP_SIZE];

    // for dfs
    bool dfs_temp_map_array[MAX_MAP_SIZE][MAX_MAP_SIZE]; // dfs 맵용
    int dfs_num;

    void dfs_find_corner(int x, int y, int dir, int len) // 코너 찾기용
    {
        dfs_temp_map_array[y][x] = true;
        if (x == end_point[0] && y == end_point[1])
        {
            map_corner[y][x] = len++;
            return;
        }

        if (map_array[y][x - 1] && !dfs_temp_map_array[y][x - 1])
        {
            if (dir != 0)
                map_corner[y][x] = len++;
            dfs_find_corner(x - 1, y, 0, len);
        }
        if (map_array[y - 1][x] && !dfs_temp_map_array[y - 1][x])
        {
            if (dir != 1)
                map_corner[y][x] = len++;
            dfs_find_corner(x, y - 1, 1, len);
        }
        if (map_array[y][x + 1] && !dfs_temp_map_array[y][x + 1])
        {
            if (dir != 2)
                map_corner[y][x] = len++;
            dfs_find_corner(x + 1, y, 2, len);
        }
        if (map_array[y + 1][x] && !dfs_temp_map_array[y + 1][x])
        {
            if (dir != 3)
                map_corner[y][x] = len++;
            dfs_find_corner(x, y + 1, 3, len);
        }
    }

    void reset_dfs_arr(int num) // num=0일시 dfs_arr을 전부 false로 초기화, num=1일시 dfs_arr에 map_array복사
    {
        if (num == 0)
        {
            for (int i = 0; i < MAX_MAP_SIZE; i++)
                for (int j = 0; j < MAX_MAP_SIZE; j++)
                    dfs_temp_map_array[i][j] = false;
        }
        else
        {
            for (int i = 0; i < MAX_MAP_SIZE; i++)
                for (int j = 0; j < MAX_MAP_SIZE; j++)
                    dfs_temp_map_array[i][j] = map_array[i][j];
        }
    }

    void only_dfs_dir(int dir, int sn, int re_arr[]) // sn이 0=start, 1=end, dir 방향 0=왼쪽, 1=오른쪽, re_arr=x,y(+-1반환)
    {
        int star_point;
        if (sn == 0)
        {
            star_point = start_point[2];
        }
        else
        {
            star_point = end_point[2];
        }

        if (star_point == 0)
        {
            if (dir == 0)
            {
                re_arr[0] = 0;
                re_arr[1] = 1;
            }
            else
            {
                re_arr[0] = 0;
                re_arr[1] = -1;
            }
        }
        else if (star_point == 1)
        {
            if (dir == 0)
            {
                re_arr[0] = -1;
                re_arr[1] = 0;
            }
            else
            {
                re_arr[0] = 1;
                re_arr[1] = 0;
            }
        }
        else if (star_point == 2)
        {
            if (dir == 0)
            {
                re_arr[0] = 0;
                re_arr[1] = -1;
            }
            else
            {
                re_arr[0] = 0;
                re_arr[1] = 1;
            }
        }
        else
        {
            if (dir == 0)
            {
                re_arr[0] = 1;
                re_arr[1] = 0;
            }
            else
            {
                re_arr[0] = -1;
                re_arr[1] = 0;
            }
        }
    }

    void cal_road_distributions(int re_arr[]) // 맵을 배열 넣으면 사분면의 길 갯수 입력한 배열에 반환
    {
        int temp_arr[2][2] = {};
        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                for (int v = (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size * i / 2; v < (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size * i / 2 + current_map_size / 2; v++)
                {
                    for (int w = (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size * j / 2; w < (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size * j / 2 + current_map_size / 2; w++)
                    {
                        if (map_array[v][w])
                            temp_arr[i][j]++;
                    }
                }
            }
        }
        re_arr[0] = temp_arr[0][0];
        re_arr[1] = temp_arr[0][1];
        re_arr[2] = temp_arr[1][0];
        re_arr[3] = temp_arr[1][1];
    }

    bool next_block_available(int direction, int x, int y) // 좌표와 방향을 입력하면 그 방향으로 1블럭 진행 가능한지 논리형 리턴
    {
        if (direction == 0)
        {
            if (x - 2 >= 0 && y - 1 >= 0)
                if (map_array[y - 1][x - 2])
                    return false;
            if (x - 1 >= 0 && y - 1 >= 0)
                if (map_array[y - 1][x - 1])
                    return false;
            if (x - 2 >= 0)
                if (map_array[y][x - 2])
                    return false;
            if (x - 1 >= 0)
                if (map_array[y][x - 1])
                    return false;
            if (x - 2 >= 0 && y + 1 < MAX_MAP_SIZE)
                if (map_array[y + 1][x - 2])
                    return false;
            if (x - 1 >= 0 && y + 1 < MAX_MAP_SIZE)
                if (map_array[y + 1][x - 1])
                    return false;
        }
        else if (direction == 1)
        {
            if (x - 1 >= 0 && y - 2 >= 0)
                if (map_array[y - 2][x - 1])
                    return false;
            if (y - 2 >= 0)
                if (map_array[y - 2][x])
                    return false;
            if (x + 1 < MAX_MAP_SIZE && y - 2 >= 0)
                if (map_array[y - 2][x + 1])
                    return false;
            if (x - 1 >= 0 && y - 1 >= 0)
                if (map_array[y - 1][x - 1])
                    return false;
            if (y - 1 >= 0)
                if (map_array[y - 1][x])
                    return false;
            if (x + 1 < MAX_MAP_SIZE && y - 1 >= 0)
                if (map_array[y - 1][x + 1])
                    return false;
        }
        else if (direction == 2)
        {
            if (x + 1 < MAX_MAP_SIZE && y - 1 >= 0)
                if (map_array[y - 1][x + 1])
                    return false;
            if (x + 2 < MAX_MAP_SIZE && y - 1 >= 0)
                if (map_array[y - 1][x + 2])
                    return false;
            if (x + 1 < MAX_MAP_SIZE)
                if (map_array[y][x + 1])
                    return false;
            if (x + 2 < MAX_MAP_SIZE)
                if (map_array[y][x + 2])
                    return false;
            if (x + 1 < MAX_MAP_SIZE && y + 1 < MAX_MAP_SIZE)
                if (map_array[y + 1][x + 1])
                    return false;
            if (x + 2 < MAX_MAP_SIZE && y + 1 < MAX_MAP_SIZE)
                if (map_array[y + 1][x + 2])
                    return false;
        }
        else if (direction == 3)
        {
            if (x - 1 >= 0 && y + 1 < MAX_MAP_SIZE)
                if (map_array[y + 1][x - 1])
                    return false;
            if (y + 1 < MAX_MAP_SIZE)
                if (map_array[y + 1][x])
                    return false;
            if (x + 1 < MAX_MAP_SIZE && y + 1 < MAX_MAP_SIZE)
                if (map_array[y + 1][x + 1])
                    return false;
            if (x - 1 >= 0 && y + 2 < MAX_MAP_SIZE)
                if (map_array[y + 2][x - 1])
                    return false;
            if (y + 2 < MAX_MAP_SIZE)
                if (map_array[y + 2][x])
                    return false;
            if (x + 1 < MAX_MAP_SIZE && y + 2 < MAX_MAP_SIZE)
                if (map_array[y + 2][x + 1])
                    return false;
        }
        else
        {
            cout << "ERROR(next block avail)";
        }
        return true;
    }

    bool dfs_on_side_path(int x, int y) // 입력된 포인터가 현재 맵 크기 +1칸인 사각형 길 위에 있는지 확인
    {
        if (x >= (MAX_MAP_SIZE - current_map_size) / 2 - 1 && x <= (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size)
            if (y == (MAX_MAP_SIZE - current_map_size) / 2 - 1 || y == (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size)
                return true;
        if (y >= (MAX_MAP_SIZE - current_map_size) / 2 - 1 && y <= (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size)
            if (x == (MAX_MAP_SIZE - current_map_size) / 2 - 1 || x == (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size)
                return true;
        return false;
    }

    void dfs_calc_distance(int point_x, int point_y, int c_x, int c_y, int len) // 포인터 x,y에서 c_x,c_y까지의 거리 측정 후, 전역변수 dfs_len에 저장
    {
        dfs_temp_map_array[c_y][c_x] = true;
        if (point_x == c_x && point_y == c_y)
        {
            dfs_num = len;
            return;
        }

        if (c_x > 0 && !dfs_temp_map_array[c_y][c_x - 1] && next_block_available(0, c_x, c_y))
            if (dfs_on_side_path(c_x - 1, c_y))
                dfs_calc_distance(point_x, point_y, c_x - 1, c_y, len + 1);
        if (c_y > 0 && !dfs_temp_map_array[c_y - 1][c_x] && next_block_available(1, c_x, c_y))
            if (dfs_on_side_path(c_x, c_y - 1))
                dfs_calc_distance(point_x, point_y, c_x, c_y - 1, len + 1);
        if (c_x + 1 < MAX_MAP_SIZE && !dfs_temp_map_array[c_y][c_x + 1] && next_block_available(2, c_x, c_y))
            if (dfs_on_side_path(c_x + 1, c_y))
                dfs_calc_distance(point_x, point_y, c_x + 1, c_y, len + 1);
        if (c_y + 1 < MAX_MAP_SIZE && !dfs_temp_map_array[c_y + 1][c_x] && next_block_available(3, c_x, c_y))
            if (dfs_on_side_path(c_x, c_y + 1))
                dfs_calc_distance(point_x, point_y, c_x, c_y + 1, len + 1);
        if (len > dfs_num)
            dfs_num = len;
    }

    void dfs_calc_distance_empty(int point_x, int point_y, int c_x, int c_y, int len) // 포인터 x,y에서 c_x,c_y까지의 거리 측정 후, 전역변수 dfs_len에 저장
    {
        dfs_temp_map_array[c_y][c_x] = true;
        if (point_x == c_x && point_y == c_y)
        {
            dfs_num = len;
            return;
        }

        if (c_x > 0 && !dfs_temp_map_array[c_y][c_x - 1])
            if (dfs_on_side_path(c_x - 1, c_y))
                dfs_calc_distance_empty(point_x, point_y, c_x - 1, c_y, len + 1);
        if (c_y > 0 && !dfs_temp_map_array[c_y - 1][c_x])
            if (dfs_on_side_path(c_x, c_y - 1))
                dfs_calc_distance_empty(point_x, point_y, c_x, c_y - 1, len + 1);
        if (c_x + 1 < MAX_MAP_SIZE && !dfs_temp_map_array[c_y][c_x + 1])
            if (dfs_on_side_path(c_x + 1, c_y))
                dfs_calc_distance_empty(point_x, point_y, c_x + 1, c_y, len + 1);
        if (c_y + 1 < MAX_MAP_SIZE && !dfs_temp_map_array[c_y + 1][c_x])
            if (dfs_on_side_path(c_x, c_y + 1))
                dfs_calc_distance_empty(point_x, point_y, c_x, c_y + 1, len + 1);
        if (len > dfs_num)
            dfs_num = len;
    }

    void dfs_fill_path(int point_x, int point_y, int c_x, int c_y, int len, int target_num, int sn) // 포인터 c_x, c_y에서 point_x,point_y까지 target_num만큼의 길을 채움 len은 1, sn(0=start, 1=end point)
    {
        dfs_temp_map_array[c_y][c_x] = true;
        map_array[c_y][c_x] = true;
        if (len == target_num)
        {
            if (sn == 0)
            {
                start_point[0] = c_x;
                start_point[1] = c_y;
                start_point[2] = find_dir(start_point[0], start_point[1]);
                if (start_point[2] == -1)
                    printf("ERROR(dfs_fill)");
                return;
            }
            else
            {
                end_point[0] = c_x;
                end_point[1] = c_y;
                end_point[2] = find_dir(end_point[0], end_point[1]);
                if (end_point[2] == -1)
                    printf("ERROR(dfs_fill)");
                return;
            }
        }

        if (c_x > 0 && !dfs_temp_map_array[c_y][c_x - 1] && next_block_available(0, c_x, c_y))
            if (dfs_on_side_path(c_x - 1, c_y))
                dfs_fill_path(point_x, point_y, c_x - 1, c_y, len + 1, target_num, sn);
        if (c_y > 0 && !dfs_temp_map_array[c_y - 1][c_x] && next_block_available(1, c_x, c_y))
            if (dfs_on_side_path(c_x, c_y - 1))
                dfs_fill_path(point_x, point_y, c_x, c_y - 1, len + 1, target_num, sn);
        if (c_x + 1 < MAX_MAP_SIZE && !dfs_temp_map_array[c_y][c_x + 1] && next_block_available(2, c_x, c_y))
            if (dfs_on_side_path(c_x + 1, c_y))
                dfs_fill_path(point_x, point_y, c_x + 1, c_y, len + 1, target_num, sn);
        if (c_y + 1 < MAX_MAP_SIZE && !dfs_temp_map_array[c_y + 1][c_x] && next_block_available(3, c_x, c_y))
            if (dfs_on_side_path(c_x, c_y + 1))
                dfs_fill_path(point_x, point_y, c_x, c_y + 1, len + 1, target_num, sn);
    }

    int find_dir(int x, int y) // 길 확장 후 ***_point[2]에 해당하는 dir 반환하는 함수
    {
        srand((unsigned int)time(NULL));
        int rand_num = rand() % 2;
        if (x < (MAX_MAP_SIZE - current_map_size) / 2 && y < (MAX_MAP_SIZE - current_map_size) / 2) // 좌측상단
        {
            if (rand_num == 0) // 왼쪽
            {
                return 0;
            }
            else // 위쪽
            {
                return 1;
            }
        }
        else if (x < (MAX_MAP_SIZE - current_map_size) / 2 && y >= current_map_size + (MAX_MAP_SIZE - current_map_size) / 2) // 좌측하단
        {
            if (rand_num == 0) // 왼쪽
            {
                return 0;
            }
            else // 아래쪽
            {
                return 3;
            }
        }
        else if (x >= current_map_size + (MAX_MAP_SIZE - current_map_size) / 2 && y < (MAX_MAP_SIZE - current_map_size) / 2) // 우측 상단
        {
            if (rand_num == 0) // 오른쪽
            {
                return 2;
            }
            else // 위쪽
            {
                return 1;
            }
        }
        else if (x >= current_map_size + (MAX_MAP_SIZE - current_map_size) / 2 && y >= current_map_size + (MAX_MAP_SIZE - current_map_size) / 2) // 우측하단
        {
            if (rand_num == 0) // 오른쪽
            {
                return 2;
            }
            else // 아래쪽
            {
                return 3;
            }
        }
        else if (x < (MAX_MAP_SIZE - current_map_size) / 2) // 좌측
        {
            return 0;
        }
        else if (y < (MAX_MAP_SIZE - current_map_size) / 2) // 상측
        {
            return 1;
        }
        else if (x >= current_map_size + (MAX_MAP_SIZE - current_map_size) / 2) // 우측
        {
            return 2;
        }
        else if (y >= current_map_size + (MAX_MAP_SIZE - current_map_size) / 2) // 하측
        {
            return 3;
        }
        return -1;
    }

    void quadrant_to_point(int quadrant, int re_arr[]) // 사분면과 반환받을 배열 입력하면 사분면의 포인터 반환
    {
        if (quadrant == 0)
        {
            re_arr[0] = (MAX_MAP_SIZE - current_map_size) / 2 - 1;
            re_arr[1] = (MAX_MAP_SIZE - current_map_size) / 2 - 1;
        }
        else if (quadrant == 1)
        {
            re_arr[0] = (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size;
            re_arr[1] = (MAX_MAP_SIZE - current_map_size) / 2 - 1;
        }
        else if (quadrant == 2)
        {
            re_arr[0] = (MAX_MAP_SIZE - current_map_size) / 2 - 1;
            re_arr[1] = (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size;
        }
        else if (quadrant == 3)
        {
            re_arr[0] = (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size;
            re_arr[1] = (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size;
        }
        else
        {
            cout << "ERROR(quadrant to point)" << quadrant << endl;
            return;
        }
    }

    int calc_distance_to_quadrant(int quadrant, int x, int y, int dir, int copy_map, int sn) // 사분면,좌표,dir(방향 0=left, 1=right), copy_map(기존의 맵을 복사해서 비교할지에 대한 변수 0=no, 1=yes), sn(0=start, 1=end point) 입력받은 포인터 x,y에서 입력한 사분면까지의 거리를 반환함.
    {
        int target_point[2]; // 목표 포인터
        int dir_check;
        quadrant_to_point(quadrant, target_point);

        if (copy_map == 1)
        {
            reset_dfs_arr(1);
        }
        else
        {
            reset_dfs_arr(0);
        }
        dfs_num = 0;
        // dfs_temp_map_array[y][x] = true;

        if (sn == 0)
        {
            dir_check = start_point[2];
        }
        else
        {
            dir_check = end_point[2];
        }

        if (dir_check == 2) // 포인터의 진행 방향이 오른쪽인 경우
        {
            if (dir == 0) // 오른쪽, 위쪽
            {
                if (copy_map == 1)
                {
                    if (next_block_available(1, x, y))
                    {
                        dfs_calc_distance(target_point[0], target_point[1], x, y - 1, 2); // up right
                    }
                    else
                    {
                        return 1;
                    }
                }
                else
                {
                    dfs_calc_distance_empty(target_point[0], target_point[1], x, y - 1, 2);
                }
                return dfs_num;
            }
            else if (dir == 1)
            {
                if (copy_map == 1)
                {
                    if (next_block_available(3, x, y))
                    {
                        dfs_calc_distance(target_point[0], target_point[1], x, y + 1, 2); // up right
                    }
                    else
                    {
                        return 1;
                    }
                }
                else
                {
                    dfs_calc_distance_empty(target_point[0], target_point[1], x, y + 1, 2);
                }
                return dfs_num;
            }
            else
            {
                return -1;
            }
        }
        else if (dir_check == 0) // 왼쪽
        {
            if (dir == 0)
            {
                if (copy_map == 1)
                {
                    if (next_block_available(3, x, y))
                    {
                        dfs_calc_distance(target_point[0], target_point[1], x, y + 1, 2); // up right
                    }
                    else
                    {
                        return 1;
                    }
                }
                else
                {
                    dfs_calc_distance_empty(target_point[0], target_point[1], x, y + 1, 2);
                }
                return dfs_num;
            }
            else if (dir == 1)
            {
                if (copy_map == 1)
                {
                    if (next_block_available(1, x, y))
                    {
                        dfs_calc_distance(target_point[0], target_point[1], x, y - 1, 2); // up right
                    }
                    else
                    {
                        return 1;
                    }
                }
                else
                {
                    dfs_calc_distance_empty(target_point[0], target_point[1], x, y - 1, 2);
                }
                return dfs_num;
            }
            else
            {
                return -1;
            }
        }
        else if (dir_check == 1)
        {
            if (dir == 0)
            {
                if (copy_map == 1)
                {
                    if (next_block_available(0, x, y))
                    {
                        dfs_calc_distance(target_point[0], target_point[1], x - 1, y, 2); // up right
                    }
                    else
                    {
                        return 1;
                    }
                }
                else
                {
                    dfs_calc_distance_empty(target_point[0], target_point[1], x - 1, y, 2);
                }
                return dfs_num;
            }
            else if (dir == 1)
            {
                if (copy_map == 1)
                {
                    if (next_block_available(2, x, y))
                    {
                        dfs_calc_distance(target_point[0], target_point[1], x + 1, y, 2); // up right
                    }
                    else
                    {
                        return 1;
                    }
                }
                else
                {
                    dfs_calc_distance_empty(target_point[0], target_point[1], x + 1, y, 2);
                }
                return dfs_num;
            }
            else
            {
                return -1;
            }
        }
        else if (dir_check == 3)
        {
            if (dir == 0)
            {
                if (copy_map == 1)
                {
                    if (next_block_available(2, x, y))
                    {
                        dfs_calc_distance(target_point[0], target_point[1], x + 1, y, 2); // up right
                    }
                    else
                    {
                        return 1;
                    }
                }
                else
                {
                    dfs_calc_distance_empty(target_point[0], target_point[1], x + 1, y, 2);
                }
                return dfs_num;
            }
            else if (dir == 1)
            {
                if (copy_map == 1)
                {
                    if (next_block_available(0, x, y))
                    {
                        dfs_calc_distance(target_point[0], target_point[1], x - 1, y, 2); // up right
                    }
                    else
                    {
                        return 1;
                    }
                }
                else
                {
                    dfs_calc_distance_empty(target_point[0], target_point[1], x - 1, y, 2);
                }
                return dfs_num;
            }
            else
            {
                return -1;
            }
        }
        else
        {
            cout << "ERROR(calc distance to quadrant)";
            return -1;
        }
        return -1;
    }

    bool go_or_turn(int root_max, int root_poss, float w) // 포인터까지의 최대 길이와 진행가능한 거리, 가중치 입력하면 1블럭갈지 목표 포인터까지 갈지 계산
    {
        if (root_poss == 1)
        {
            return false;
        }
        srand((unsigned int)time(NULL));
        int rand_num;
        int sum_max_poss;
        sum_max_poss = rand() % int(round(pow(root_max, 1 - w) * 0.2 + pow(root_poss, 1 + w) * 0.6));
        if (sum_max_poss < int(round(pow(root_poss, 1 + w))))
        {
            return true;
        }
        else
        {
            return false;
        }
        return false;
    }

    int rand_go_block_num(int root_max, int root_poss, float w) // 포인터까지의 최대 길이와 진행가능한 거리, 가중치 입력하면 몇 블럭을 갈지 반환
    {
        srand((unsigned int)time(NULL));
        int com_num = int(rand() % root_poss * (1 + root_poss / root_max)) + int(round(root_poss * w));
        if (com_num < 2)
        {
            return 2;
        }
        if (com_num > root_poss)
        {
            com_num = root_poss;
        }
        return com_num;
    }

    bool evaluate_root(int l_root_max, int l_root_poss, int r_root_max, int r_root_poss, float w) // 사분면, 포인터를 입력하면 전진할 방향(왼쪽(false), 오른쪽(true)) 반환, w = 가중치(0~1)가 클수록 멀고, 진행 가능한 블록이 많은 쪽으로 감
    {
        float left_path_weighted, right_path_weighted;   // 계산용
        int left_path_calculated, right_path_calculated; // 계산됨
        int rand_num;

        left_path_weighted = l_root_max * 0.6 + l_root_poss * 0.4;
        right_path_weighted = r_root_max * 0.6 + r_root_poss * 0.4;
        left_path_weighted = pow(left_path_weighted, 1 + w); // 기본 1 가중치 w(수정필요)
        left_path_weighted = round(left_path_weighted);
        left_path_calculated = int(left_path_weighted) + 1;
        right_path_weighted = pow(right_path_weighted, 1 + w);
        right_path_weighted = round(right_path_weighted);
        right_path_calculated = int(right_path_weighted) + 1;
        srand((unsigned int)time(NULL));
        rand_num = rand() % (left_path_calculated + right_path_calculated);
        if (rand_num < left_path_calculated)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

    int get_quadrant(int x, int y, float w) // 사분면 중 하나 가중치 계산 후 반환, w = 가중치(0~1)가 클수록 길이 없는 쪽으로 감
    {
        int road_dist[4];
        int rand_num, arr_sum = 0, sum_road_dist = 0;

        srand((unsigned int)time(NULL));
        cal_road_distributions(road_dist);
        for (int i = 0; i < 4; i++)
        {
            road_dist[i] = int(round(pow(road_dist[i], 1 + w))); // 기본 1 가중치 w(수정필요)
            arr_sum += road_dist[i];
        }
        rand_num = rand() % arr_sum;
        for (int i = 0; i < 4; i++)
        {
            sum_road_dist += road_dist[i];
            if (rand_num < sum_road_dist)
            {
                return i;
            }
        }
        return -1;
    }

    void next_block_point(int sn, int re_arr[]) // sn=(0=start_point, 1=end_point), re_arr[]=끝점의 다음 블록 반환
    {
        if (sn == 0)
        {
            if (start_point[2] == 0)
            {
                re_arr[0] = start_point[0] - 1;
                re_arr[1] = start_point[1];
            }
            else if (start_point[2] == 1)
            {
                re_arr[0] = start_point[0];
                re_arr[1] = start_point[1] - 1;
            }
            else if (start_point[2] == 2)
            {
                re_arr[0] = start_point[0] + 1;
                re_arr[1] = start_point[1];
            }
            else if (start_point[2] == 3)
            {
                re_arr[0] = start_point[0];
                re_arr[1] = start_point[1] + 1;
            }
        }
        else if (sn == 1)
        {
            if (end_point[2] == 0)
            {
                re_arr[0] = end_point[0] - 1;
                re_arr[1] = end_point[1];
            }
            else if (end_point[2] == 1)
            {
                re_arr[0] = end_point[0];
                re_arr[1] = end_point[1] - 1;
            }
            else if (end_point[2] == 2)
            {
                re_arr[0] = end_point[0] + 1;
                re_arr[1] = end_point[1];
            }
            else if (end_point[2] == 3)
            {
                re_arr[0] = end_point[0];
                re_arr[1] = end_point[1] + 1;
            }
        }
    }

public:
    void find_corner()
    {
        for (int i = 0; i < MAX_MAP_SIZE; i++)
            for (int j = 0; j < MAX_MAP_SIZE; j++)
                map_corner[i][j] = 0;
        reset_dfs_arr(0);
        map_corner[start_point[1]][start_point[0]] = 1;
        dfs_find_corner(start_point[0], start_point[1], start_point[2], 1);
    }

    void expand_map() // 맵 사이즈 확대 (4방향으로 1칸씩)
    {
        srand((unsigned int)time(NULL));
        int start_select = rand() % 2;
        int left_path_size[2], right_path_size[2]; //[0]=max,[1]=진행가능거리
        int dest_quadrant;
        int point[2]; //[0]=x,[1]=y
        int go_block_num;
        int quad_point[2];
        int cna[2];
        if (start_select == 0) // start first
        {
            // start
            next_block_point(0, point);
            dest_quadrant = get_quadrant(point[0], point[1], 0);
            left_path_size[0] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 0, 0, 0);
            left_path_size[1] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 0, 1, 0);
            right_path_size[0] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 1, 0, 0);
            right_path_size[1] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 1, 1, 0);
            quadrant_to_point(dest_quadrant, quad_point);
            if (!evaluate_root(left_path_size[0], left_path_size[1], right_path_size[0], right_path_size[1], 0)) // 왼쪽으로 진행
            {
                if (go_or_turn(left_path_size[0], left_path_size[1], weighted_num)) // 한블럭 진행이 아닌 사분면의 포인터까지 진행
                {
                    go_block_num = rand_go_block_num(left_path_size[0], left_path_size[1], weighted_num);
                    reset_dfs_arr(0);
                    map_array[point[1]][point[0]] = true;
                    dfs_temp_map_array[point[1]][point[0]] = true;
                    only_dfs_dir(0, 0, cna);
                    dfs_fill_path(quad_point[0], quad_point[1], point[0] + cna[0], point[1] + cna[1], 2, go_block_num, 0);
                }
                else // 한블럭 진행
                {
                    map_array[point[1]][point[0]] = true;
                    start_point[0] = point[0];
                    start_point[1] = point[1];
                    start_point[2] = find_dir(point[0], point[1]);
                }
            }
            else // 오른쪽으로 진행
            {
                if (go_or_turn(right_path_size[0], right_path_size[1], weighted_num)) // 한블럭 진행이 아닌 사분면의 포인터까지 진행
                {
                    go_block_num = rand_go_block_num(right_path_size[0], right_path_size[1], weighted_num);
                    reset_dfs_arr(0);
                    map_array[point[1]][point[0]] = true;
                    dfs_temp_map_array[point[1]][point[0]] = true;
                    only_dfs_dir(1, 0, cna);
                    dfs_fill_path(quad_point[0], quad_point[1], point[0] + cna[0], point[1] + cna[1], 2, go_block_num, 0);
                }
                else // 한블럭 진행
                {
                    map_array[point[1]][point[0]] = true;
                    start_point[0] = point[0];
                    start_point[1] = point[1];
                    start_point[2] = find_dir(point[0], point[1]);
                }
            }
            // end
            next_block_point(1, point);
            dest_quadrant = get_quadrant(point[0], point[1], weighted_num);
            left_path_size[0] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 0, 0, 1);
            left_path_size[1] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 0, 1, 1);
            right_path_size[0] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 1, 0, 1);
            right_path_size[1] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 1, 1, 1);
            quadrant_to_point(dest_quadrant, quad_point);
            if (!evaluate_root(left_path_size[0], left_path_size[1], right_path_size[0], right_path_size[1], 0)) // 왼쪽으로 진행
            {
                if (go_or_turn(left_path_size[0], left_path_size[1], 0)) // 한블럭 진행이 아닌 사분면의 포인터까지 진행
                {
                    go_block_num = rand_go_block_num(left_path_size[0], left_path_size[1], weighted_num);
                    reset_dfs_arr(0);
                    map_array[point[1]][point[0]] = true;
                    dfs_temp_map_array[point[1]][point[0]] = true;
                    only_dfs_dir(0, 1, cna);
                    dfs_fill_path(quad_point[0], quad_point[1], point[0] + cna[0], point[1] + cna[1], 2, go_block_num, 1);
                }
                else // 한블럭 진행
                {
                    map_array[point[1]][point[0]] = true;
                    end_point[0] = point[0];
                    end_point[1] = point[1];
                    end_point[2] = find_dir(point[0], point[1]);
                }
            }
            else // 오른쪽으로 진행
            {
                if (go_or_turn(right_path_size[0], right_path_size[1], 0)) // 한블럭 진행이 아닌 사분면의 포인터까지 진행
                {
                    go_block_num = rand_go_block_num(right_path_size[0], right_path_size[1], weighted_num);
                    reset_dfs_arr(0);
                    map_array[point[1]][point[0]] = true;
                    dfs_temp_map_array[point[1]][point[0]] = true;
                    only_dfs_dir(1, 1, cna);
                    dfs_fill_path(quad_point[0], quad_point[1], point[0] + cna[0], point[1] + cna[1], 2, go_block_num, 1);
                }
                else // 한블럭 진행
                {
                    map_array[point[1]][point[0]] = true;
                    end_point[0] = point[0];
                    end_point[1] = point[1];
                    end_point[2] = find_dir(point[0], point[1]);
                }
            }
        }
        else // end first
        {
            // end
            next_block_point(1, point);
            dest_quadrant = get_quadrant(point[0], point[1], weighted_num);
            left_path_size[0] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 0, 0, 1);
            left_path_size[1] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 0, 1, 1);
            right_path_size[0] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 1, 0, 1);
            right_path_size[1] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 1, 1, 1);
            quadrant_to_point(dest_quadrant, quad_point);
            if (!evaluate_root(left_path_size[0], left_path_size[1], right_path_size[0], right_path_size[1], 0)) // 왼쪽으로 진행
            {
                if (go_or_turn(left_path_size[0], left_path_size[1], weighted_num)) // 한블럭 진행이 아닌 사분면의 포인터까지 진행
                {
                    go_block_num = rand_go_block_num(left_path_size[0], left_path_size[1], weighted_num);
                    reset_dfs_arr(0);
                    map_array[point[1]][point[0]] = true;
                    dfs_temp_map_array[point[1]][point[0]] = true;
                    only_dfs_dir(0, 1, cna);
                    dfs_fill_path(quad_point[0], quad_point[1], point[0] + cna[0], point[1] + cna[1], 2, go_block_num, 1);
                }
                else // 한블럭 진행
                {
                    map_array[point[1]][point[0]] = true;
                    end_point[0] = point[0];
                    end_point[1] = point[1];
                    end_point[2] = find_dir(point[0], point[1]);
                }
            }
            else // 오른쪽으로 진행
            {
                if (go_or_turn(right_path_size[0], right_path_size[1], weighted_num)) // 한블럭 진행이 아닌 사분면의 포인터까지 진행
                {
                    go_block_num = rand_go_block_num(right_path_size[0], right_path_size[1], weighted_num);
                    reset_dfs_arr(0);
                    map_array[point[1]][point[0]] = true;
                    dfs_temp_map_array[point[1]][point[0]] = true;
                    only_dfs_dir(1, 1, cna);
                    dfs_fill_path(quad_point[0], quad_point[1], point[0] + cna[0], point[1] + cna[1], 2, go_block_num, 1);
                }
                else // 한블럭 진행
                {
                    map_array[point[1]][point[0]] = true;
                    end_point[0] = point[0];
                    end_point[1] = point[1];
                    end_point[2] = find_dir(point[0], point[1]);
                }
            }
            // start
            next_block_point(0, point);
            dest_quadrant = get_quadrant(point[0], point[1], weighted_num);
            left_path_size[0] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 0, 0, 0);
            left_path_size[1] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 0, 1, 0);
            right_path_size[0] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 1, 0, 0);
            right_path_size[1] = calc_distance_to_quadrant(dest_quadrant, point[0], point[1], 1, 1, 0);
            quadrant_to_point(dest_quadrant, quad_point);
            if (!evaluate_root(left_path_size[0], left_path_size[1], right_path_size[0], right_path_size[1], weighted_num)) // 왼쪽으로 진행
            {
                if (go_or_turn(left_path_size[0], left_path_size[1], weighted_num)) // 한블럭 진행이 아닌 사분면의 포인터까지 진행
                {
                    go_block_num = rand_go_block_num(left_path_size[0], left_path_size[1], weighted_num);
                    reset_dfs_arr(0);
                    map_array[point[1]][point[0]] = true;
                    dfs_temp_map_array[point[1]][point[0]] = true;
                    only_dfs_dir(0, 0, cna);
                    dfs_fill_path(quad_point[0], quad_point[1], point[0] + cna[0], point[1] + cna[1], 2, go_block_num, 0);
                }
                else // 한블럭 진행
                {
                    map_array[point[1]][point[0]] = true;
                    start_point[0] = point[0];
                    start_point[1] = point[1];
                    start_point[2] = find_dir(point[0], point[1]);
                }
            }
            else // 오른쪽으로 진행
            {
                if (go_or_turn(right_path_size[0], right_path_size[1], weighted_num)) // 한블럭 진행이 아닌 사분면의 포인터까지 진행
                {
                    go_block_num = rand_go_block_num(right_path_size[0], right_path_size[1], weighted_num);
                    reset_dfs_arr(0);
                    map_array[point[1]][point[0]] = true;
                    dfs_temp_map_array[point[1]][point[0]] = true;
                    only_dfs_dir(1, 0, cna);
                    dfs_fill_path(quad_point[0], quad_point[1], point[0] + cna[0], point[1] + cna[1], 2, go_block_num, 0);
                }
                else // 한블럭 진행
                {
                    map_array[point[1]][point[0]] = true;
                    start_point[0] = point[0];
                    start_point[1] = point[1];
                    start_point[2] = find_dir(point[0], point[1]);
                }
            }
        }
        current_map_size += 2;
    }

    void get_start_point(int t_arr[]) // return start_point, input array's adress
    {
        t_arr[0] = start_point[0];
        t_arr[1] = start_point[1];
    }

    void get_end_point(int t_arr[]) // return end_point, input array's adress
    {
        t_arr[0] = end_point[0];
        t_arr[1] = end_point[1];
    }

    int get_map_size() // return map_size
    {
        return current_map_size;
    }

    void output_map()
    {
        for (int i = (MAX_MAP_SIZE - current_map_size) / 2; i < (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size; i++)
        {
            for (int j = (MAX_MAP_SIZE - current_map_size) / 2; j < (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size; j++)
                if (map_array[i][j])
                {
                    cout << "◻︎";
                }
                else
                {
                    cout << "◼︎";
                }
            cout << endl;
        }
        cout << endl;
    }

    void output_map_cor()
    {
        find_corner();
        for (int i = (MAX_MAP_SIZE - current_map_size) / 2; i < (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size; i++)
        {
            for (int j = (MAX_MAP_SIZE - current_map_size) / 2; j < (MAX_MAP_SIZE - current_map_size) / 2 + current_map_size; j++)
                cout << map_corner[i][j];
            cout << endl;
        }
        cout << endl;
    }

    map()
    {
        current_map_size = 2;
        srand((unsigned int)time(NULL));
        for (int i = 0; i < MAX_MAP_SIZE; i++) // map_array reset
            for (int j = 0; j < MAX_MAP_SIZE; j++)
                map_array[i][j] = false;
        // make a 2 x 2 random map
        int rand_num = rand() % 2 + 1; // 길 갯수 2~3
        int rand_num_arr[2];
        int rand_num_start[3];
        if (rand_num == 0) // 길 1개(버그로 인해 삭제)
        {                  /*
                              rand_num_arr[0] = rand() % 2; // x
                              rand_num_arr[1] = rand() % 2; // y
                              rand_num_start[0] = rand() % 2;
                              map_array[(MAX_MAP_SIZE - current_map_size) / 2 + rand_num_arr[1]][(MAX_MAP_SIZE - current_map_size) / 2 + rand_num_arr[0]] = true;
                              start_point[0] = (MAX_MAP_SIZE - current_map_size) / 2 + rand_num_arr[0];
                              start_point[1] = (MAX_MAP_SIZE - current_map_size) / 2 + rand_num_arr[1];
                              end_point[0] = start_point[0];
                              end_point[1] = start_point[1];
                 
                              if (rand_num_arr[0] == 0) // 길x위치
                              {
                                  if (rand_num_arr[1] == 0) // 길y위치
                                  {
                                      if (rand_num_start[0] == 0)
                                      {
                                          start_point[2] = 0;
                                          end_point[2] = 1;
                                      }
                                      else
                                      {
                                          start_point[2] = 1;
                                          end_point[2] = 0;
                                      }
                                  }
                                  else
                                  {
                                      if (rand_num_start[0] == 0)
                                      {
                                          start_point[2] = 0;
                                          end_point[2] = 3;
                                      }
                                      else
                                      {
                                          start_point[2] = 3;
                                          end_point[2] = 0;
                                      }
                                  }
                              }
                              else
                              {
                                  if (rand_num_arr[1] == 0)
                                  {
                                      if (rand_num_start[0] == 0)
                                      {
                                          start_point[2] = 1;
                                          end_point[2] = 2;
                                      }
                                      else
                                      {
                                          start_point[2] = 2;
                                          end_point[2] = 1;
                                      }
                                  }
                                  else
                                  {
                                      if (rand_num_start[0] == 0)
                                      {
                                          start_point[2] = 2;
                                          end_point[2] = 3;
                                      }
                                      else
                                      {
                                          start_point[2] = 3;
                                          end_point[2] = 2;
                                      }
                                  }
                              }
                              */
        }
        else if (rand_num == 1) // 길 2개
        {
            rand_num_arr[0] = rand() % 4;
            rand_num_arr[1] = rand() % 2;
            rand_num_start[0] = rand() % 2;
            rand_num_start[1] = rand() % 2;
            if (rand_num_arr[0] == 0) // 기준점 왼쪽위
            {
                if (rand_num_arr[1] == 0) // 추가된 길이 x+1경우
                {
                    map_array[(MAX_MAP_SIZE - current_map_size) / 2][(MAX_MAP_SIZE - current_map_size) / 2] = true;
                    map_array[(MAX_MAP_SIZE - current_map_size) / 2][(MAX_MAP_SIZE - current_map_size) / 2 + 1] = true;
                    start_point[0] = (MAX_MAP_SIZE - current_map_size) / 2;
                    start_point[1] = (MAX_MAP_SIZE - current_map_size) / 2;
                    end_point[0] = (MAX_MAP_SIZE - current_map_size) / 2 + 1;
                    end_point[1] = (MAX_MAP_SIZE - current_map_size) / 2;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 0;
                            end_point[2] = 1;
                        }
                        else
                        {
                            start_point[2] = 0;
                            end_point[2] = 2;
                        }
                    }
                    else
                    {
                        start_point[2] = 1;
                        end_point[2] = 2;
                    }
                }
                else // 추가된 길이 y+1인 경우
                {
                    map_array[(MAX_MAP_SIZE - current_map_size) / 2][(MAX_MAP_SIZE - current_map_size) / 2] = true;
                    map_array[(MAX_MAP_SIZE - current_map_size) / 2 + 1][(MAX_MAP_SIZE - current_map_size) / 2] = true;
                    start_point[0] = (MAX_MAP_SIZE - current_map_size) / 2;
                    start_point[1] = (MAX_MAP_SIZE - current_map_size) / 2;
                    end_point[0] = (MAX_MAP_SIZE - current_map_size) / 2;
                    end_point[1] = (MAX_MAP_SIZE - current_map_size) / 2 + 1;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 1;
                            end_point[2] = 0;
                        }
                        else
                        {
                            start_point[2] = 1;
                            end_point[2] = 3;
                        }
                    }
                    else
                    {
                        start_point[2] = 0;
                        end_point[2] = 3;
                    }
                }
            }
            else if (rand_num_arr[0] == 1) // 기준점 오른쪽위
            {
                if (rand_num_arr[1] == 0)
                {
                    map_array[(MAX_MAP_SIZE - 2) / 2][(MAX_MAP_SIZE - 2) / 2 + 1] = true;
                    map_array[(MAX_MAP_SIZE - 2) / 2][(MAX_MAP_SIZE - 2) / 2] = true;
                    start_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    start_point[1] = (MAX_MAP_SIZE - 2) / 2;
                    end_point[0] = (MAX_MAP_SIZE - 2) / 2;
                    end_point[1] = (MAX_MAP_SIZE - 2) / 2;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 2;
                            end_point[2] = 0;
                        }
                        else
                        {
                            start_point[2] = 2;
                            end_point[2] = 1;
                        }
                    }
                    else
                    {
                        start_point[2] = 1;
                        end_point[2] = 0;
                    }
                }
                else
                {
                    map_array[(MAX_MAP_SIZE - 2) / 2 ][(MAX_MAP_SIZE - 2) / +1] = true;
                    map_array[(MAX_MAP_SIZE - 2) / 2 + 1][(MAX_MAP_SIZE - 2) / 2 + 1] = true;
                    start_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    start_point[1] = (MAX_MAP_SIZE - 2) / 2;
                    end_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 1;
                            end_point[2] = 2;
                        }
                        else
                        {
                            start_point[2] = 1;
                            end_point[2] = 3;
                        }
                    }
                    else
                    {
                        start_point[2] = 2;
                        end_point[2] = 3;
                    }
                }
            }
            else if (rand_num_arr[0] == 2) // 기준점 왼쪽아래
            {
                if (rand_num_arr[1] == 0)
                {
                    map_array[(MAX_MAP_SIZE - 2) / 2 + 1][(MAX_MAP_SIZE - 2) / 2] = true;
                    map_array[(MAX_MAP_SIZE - 2) / 2][(MAX_MAP_SIZE - 2) / 2] = true;
                    start_point[0] = (MAX_MAP_SIZE - 2) / 2;
                    start_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[0] = (MAX_MAP_SIZE - 2) / 2;
                    end_point[1] = (MAX_MAP_SIZE - 2) / 2;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 3;
                            end_point[2] = 1;
                        }
                        else
                        {
                            start_point[2] = 3;
                            end_point[2] = 0;
                        }
                    }
                    else
                    {
                        start_point[2] = 0;
                        end_point[2] = 1;
                    }
                }
                else
                {
                    map_array[(MAX_MAP_SIZE - 2) / 2 + 1][(MAX_MAP_SIZE - 2) / 2] = true;
                    map_array[(MAX_MAP_SIZE - 2) / 2 + 1][(MAX_MAP_SIZE - 2) / 2 + 1] = true;
                    start_point[0] = (MAX_MAP_SIZE - 2) / 2;
                    start_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 0;
                            end_point[2] = 3;
                        }
                        else
                        {
                            start_point[2] = 0;
                            end_point[2] = 2;
                        }
                    }
                    else
                    {
                        start_point[2] = 3;
                        end_point[2] = 2;
                    }
                }
            }
            else // 기준점 오른쪽 아래
            {
                if (rand_num_arr[1] == 0)
                {
                    map_array[(MAX_MAP_SIZE - 2) / 2 + 1][(MAX_MAP_SIZE - 2) / 2 + 1] = true;
                    map_array[(MAX_MAP_SIZE - 2) / 2 + 1][(MAX_MAP_SIZE - 2) / 2] = true;
                    start_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    start_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[0] = (MAX_MAP_SIZE - 2) / 2;
                    end_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 2;
                            end_point[2] = 0;
                        }
                        else
                        {
                            start_point[2] = 2;
                            end_point[2] = 3;
                        }
                    }
                    else
                    {
                        start_point[2] = 3;
                        end_point[2] = 0;
                    }
                }
                else
                {
                    map_array[(MAX_MAP_SIZE - 2) / 2 + 1][(MAX_MAP_SIZE - 2) / 2 + 1] = true;
                    map_array[(MAX_MAP_SIZE - 2) / 2][(MAX_MAP_SIZE - 2) / 2 + 1] = true;
                    start_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    start_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[1] = (MAX_MAP_SIZE - 2) / 2;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 3;
                            end_point[2] = 1;
                        }
                        else
                        {
                            start_point[2] = 3;
                            end_point[2] = 2;
                        }
                    }
                    else
                    {
                        start_point[2] = 2;
                        end_point[2] = 1;
                    }
                }
            }
        }
        else if (rand_num == 2) // 길 3개
        {
            rand_num_arr[0] = rand() % 4;
            rand_num_start[0] = rand() % 2;
            rand_num_start[1] = rand() % 2;
            rand_num_start[2] = rand() % 2;
            if (rand_num_arr[0] == 0)
            {
                map_array[(MAX_MAP_SIZE - 2) / 2][(MAX_MAP_SIZE - 2) / 2 + 1] = true;
                map_array[(MAX_MAP_SIZE - 2) / 2 + 1][(MAX_MAP_SIZE - 2) / 2] = true;
                map_array[(MAX_MAP_SIZE - 2) / 2 + 1][(MAX_MAP_SIZE - 2) / 2 + 1] = true;
                if (rand_num_start[2] == 0)
                {
                    start_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    start_point[1] = (MAX_MAP_SIZE - 2) / 2;
                    end_point[0] = (MAX_MAP_SIZE - 2) / 2;
                    end_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 1;
                            end_point[2] = 3;
                        }
                        else
                        {
                            start_point[2] = 1;
                            end_point[2] = 0;
                        }
                    }
                    else
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 2;
                            end_point[2] = 3;
                        }
                        else
                        {
                            start_point[2] = 2;
                            end_point[2] = 0;
                        }
                    }
                }
                else
                {
                    start_point[0] = (MAX_MAP_SIZE - 2) / 2;
                    start_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[1] = (MAX_MAP_SIZE - 2) / 2;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 3;
                            end_point[2] = 1;
                        }
                        else
                        {
                            start_point[2] = 0;
                            end_point[2] = 1;
                        }
                    }
                    else
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 3;
                            end_point[2] = 2;
                        }
                        else
                        {
                            start_point[2] = 0;
                            end_point[2] = 2;
                        }
                    }
                }
            }
            else if (rand_num_arr[0] == 1)
            {
                map_array[(MAX_MAP_SIZE - 2) / 2][(MAX_MAP_SIZE - 2) / 2] = true;
                map_array[(MAX_MAP_SIZE - 2) / 2 + 1][(MAX_MAP_SIZE - 2) / 2] = true;
                map_array[(MAX_MAP_SIZE - 2) / 2 + 1][(MAX_MAP_SIZE - 2) / 2 + 1] = true;
                if (rand_num_start[2] == 0)
                {
                    start_point[0] = (MAX_MAP_SIZE - 2) / 2;
                    start_point[1] = (MAX_MAP_SIZE - 2) / 2;
                    end_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 0;
                            end_point[2] = 2;
                        }
                        else
                        {
                            start_point[2] = 0;
                            end_point[2] = 3;
                        }
                    }
                    else
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 1;
                            end_point[2] = 2;
                        }
                        else
                        {
                            start_point[2] = 1;
                            end_point[2] = 3;
                        }
                    }
                }
                else
                {
                    start_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    start_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[0] = (MAX_MAP_SIZE - 2) / 2;
                    end_point[1] = (MAX_MAP_SIZE - 2) / 2;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 2;
                            end_point[2] = 0;
                        }
                        else
                        {
                            start_point[2] = 3;
                            end_point[2] = 0;
                        }
                    }
                    else
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 2;
                            end_point[2] = 1;
                        }
                        else
                        {
                            start_point[2] = 3;
                            end_point[2] = 1;
                        }
                    }
                }
            }
            else if (rand_num_arr[0] == 2)
            {
                map_array[(MAX_MAP_SIZE - 2) / 2][(MAX_MAP_SIZE - 2) / 2] = true;
                map_array[(MAX_MAP_SIZE - 2) / 2][(MAX_MAP_SIZE - 2) / 2 + 1] = true;
                map_array[(MAX_MAP_SIZE - 2) / 2 + 1][(MAX_MAP_SIZE - 2) / 2 + 1] = true;
                if (rand_num_start[2] == 0)
                {
                    start_point[0] = (MAX_MAP_SIZE - 2) / 2;
                    start_point[1] = (MAX_MAP_SIZE - 2) / 2;
                    end_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 0;
                            end_point[2] = 2;
                        }
                        else
                        {
                            start_point[2] = 0;
                            end_point[2] = 3;
                        }
                    }
                    else
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 1;
                            end_point[2] = 2;
                        }
                        else
                        {
                            start_point[2] = 1;
                            end_point[2] = 3;
                        }
                    }
                }
                else
                {
                    start_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    start_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[0] = (MAX_MAP_SIZE - 2) / 2;
                    end_point[1] = (MAX_MAP_SIZE - 2) / 2;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 2;
                            end_point[2] = 0;
                        }
                        else
                        {
                            start_point[2] = 3;
                            end_point[2] = 0;
                        }
                    }
                    else
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 2;
                            end_point[2] = 1;
                        }
                        else
                        {
                            start_point[2] = 3;
                            end_point[2] = 1;
                        }
                    }
                }
            }
            else
            {
                map_array[(MAX_MAP_SIZE - 2) / 2][(MAX_MAP_SIZE - 2) / 2] = true;
                map_array[(MAX_MAP_SIZE - 2) / 2][(MAX_MAP_SIZE - 2) / 2 + 1] = true;
                map_array[(MAX_MAP_SIZE - 2) / 2 + 1][(MAX_MAP_SIZE - 2) / 2] = true;
                if (rand_num_start[2] == 0)
                {
                    start_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    start_point[1] = (MAX_MAP_SIZE - 2) / 2;
                    end_point[0] = (MAX_MAP_SIZE - 2) / 2;
                    end_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 2;
                            end_point[2] = 3;
                        }
                        else
                        {
                            start_point[2] = 2;
                            end_point[2] = 0;
                        }
                    }
                    else
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 1;
                            end_point[2] = 3;
                        }
                        else
                        {
                            start_point[2] = 1;
                            end_point[2] = 0;
                        }
                    }
                }
                else
                {
                    start_point[0] = (MAX_MAP_SIZE - 2) / 2;
                    start_point[1] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[0] = (MAX_MAP_SIZE - 2) / 2 + 1;
                    end_point[1] = (MAX_MAP_SIZE - 2) / 2;
                    if (rand_num_start[0] == 0)
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 3;
                            end_point[2] = 2;
                        }
                        else
                        {
                            start_point[2] = 0;
                            end_point[2] = 2;
                        }
                    }
                    else
                    {
                        if (rand_num_start[1] == 0)
                        {
                            start_point[2] = 3;
                            end_point[2] = 1;
                        }
                        else
                        {
                            start_point[2] = 0;
                            end_point[2] = 1;
                        }
                    }
                }
            }
        }
    }
};

extern map myInstance;

int main(void)
{
    map game_map = map();

    int a = 1;
    while (1)
    {
        cout << "1=print map, 2=expandmap, 3=print corner map, others=exit";
        cin >> a;
        if (a == 1)
        {
            game_map.output_map();
        }
        else if (a == 2)
        {
            game_map.expand_map();
        }
        else if (a == 3)
        {
            game_map.output_map_cor();
        }
        else
        {
            break;
        }
    }
    /*
    game_map.output_map();
    game_map.expand_map();
    game_map.output_map();
    game_map.expand_map();
    game_map.output_map();
    */
}