Example #1
0
        public bool isRoomInDirectionFree(Position pos, int direction)
        {
            Position dir_pos = pos.GetBiasedPosition(direction);

            if ((0 <= dir_pos.X) && (dir_pos.X < width) && (0 <= dir_pos.Y) && (dir_pos.Y < height))
            {
                return(!rooms[dir_pos.X][dir_pos.Y].isOccupied());
            }
            return(false);
        }
Example #2
0
        bool _set_traits(Position pos, int direction, int door_type)
        {
            Position biased_pos = pos.GetBiasedPosition(direction);

            if ((biased_pos.X >= 0) && (biased_pos.Y >= 0))
            {
                if ((biased_pos.X < width) && (biased_pos.Y < height))
                {
                    if (!maze_generator.isFree(biased_pos))
                    {
                        return(false);
                    }
                    maze_generator.markReservedPosition(biased_pos);
                }
            }
            RoomTrait room = getRoom(pos);

            if (room.isLinked(direction))
            {
                throw new Exception();
            }

            if (room.getDoorType(direction) != 0)
            {
                throw new Exception();
            }

            int link_type;

            if (door_type == 3100)
            {
                link_type = 2;
            }
            else if (door_type == 3000)
            {
                link_type = 1;
            }
            else
            {
                throw new Exception();
            }
            room.Link(direction, link_type);
            room.setDoorType(direction, door_type);
            return(true);
        }
Example #3
0
        bool _create_sub_path_recursive(Position pos)
        {
            RoomTrait          room      = getRoom(pos);
            maze_room_internal maze_room = maze_generator.getRoom(pos);

            room.roomType = 1;
            for (int direction = 0; direction < 4; direction++)
            {
                if (maze_room.GetPassageType(direction) == 2)
                {
                    Position biased_pos = pos.GetBiasedPosition(direction);
                    if (room != null)
                    {
                        room.Link(direction, 2);
                    }
                    return(_create_sub_path_recursive(biased_pos));
                }
            }
            return(true);
        }
Example #4
0
        int _sub(Position pos)
        {
            if (getRoom(pos) != null)
            {
                int cnt = 1;

                for (int i_dir = 0; i_dir < 4; i_dir++)
                {
                    maze_room_internal room = getRoom(pos.GetBiasedPosition(i_dir));
                    if (room != null)
                    {
                        if (!room.isOccupied())
                        {
                            cnt += 1;
                        }
                    }
                }
                return(cnt);
            }

            return(0);
        }
Example #5
0
        bool _generateCriticalPathRecursive(int CritPathPos, int CritPathMin, int CritPathMax, int direction, MTRandom MT)
        {
            int[] directions = new int[4];
            _CritPathMaxResult += 1;

            if (_CritPathMaxResult <= 10 * CritPathMax)
            {
                if (CritPathMin <= CritPathPos && CritPathPos <= CritPathMax && this.isRoomInDirectionFree(this.current_pos, this.start_direction))
                {
                    start_pos = current_pos;
                    foreach (maze_move move in CriticalPath)
                    {
                        int temp = move.pos_from.X;
                        move.pos_from.X = move.pos_to.X;
                        move.pos_to.X   = temp;

                        temp            = move.pos_from.Y;
                        move.pos_from.Y = move.pos_to.Y;
                        move.pos_to.Y   = temp;

                        move.direction = Direction.GetOppositeDirection(move.direction);
                    }

                    CriticalPath.Reverse();
                    //print_maze();
                    return(true);
                }
                else
                {
                    CritPathPos += 1;
                    int count = 0;

                    if (CritPathPos <= CritPathMax)
                    {
                        if (direction != -1)
                        {
                            direction = Direction.GetOppositeDirection(direction);
                        }

                        for (int i = 0; i < 4; i++)
                        {
                            if (i == direction)
                            {
                                directions[i] = 0;
                            }
                            else
                            {
                                Position next_pos = current_pos.GetBiasedPosition(i);
                                directions[i] = _sub(next_pos);
                                count        += directions[i];
                            }
                        }
                        while (count > 0)
                        {
                            var rnd  = MT.GetUInt32() % count + 1;
                            int cnt2 = 0;

                            int i_dir = 0;
                            while (i_dir < 4)
                            {
                                cnt2 += directions[i_dir];
                                if (cnt2 >= rnd)
                                {
                                    break;
                                }
                                i_dir++;
                            }
                            count            -= directions[i_dir];
                            directions[i_dir] = 0;
                            //moves_count = len(self.CriticalPath)
                            if (_make_move(i_dir))
                            {
                                if (_generateCriticalPathRecursive(CritPathPos, CritPathMin, CritPathMax, i_dir, MT))
                                {
                                    return(true);
                                }
                                _undo_move();
                            }
                        }
                    }
                }
            }

            return(false);
        }
Example #6
0
        int _sub(Position pos)
        {
            if (getRoom(pos) != null)
            {
                int cnt = 1;

                for (int i_dir = 0; i_dir < 4; i_dir++)
                {
                    maze_room_internal room = getRoom(pos.GetBiasedPosition(i_dir));
                    if (room != null)
                        if (!room.isOccupied())
                            cnt += 1;
                }
                return cnt;
            }

            return 0;
        }
Example #7
0
 public bool isRoomInDirectionFree(Position pos, int direction)
 {
     Position dir_pos = pos.GetBiasedPosition(direction);
     if ((0 <= dir_pos.X) && (dir_pos.X < width) && (0 <= dir_pos.Y) && (dir_pos.Y < height))
         return !rooms[dir_pos.X][dir_pos.Y].isOccupied();
     return false;
 }
        bool _set_traits(Position pos, int direction, int door_type)
        {
            Position biased_pos = pos.GetBiasedPosition(direction);
            if ((biased_pos.X >= 0) && (biased_pos.Y >= 0))
            {
                if ((biased_pos.X < width) && (biased_pos.Y < height))
                {
                    if (!maze_generator.isFree(biased_pos))
                        return false;
                    maze_generator.markReservedPosition(biased_pos);
                }
            }
            RoomTrait room = getRoom(pos);
            if (room.isLinked(direction))
                throw new Exception();

            if (room.getDoorType(direction) != 0)
                throw new Exception();

            int link_type;
            if (door_type == 3100)
                link_type = 2;
            else if (door_type == 3000)
                link_type = 1;
            else
                throw new Exception();
            room.Link(direction, link_type);
            room.setDoorType(direction, door_type);
            return true;
        }
 bool _create_sub_path_recursive(Position pos)
 {
     RoomTrait room = getRoom(pos);
     maze_room_internal maze_room = maze_generator.getRoom(pos);
     room.roomType = 1;
     for (int direction = 0; direction < 4; direction++)
     {
         if (maze_room.GetPassageType(direction) == 2)
         {
             Position biased_pos = pos.GetBiasedPosition(direction);
             if (room != null)
                 room.Link(direction, 2);
             return _create_sub_path_recursive(biased_pos);
         }
     }
     return true;
 }