Пример #1
0
        private void GenerateDetailMap(Node[,] MapStruct, Boolean[,] detailedMapStruct)
        {
            this.initializeDetailedMap(detailedMapStruct);
            for (int row = 0; row < this.numNodesV; row++)
            {
                for (int col = 0; col < this.numNodesH; col++)
                {
                    Node tempNode = MapStruct[row, col];
                    int  rowIndex = row * tempNode.Height;
                    int  colIndex = col * tempNode.Width;

                    if (tempNode is RoomNode)
                    {
                        RoomNode room = (RoomNode)tempNode;
                        this.setRoomInDetailedMap(detailedMapStruct, room, rowIndex, colIndex);
                    }
                    else if (tempNode is WallNode)
                    {
                        WallNode wall = (WallNode)tempNode;
                        this.setWallInDetailedMap(detailedMapStruct, wall, rowIndex, colIndex);
                    }
                    if (tempNode is EmptyNode)
                    {
                        EmptyNode empty = (EmptyNode)tempNode;
                    }
                }
            }
        }
Пример #2
0
        public void GenerateRandomMap()
        {
            this.rooms        = new ArrayList();
            this.walls        = new ArrayList();
            this.empties      = new ArrayList();
            this.numOfEmpties = 0;
            this.numOfRooms   = 0;
            this.numOfWalls   = 0;
            //Random randomGenerator = new Random(randomSeed);
            for (int row = 0; row < this.numNodesV; row++)
            {
                for (int col = 0; col < this.numNodesH; col++)
                {
                    if ((row == 0 && col == 0) || (row == this.numNodesV - 1 && col == this.numNodesH - 1))
                    {
                        this.internalMapStruct[row, col]  = new EmptyNode();
                        this.optimizedMapStruct[row, col] = new EmptyNode();
                        this.numOfEmpties++;
                        continue;
                    }

                    int randomType = this.randomGenerator.Next(3);
                    if (randomType == 0)
                    {
                        RoomNode tempRoom            = new RoomNode(this.randomGenerator);
                        KeyValuePair <int, int> item = new KeyValuePair <int, int>(row, col);
                        this.rooms.Add(item);
                        this.numOfRooms++;
                        this.internalMapStruct[row, col]  = tempRoom;
                        this.optimizedMapStruct[row, col] = tempRoom;
                    }
                    else if (randomType == 1)
                    {
                        WallNode tempWall            = new WallNode(this.randomGenerator);
                        KeyValuePair <int, int> item = new KeyValuePair <int, int>(row, col);
                        this.walls.Add(item);
                        this.numOfWalls++;
                        this.internalMapStruct[row, col]  = tempWall;
                        this.optimizedMapStruct[row, col] = tempWall;
                    }
                    else
                    {
                        EmptyNode tempEmpty          = new EmptyNode();
                        KeyValuePair <int, int> item = new KeyValuePair <int, int>(row, col);
                        this.empties.Add(item);
                        this.numOfEmpties++;
                        this.internalMapStruct[row, col]  = tempEmpty;
                        this.optimizedMapStruct[row, col] = tempEmpty;
                    }
                }
            }
            this.GenerateDetailMap(this.internalMapStruct, this.detailedInternalMapStruct);
            this.GenerateDetailMap(this.optimizedMapStruct, this.detailedOptimizedInternalMapStruct);
        }
Пример #3
0
        public void printMaps()
        {
            for (int row = 0; row < this.numGridsV; row++)
            {
                for (int col = 0; col < this.numGridsH; col++)
                {
                    if (this.detailedInternalMapStruct[row, col])
                    {
                        Console.Write("  ");
                    }
                    else
                    {
                        Console.Write("* ");
                    }
                    //Console.Write("{0} ", this.detailedInternalMapStruct[row, col]);
                }
                Console.WriteLine("");
            }

            for (int row = 0; row < this.numNodesV; row++)
            {
                for (int col = 0; col < this.numNodesH; col++)
                {
                    Node tempNode = this.internalMapStruct[row, col];

                    if (tempNode is RoomNode)
                    {
                        RoomNode room = (RoomNode)tempNode;
                        Console.Write("R ");
                    }
                    else if (tempNode is WallNode)
                    {
                        WallNode wall = (WallNode)tempNode;
                        Console.Write("W ");
                    }
                    if (tempNode is EmptyNode)
                    {
                        EmptyNode empty = (EmptyNode)tempNode;
                        Console.Write("E ");
                    }
                }
                Console.WriteLine("");
            }
        }
