// Use this for initialization
    void Start()
    {
        roomCount  = myLevelData.roomCount; // Each row/column will have this number + 1 rooms. Room count is actually (roomCount + 1)^2
        roomHeight = (myLevelData.mapHalfHeight) / roomCount;
        roomWidth  = (myLevelData.mapHalfWidth) / roomCount;

        Debug.Log("Room Width: " + roomWidth);
        Debug.Log("Room Height: " + roomHeight);

        for (int i = -(roomCount / 2); i <= roomCount / 2; i++)
        {
            for (int j = -(roomCount / 2); j <= roomCount / 2; j++)
            {
                int newLocX = i * (roomWidth);
                int newLocY = j * (roomHeight);
                roomLocs.Add(new Vector2(newLocX, newLocY));
                roomData newRoom = new roomData();
                newRoom.location = new Vector2(newLocX, newLocY);
                rooms.Add(newRoom);
            }
        }

        mapLimitX = (int)((roomCount / 2) * roomWidth) + roomWidth / 2;
        mapLimitY = (int)((roomCount / 2) * roomHeight) + roomHeight / 2;

        Debug.Log("Map Limit is: " + mapLimitX + ", " + mapLimitY);
        cornerRoomCheck();
        // initiateRoomColor();
        initiateCritPathBuild();
        buildLevel();
        // shuffle(playerStartPos);
        Debug.Log("FINISHED!");
        StartCoroutine(visualizeCritPath());
    }
Exemple #2
0
    void checkForHashClones(int layers)
    {
        int clonecount = 0;
        Dictionary <int, roomData> hash = new Dictionary <int, roomData>();

        for (int i = 0; i <= layers; i++)
        {
            for (int p = 0; p <= Mathf.Pow(3, i); p++)
            {
                roomData room = new roomData((uint)i, (uint)p);
                int      num  = room.GetHashCode();
                if (hash.ContainsKey(num))
                {
                    print("1# " + hash[num].layerNumber + ", " + hash[num].roomNumber + ": " + hash[num].GetHashCode());
                    print("2# " + room.layerNumber + ", " + room.roomNumber + ": " + room.GetHashCode());
                    clonecount++;
                }
                else
                {
                    hash.Add(num, room);
                }
            }
        }
        print("clone count: " + clonecount);
    }
    void tilePathfinding(roomData currRoom, roomData nextRoom) // YO DAWG, I HEARD YOU LIKE A*!
    {
        Debug.Log("Started tilePathfinding from room" + currRoom.location);
        Debug.Log("Going to " + nextRoom.location);

        Queue <Vertex> toBeSearched = new Queue <Vertex>();
        List <Vector2> beenThere    = new List <Vector2>();

        Vector2[] dirs =
        {
            new Vector2(1,   0),
            new Vector2(-1,  0),
            new Vector2(0,   1),
            new Vector2(0,  -1),
        };
        Vertex current = new Vertex();

        current.loc      = currRoom.location;
        current.moveCost = manhattanDistance(current.loc, nextRoom.location);
        toBeSearched.Enqueue(current);
        while (toBeSearched.Count > 0)
        {
            current = toBeSearched.Dequeue();
            if (current.loc == nextRoom.location ||
                critPath.Contains(current.loc))
            {
                while (current != null)
                {
                    critPath.Add(current.loc);
                    current = current.parent;
                }
            }
            List <Vertex> potentialSearches = new List <Vertex>();
            for (int i = 0; i < dirs.Length; i++)
            {
                Vector2 newLoc = current.loc + dirs[i];
                int     dist   = manhattanDistance(newLoc, nextRoom.location);
                if (isInMap(newLoc) && dist <= current.moveCost + 1 && !beenThere.Contains(newLoc))
                {
                    Vertex nextVertex = new Vertex();
                    nextVertex.loc      = newLoc;
                    nextVertex.parent   = current;
                    nextVertex.moveCost = dist;
                    nextVertex.pathDir  = dirs[i];
                    potentialSearches.Add(nextVertex);
                }
            }
            if (toBeSearched.Count > 0)
            {
                Debug.Log("Adding a thing!");
                toBeSearched.Enqueue(potentialSearches[Random.Range(0, potentialSearches.Count)]);
            }
            beenThere.Add(current.loc);
        }
    }