Пример #4
0
        public void OptimizeMap()
        {
            /*
             * int minSize = numNodesH;
             * if (numNodesV < numNodesH)
             *  minSize = numNodesV;
             * ArrayList rowList1 = new ArrayList();
             * ArrayList colList1 = new ArrayList();
             * ArrayList rowList2 = new ArrayList();
             * ArrayList colList2 = new ArrayList();
             *
             * // find suitable spoitions for placing optimal spots
             * for (int row = 0; row < this.numNodesV; row++)
             * {
             *  for (int col = 0; col < this.numNodesH; col++)
             *  {
             *      if (distance(0, 0, row, col) >= 0.75 * minSize)
             *      {
             *          rowList1.Add(row);
             *          colList1.Add(col);
             *      }
             *      if (distance(this.numNodesV - 1, this.numNodesH - 1, row, col) >= 0.75 * minSize)
             *      {
             *          rowList2.Add(row);
             *          colList2.Add(col);
             *      }
             *  }
             * }
             * // randomly pick four spots and create "safe" spots
             * Random rand = new Random();
             * for (int i = 0; i < 4; i++)
             * {
             *  int pos = rand.Next(rowList1.Count);
             *  for (int j = pos - 1; j <= pos + 1; j++)
             *      for (int k = pos - 1; k <= pos + 1; k++)
             *          this.optimizedMapStruct[(int)rowList1[j], (int)colList1[k]] = new EmptyNode();
             * }
             * for (int i = 0; i < 4; i++)
             * {
             *  int pos = rand.Next(rowList2.Count);
             *  for (int j = pos - 1; j <= pos + 1; j++)
             *      for (int k = pos - 1; k <= pos + 1; k++)
             *          this.optimizedMapStruct[(int)rowList2[j], (int)colList2[k]] = new EmptyNode();
             * }
             */



            /*
             * float roomNum = 0, wallNum = 0, emptyNum = 0;
             * float totalNum = this.numNodesH * this.numNodesV;
             * for (int row = 0; row < this.numNodesV; row++)
             * {
             *  for (int col = 0; col < this.numNodesH; col++)
             *  {
             *      Node tempNode = this.optimizedMapStruct[row, col];
             *      if (tempNode is RoomNode)
             *      {
             *          //Console.WriteLine("Wrong");
             *          roomNum++;
             *      }
             *      else if (tempNode is WallNode)
             *      {
             *          wallNum++;
             *      }
             *      if (tempNode is EmptyNode)
             *      {
             *          emptyNum++;
             *      }
             *
             *  }
             * }
             * float roomRate = (roomNum / totalNum) * 100;
             * float wallRate = (wallNum / totalNum) * 100;
             * float emptyRate = (emptyNum / totalNum) * 100;
             */

            float totalNum  = this.numNodesH * this.numNodesV;//this.numOfWalls + this.numOfRooms + this.numOfEmpties;
            float roomRate  = (this.numOfRooms / totalNum) * 100;
            float wallRate  = (this.numOfWalls / totalNum) * 100;
            float emptyRate = (this.numOfEmpties / totalNum) * 100;

            Console.WriteLine("{0} {1} {2} ", roomRate, wallRate, emptyRate);
            while (true)
            {
                Console.WriteLine("{0} {1} {2} ", roomRate, wallRate, emptyRate);
                if (roomRate > InternalMap.RoomFixRate)
                {
                    int index = this.randomGenerator.Next(this.rooms.Count);
                    KeyValuePair <int, int> removed = (KeyValuePair <int, int>) this.rooms[index];
                    this.rooms.RemoveAt(index);
                    this.numOfRooms--;
                    if (emptyRate < InternalMap.EmptyFixRate)
                    {
                        this.empties.Add(removed);
                        this.numOfEmpties++;

                        EmptyNode temp = new EmptyNode();
                        this.optimizedMapStruct[removed.Key, removed.Value] = temp;
                    }
                    else if (wallRate < InternalMap.WallFixRate)
                    {
                        this.walls.Add(removed);
                        this.numOfWalls++;

                        WallNode temp = new WallNode(this.randomGenerator);
                        this.optimizedMapStruct[removed.Key, removed.Value] = temp;
                    }
                }
                else if (wallRate < InternalMap.WallFixRate)
                {
                    int index;
                    KeyValuePair <int, int> removed;
                    if (roomRate > InternalMap.RoomFixRate)
                    {
                        index   = this.randomGenerator.Next(this.rooms.Count);
                        removed = (KeyValuePair <int, int>) this.rooms[index];
                        this.rooms.RemoveAt(index);
                        this.numOfRooms--;

                        WallNode temp = new WallNode(this.randomGenerator);
                        this.optimizedMapStruct[removed.Key, removed.Value] = temp;
                        this.walls.Add(removed);
                        this.numOfWalls++;
                    }
                    else if (emptyRate > InternalMap.EmptyFixRate)
                    {
                        index   = this.randomGenerator.Next(this.empties.Count);
                        removed = (KeyValuePair <int, int>) this.empties[index];
                        this.empties.RemoveAt(index);
                        this.numOfEmpties--;

                        WallNode temp = new WallNode(this.randomGenerator);
                        this.optimizedMapStruct[removed.Key, removed.Value] = temp;
                        this.walls.Add(removed);
                        this.numOfWalls++;
                    }
                }
                else if (emptyRate < InternalMap.EmptyFixRate)
                {
                    int index;
                    KeyValuePair <int, int> removed;
                    if (roomRate > InternalMap.RoomFixRate)
                    {
                        index   = this.randomGenerator.Next(this.rooms.Count);
                        removed = (KeyValuePair <int, int>) this.rooms[index];
                        this.rooms.RemoveAt(index);
                        this.numOfRooms--;

                        EmptyNode temp = new EmptyNode();
                        this.optimizedMapStruct[removed.Key, removed.Value] = temp;
                        this.empties.Add(removed);
                        this.numOfEmpties++;
                    }
                    else if (wallRate > InternalMap.WallFixRate)
                    {
                        index   = this.randomGenerator.Next(this.walls.Count);
                        removed = (KeyValuePair <int, int>) this.walls[index];
                        this.walls.RemoveAt(index);
                        this.numOfWalls--;

                        EmptyNode temp = new EmptyNode();
                        this.optimizedMapStruct[removed.Key, removed.Value] = temp;
                        this.empties.Add(removed);
                        this.numOfEmpties++;
                    }
                }
                else
                {
                    break;
                }

                roomRate  = (this.numOfRooms / totalNum) * 100;
                wallRate  = (this.numOfWalls / totalNum) * 100;
                emptyRate = (this.numOfEmpties / totalNum) * 100;
            }


            //this.optimizedMapStruct[0, 0] = new RoomNode(this.randomGenerator);
            this.GenerateDetailMap(this.optimizedMapStruct, this.detailedOptimizedInternalMapStruct);
        }