Exemple #4
0
    public roomData goBack(roomData room)
    {
        if (room.layerNumber <= 0)
        {
            return(null);
        }

        roomData nextRoom = new roomData(room.layerNumber - 1, room.roomNumber / 3);

        return(nextRoom);
    }
Exemple #5
0
    public roomData goRight(roomData room)
    {
        if (room.layerNumber >= 20)
        {
            return(null);
        }

        roomData nextRoom = new roomData(room.layerNumber + 1, room.roomNumber * 3 + 2);

        return(nextRoom);
    }
Exemple #6
0
    roomData goBack()
    {
        roomData tempRoom = currentRoom.goBack(currentRoom);

        if (tempRoom == null)
        {
            return(currentRoom);
        }

        currentRoom = tempRoom;
        return(currentRoom);
    }
Exemple #7
0
    roomData goMiddle()
    {
        roomData tempRoom = currentRoom.goMiddle(currentRoom);

        if (tempRoom == null)
        {
            return(currentRoom);
        }

        currentRoom = tempRoom;
        return(currentRoom);
    }
Exemple #8
0
    void Start()
    {
        initDoors();

        currentRoom = new roomData(0, 0);


        buildScene(currentRoom);

        //checkForHashClones(13);
        //checkForClonesGames(10000, 19);
    }
Exemple #9
0
        public static async Task<string> createRoom( string uuid_creator, int partcipants_limit  = 30 )
        {
          

            roomData nonCached = new roomData(partcipants_limit, uuid_creator);
            Console.WriteLine( "nonCached.uuid_creator" + nonCached.uuid_creator );
            await databaseManager.updateQuery( "INSERT INTO rooms (uuid, uuid_creator, participants_limit) VALUES(@uuid, @uuid_creator, @participants_limit)" )
                .addValue("@uuid", nonCached.uuid)
                .addValue( "@uuid_creator", nonCached.uuid_creator )
                .addValue("@participants_limit", nonCached.participants_limit)
                .Execute( );

            rooms.Add( nonCached );
            return nonCached.uuid;
        }
Exemple #10
0
    void buildScene(roomData room)
    {
        Random.InitState(room.GetHashCode() + 1);

        currentWidth  = Random.Range(minWidth, maxWidth + 1);
        currentHeight = Random.Range(minHeight, maxHeight + 1);

        clearMap();
        randomWalkTiles(0.2f, 0.02f, 5);

        setPlayer();
        removeSoloBlocks();
        buildDoors();
        populate();

        setTiles();
    }
Exemple #11
0
    void checkForClonesGames(int games, int layers)
    {
        int clonecount = 0;
        Dictionary <int, roomData> hash = new Dictionary <int, roomData>();

        for (int g = 0; g < games; g++)
        {
            print("game " + g);
            roomData currentRoom = new roomData(0, 0);
            for (int r = 0; r <= layers; r++)
            {
                Random.InitState((int)System.DateTime.Now.Ticks);
                int rand = Random.Range(0, 3);
                if (rand == 0)
                {
                    currentRoom = currentRoom.goLeft(currentRoom);
                }
                if (rand == 1)
                {
                    currentRoom = currentRoom.goMiddle(currentRoom);
                }
                if (rand == 2)
                {
                    currentRoom = currentRoom.goRight(currentRoom);
                }
                int chash = currentRoom.GetHashCode();

                if (hash.ContainsKey(chash) && hash[chash].layerNumber != currentRoom.layerNumber)
                {
                    print("1# " + hash[chash].layerNumber + ", " + hash[chash].roomNumber + ": " + hash[chash].GetHashCode());
                    print("2# " + currentRoom.layerNumber + ", " + currentRoom.roomNumber + ": " + currentRoom.GetHashCode());
                    clonecount++;
                }
                else
                {
                    if (!hash.ContainsKey(chash))
                    {
                        hash.Add(chash, currentRoom);
                    }
                }
            }
        }
        print("clone count: " + clonecount);
    }