Пример #5
0
        public void OptimizeMap()
        {
            /*
            int minSize = numNodesH;
            if (numNodesV < numNodesH)
                minSize = numNodesV;
            ArrayList rowList1 = new ArrayList();
            ArrayList colList1 = new ArrayList();
            ArrayList rowList2 = new ArrayList();
            ArrayList colList2 = new ArrayList();

            // find suitable spoitions for placing optimal spots
            for (int row = 0; row < this.numNodesV; row++)
            {
                for (int col = 0; col < this.numNodesH; col++)
                {
                    if (distance(0, 0, row, col) >= 0.75 * minSize)
                    {
                        rowList1.Add(row);
                        colList1.Add(col);
                    }
                    if (distance(this.numNodesV - 1, this.numNodesH - 1, row, col) >= 0.75 * minSize)
                    {
                        rowList2.Add(row);
                        colList2.Add(col);
                    }
                }
            }
            // randomly pick four spots and create "safe" spots
            Random rand = new Random();
            for (int i = 0; i < 4; i++)
            {
                int pos = rand.Next(rowList1.Count);
                for (int j = pos - 1; j <= pos + 1; j++)
                    for (int k = pos - 1; k <= pos + 1; k++)
                        this.optimizedMapStruct[(int)rowList1[j], (int)colList1[k]] = new EmptyNode();
            }
            for (int i = 0; i < 4; i++)
            {
                int pos = rand.Next(rowList2.Count);
                for (int j = pos - 1; j <= pos + 1; j++)
                    for (int k = pos - 1; k <= pos + 1; k++)
                        this.optimizedMapStruct[(int)rowList2[j], (int)colList2[k]] = new EmptyNode();
            }
            */

            /*
            float roomNum = 0, wallNum = 0, emptyNum = 0;
            float totalNum = this.numNodesH * this.numNodesV;
            for (int row = 0; row < this.numNodesV; row++)
            {
                for (int col = 0; col < this.numNodesH; col++)
                {
                    Node tempNode = this.optimizedMapStruct[row, col];
                    if (tempNode is RoomNode)
                    {
                        //Console.WriteLine("Wrong");
                        roomNum++;
                    }
                    else if (tempNode is WallNode)
                    {
                        wallNum++;
                    }
                    if (tempNode is EmptyNode)
                    {
                        emptyNum++;
                    }

                }
            }
            float roomRate = (roomNum / totalNum) * 100;
            float wallRate = (wallNum / totalNum) * 100;
            float emptyRate = (emptyNum / totalNum) * 100;
            */

            float totalNum = this.numNodesH * this.numNodesV;//this.numOfWalls + this.numOfRooms + this.numOfEmpties;
            float roomRate = (this.numOfRooms / totalNum) * 100;
            float wallRate = (this.numOfWalls / totalNum) * 100;
            float emptyRate = (this.numOfEmpties / totalNum) * 100;
            Console.WriteLine("{0} {1} {2} ", roomRate, wallRate, emptyRate);
            while (true)
            {
                Console.WriteLine("{0} {1} {2} ", roomRate, wallRate, emptyRate);
                if (roomRate > InternalMap.RoomFixRate)
                {
                    int index = this.randomGenerator.Next(this.rooms.Count);
                    KeyValuePair<int, int> removed = (KeyValuePair<int, int>)this.rooms[index];
                    this.rooms.RemoveAt(index);
                    this.numOfRooms--;
                    if (emptyRate < InternalMap.EmptyFixRate)
                    {
                        this.empties.Add(removed);
                        this.numOfEmpties++;

                        EmptyNode temp = new EmptyNode();
                        this.optimizedMapStruct[removed.Key, removed.Value] = temp;
                    }
                    else if (wallRate < InternalMap.WallFixRate)
                    {
                        this.walls.Add(removed);
                        this.numOfWalls++;

                        WallNode temp = new WallNode(this.randomGenerator);
                        this.optimizedMapStruct[removed.Key, removed.Value] = temp;
                    }
                }
                else if (wallRate < InternalMap.WallFixRate)
                {
                    int index;
                    KeyValuePair<int, int> removed;
                    if (roomRate > InternalMap.RoomFixRate)
                    {
                        index = this.randomGenerator.Next(this.rooms.Count);
                        removed = (KeyValuePair<int, int>)this.rooms[index];
                        this.rooms.RemoveAt(index);
                        this.numOfRooms--;

                        WallNode temp = new WallNode(this.randomGenerator);
                        this.optimizedMapStruct[removed.Key, removed.Value] = temp;
                        this.walls.Add(removed);
                        this.numOfWalls++;
                    }
                    else if (emptyRate > InternalMap.EmptyFixRate)
                    {
                        index = this.randomGenerator.Next(this.empties.Count);
                        removed = (KeyValuePair<int, int>)this.empties[index];
                        this.empties.RemoveAt(index);
                        this.numOfEmpties--;

                        WallNode temp = new WallNode(this.randomGenerator);
                        this.optimizedMapStruct[removed.Key, removed.Value] = temp;
                        this.walls.Add(removed);
                        this.numOfWalls++;
                    }

                }
                else if (emptyRate < InternalMap.EmptyFixRate)
                {
                    int index;
                    KeyValuePair<int, int> removed;
                    if (roomRate > InternalMap.RoomFixRate)
                    {
                        index = this.randomGenerator.Next(this.rooms.Count);
                        removed = (KeyValuePair<int, int>)this.rooms[index];
                        this.rooms.RemoveAt(index);
                        this.numOfRooms--;

                        EmptyNode temp = new EmptyNode();
                        this.optimizedMapStruct[removed.Key, removed.Value] = temp;
                        this.empties.Add(removed);
                        this.numOfEmpties++;
                    }
                    else if (wallRate > InternalMap.WallFixRate)
                    {
                        index = this.randomGenerator.Next(this.walls.Count);
                        removed = (KeyValuePair<int, int>)this.walls[index];
                        this.walls.RemoveAt(index);
                        this.numOfWalls--;

                        EmptyNode temp = new EmptyNode();
                        this.optimizedMapStruct[removed.Key, removed.Value] = temp;
                        this.empties.Add(removed);
                        this.numOfEmpties++;
                    }
                }
                else
                {
                    break;
                }

                roomRate = (this.numOfRooms / totalNum) * 100;
                wallRate = (this.numOfWalls / totalNum) * 100;
                emptyRate = (this.numOfEmpties / totalNum) * 100;
            }

            //this.optimizedMapStruct[0, 0] = new RoomNode(this.randomGenerator);
            this.GenerateDetailMap(this.optimizedMapStruct,this.detailedOptimizedInternalMapStruct);
        }