Exemple #12
0
        public static async Task<roomData> fetchRoomData( string uuid )
        {
            var roomIndex = rooms.FindIndex(room => room.uuid == uuid);
            if ( roomIndex != -1 )
                return rooms[ roomIndex ];

            roomData nonCached = new roomData();

            await databaseManager.selectQuery( "SELECT uuid, uuid_creator, participants_limit FROM rooms WHERE uuid = @uuid LIMIT 1", delegate ( DbDataReader reader ) {
                if ( reader.HasRows )
                {
                    nonCached.participants_limit = ( int ) reader[ "participants_limit" ];
                    nonCached.uuid = ( string ) reader[ "uuid" ];
                    nonCached.uuid_creator = ( string ) reader[ "uuid_creator" ];

                }
            } ).addValue( "@uuid", uuid ).Execute( );

            rooms.Add( nonCached );
            return nonCached;
        }
    //room generator
    private void MakeDungeonRoom(Vector3 spawnPosition)
    {
        int  i             = UnityEngine.Random.Range(0, RoomMasterArray.Length);
        int  x             = roomDictionary.Count;
        bool isLeftViable  = false;
        bool isRightViable = false;
        var  room          = Instantiate(RoomMasterArray[i], spawnPosition, Quaternion.identity);

        if (room.transform.Find("ExitPointRight"))
        {
            isRightViable = true;
        }

        if (room.transform.Find("ExitPointLeft"))
        {
            isLeftViable = true;
        }

        roomData newRoom = new roomData(room, isLeftViable, isRightViable);

        roomDictionary.Add(x, newRoom);
        roomList.Add(room);
    }
        private void buttonSaveAll_Click(object sender, EventArgs e)
        {
            if (!checkRestriction())
            {
                return;
            }
            room.dataRoom     = new List <roomData>();
            room.nutzdataRoom = new List <roomData>();

            int count = 0;

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                count++;
                if (count != dataGridView1.Rows.Count)
                {
                    /*
                     * dataGridView1.Columns.Add("Punktindex", "Punktindex");
                     * dataGridView1.Columns.Add("RaumID", "RaumID");
                     * dataGridView1.Columns.Add("Day", "Day");
                     * dataGridView1.Columns.Add("Stunde", "Stunde");
                     * dataGridView1.Columns.Add("Minute", "Minute");
                     * dataGridView1.Columns.Add("Temp", "Temp");
                     */

                    room.addData(room.ID, (roomData.Day)Enum.Parse(typeof(roomData.Day), Convert.ToString(row.Cells[2].Value)), row.Cells[3].Value != null ? Convert.ToByte(row.Cells[3].Value) : (byte)0, row.Cells[4].Value != null ? Convert.ToByte(row.Cells[4].Value) : (byte)0, row.Cells[5].Value != null ? short.Parse(Convert.ToString(row.Cells[5].Value)) : (short)15);

                    room.nutzaddData(room.ID, (roomData.Day)Enum.Parse(typeof(roomData.Day), Convert.ToString(row.Cells[2].Value)), row.Cells[3].Value != null ? Convert.ToByte(row.Cells[3].Value) : (byte)0, row.Cells[4].Value != null ? Convert.ToByte(row.Cells[4].Value) : (byte)0, row.Cells[5].Value != null ? short.Parse(Convert.ToString(row.Cells[5].Value)) : (short)15);
                    //room.addData(room.ID, row.Cells[2].Value != null ? (int.TryParse(Convert.ToString(row.Cells[2].Value), out int notneeded) == true ? (roomData.Day)Convert.ToInt32(row.Cells[2].Value) : (roomData.Day)Enum.Parse(typeof(roomData.Day), Convert.ToString(row.Cells[2].Value))) : (roomData.Day)1, row.Cells[3].Value != null ? Convert.ToByte(row.Cells[3].Value) : (byte)0, row.Cells[4].Value != null ? Convert.ToByte(row.Cells[4].Value) : (byte)0, row.Cells[5].Value != null ? short.Parse(Convert.ToString(row.Cells[5].Value)) : (short)15);
                    //room.nutzaddData(room.ID, row.Cells[2].Value != null ? (int.TryParse(Convert.ToString(row.Cells[2].Value), out int notneeded2) == true ? (roomData.Day)Convert.ToInt32(row.Cells[2].Value) : (roomData.Day)Enum.Parse(typeof(roomData.Day), Convert.ToString(row.Cells[2].Value))) : (roomData.Day)1, row.Cells[3].Value != null ? Convert.ToByte(row.Cells[3].Value) : (byte)0, row.Cells[4].Value != null ? Convert.ToByte(row.Cells[4].Value) : (byte)0, row.Cells[5].Value != null ? short.Parse(Convert.ToString(row.Cells[5].Value)) : (short)15);
                }
            }
            sort();
            int             indexx  = 0;
            List <roomData> newtemp = new List <roomData>();

            foreach (roomData rd in room.dataRoom)
            {
                newtemp.Add(rd);
                if (indexx + 1 == room.dataRoom.Count)
                {
                    if (rd.Stunde == 23 && rd.Minute == 50)
                    {
                        //nichts
                    }
                    else
                    {
                        newtemp.Add(new roomData(rd.RaumID, rd.Wochentag, (byte)23, (byte)50, rd.Temperatur));
                    }
                }
                else
                {
                    roomData rd2 = room.dataRoom[indexx + 1];
                    if (rd.Wochentag == rd2.Wochentag)
                    {
                        newtemp.Add(new roomData(rd.RaumID, rd.Wochentag, rd2.Stunde, rd2.Minute, rd.Temperatur));
                    }
                    else
                    {
                        if (rd.Stunde == 23 && rd.Minute == 50)
                        {
                            //nichts
                        }
                        else
                        {
                            newtemp.Add(new roomData(rd.RaumID, rd.Wochentag, (byte)23, (byte)50, rd.Temperatur));
                        }
                    }
                }
                indexx++;
            }
            room.dataRoom     = newtemp;
            room.nutzdataRoom = newtemp;
            refresh();
        }
    List <roomData> roomPathfinding(roomData currRoom, Vector2 target)
    {
        Debug.Log("Starting room pathfinding from " + currRoom.location);
        Queue <Vertex> toBeSearched = new Queue <Vertex>();
        List <Vector2> beenThere    = new List <Vector2>();

        Vector2[] dirs =
        {
            new Vector2(1,   0),
            new Vector2(-1,  0),
            new Vector2(0,   1),
            new Vector2(0,  -1),
        };
        Vertex current = new Vertex();

        current.loc      = currRoom.location;
        current.moveCost = manhattanDistance(current.loc, target);
        toBeSearched.Enqueue(current);
        while (toBeSearched.Count > 0)
        {
            current = toBeSearched.Dequeue();
            if (current.loc == target) // You've found it!
            {
                Debug.Log("Found path from room!");
                List <roomData> path = new List <roomData>();
                while (current != null)
                {
                    Debug.Log("Adding room at " + current.loc);
                    roomData newRoomData = new roomData();
                    newRoomData.location = current.loc;
                    newRoomData.pathDir  = current.pathDir;
                    if (newRoomData.location == currRoom.location)
                    {
                        newRoomData.isSpawnRoom = true;
                    }
                    path.Add(newRoomData);
                    current = current.parent;
                }
                return(path);
            }
            List <Vertex> potentialSearches = new List <Vertex>();
            for (int i = 0; i < dirs.Length; i++)
            {
                Vector2 newLoc = current.loc + new Vector2(dirs[i].x * roomWidth, dirs[i].y * roomHeight);
                int     dist   = manhattanDistance(newLoc, target);
                if (isInMap(newLoc) && !beenThere.Contains(newLoc) && dist <= current.moveCost)
                {
                    Vertex newVertex = new Vertex();
                    newVertex.loc      = newLoc;
                    newVertex.parent   = current;
                    newVertex.moveCost = dist;
                    newVertex.pathDir  = dirs[i];
                    potentialSearches.Add(newVertex);
                }
            }
            if (potentialSearches.Count > 0)
            {
                toBeSearched.Enqueue(potentialSearches[Random.Range(0, potentialSearches.Count)]);
            }
            beenThere.Add(current.loc);
        }
        return(null);
    }