Пример #6
0
        public void GenerateRandomMap()
        {
            this.rooms = new ArrayList();
            this.walls = new ArrayList();
            this.empties = new ArrayList();
            this.numOfEmpties = 0;
            this.numOfRooms = 0;
            this.numOfWalls = 0;
            //Random randomGenerator = new Random(randomSeed);
            for (int row = 0; row < this.numNodesV; row++)
            {
                for (int col = 0; col < this.numNodesH; col++)
                {
                    if ( (row == 0 && col == 0) || (row == this.numNodesV - 1 && col == this.numNodesH - 1))
                    {
                        this.internalMapStruct[row, col] = new EmptyNode();
                        this.optimizedMapStruct[row, col] = new EmptyNode();
                        this.numOfEmpties++;
                        continue;
                    }

                    int randomType = this.randomGenerator.Next(3);
                    if (randomType == 0)
                    {
                        RoomNode tempRoom = new RoomNode(this.randomGenerator);
                        KeyValuePair<int, int> item = new KeyValuePair<int, int>(row, col);
                        this.rooms.Add(item);
                        this.numOfRooms++;
                        this.internalMapStruct[row, col] = tempRoom;
                        this.optimizedMapStruct[row, col] = tempRoom;

                    }
                    else if (randomType == 1)
                    {
                        WallNode tempWall = new WallNode(this.randomGenerator);
                        KeyValuePair<int, int> item = new KeyValuePair<int, int>(row, col);
                        this.walls.Add(item);
                        this.numOfWalls++;
                        this.internalMapStruct[row, col] = tempWall;
                        this.optimizedMapStruct[row, col] = tempWall;
                    }
                    else
                    {
                        EmptyNode tempEmpty = new EmptyNode();
                        KeyValuePair<int, int> item = new KeyValuePair<int, int>(row, col);
                        this.empties.Add(item);
                        this.numOfEmpties++;
                        this.internalMapStruct[row, col] = tempEmpty;
                        this.optimizedMapStruct[row, col] = tempEmpty;
                    }
                }
            }
            this.GenerateDetailMap(this.internalMapStruct, this.detailedInternalMapStruct);
            this.GenerateDetailMap(this.optimizedMapStruct, this.detailedOptimizedInternalMapStruct);
        }