<commit_before>using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExecuteInEditMode]
public class DungeonCreator : MonoBehaviour
{
	public GameObject[] dungeonParts;
	public int dungeonSize = 10;
	
    private List<MountPoint> opens = new List<MountPoint>();

    public void Generate()
	{
        opens = new List<MountPoint>();
        createFirstDungeonPart();
        int missingParts = dungeonSize;
        int i = 1;
        while (missingParts > 0 )
		{
            MountPoint currentMountPoint = getRandomOpen();

			GameObject dungeonPart = Instantiate(dungeonParts[getRandomIndex()]) as GameObject;
			dungeonPart.name = String.Format("part-{0}", i);
			dungeonPart.transform.parent = transform;
            missingParts--;
            int index = getRandomIndex(dungeonPart.GetComponent<DungeonPart>().mountPoints);
            addToOpensExept(dungeonPart.GetComponent<DungeonPart>().mountPoints, index);
            Transform mpTransform = dungeonPart.GetComponent<DungeonPart>().mountPoints[index];
            MountPoint mp = mpTransform.GetComponent<MountPoint>();
            TranslateAndRotation tr = getTranslateAndRotation(currentMountPoint.direction, mp.direction);
            
            dungeonPart.transform.Rotate(tr.rotation);
            updateMountPointDirections(dungeonPart.GetComponent<DungeonPart>(), tr.rotation);
            mpTransform = dungeonPart.GetComponent<DungeonPart>().mountPoints[index];
            mp = mpTransform.GetComponent<MountPoint>();
            dungeonPart.transform.position = currentMountPoint.transform.position + new Vector3(tr.translationScale.x * Math.Abs(mp.translation.x), tr.translationScale.y * mp.translation.y, tr.translationScale.z * Math.Abs(mp.translation.z));
            i++;
		}
        
        while (opens.Count > 0)
        {
            MountPoint currentMountPoint = getRandomOpen();

            // Completo con habitaciones, por eso el indice 2.
            GameObject dungeonPart = Instantiate(dungeonParts[2]) as GameObject;
            dungeonPart.name = String.Format("part-{0}", i);
            dungeonPart.transform.parent = transform;

            int index = getRandomIndex(dungeonPart.GetComponent<DungeonPart>().mountPoints);
            addToOpensExept(dungeonPart.GetComponent<DungeonPart>().mountPoints, index);
            Transform mpTransform = dungeonPart.GetComponent<DungeonPart>().mountPoints[index];
            MountPoint mp = mpTransform.GetComponent<MountPoint>();
            TranslateAndRotation tr = getTranslateAndRotation(currentMountPoint.direction, mp.direction);
            
            dungeonPart.transform.Rotate(tr.rotation);
            updateMountPointDirections(dungeonPart.GetComponent<DungeonPart>(), tr.rotation);
            mpTransform = dungeonPart.GetComponent<DungeonPart>().mountPoints[index];
            mp = mpTransform.GetComponent<MountPoint>();
            dungeonPart.transform.position = currentMountPoint.transform.position + new Vector3(tr.translationScale.x * Math.Abs(mp.translation.x), tr.translationScale.y * mp.translation.y, tr.translationScale.z * Math.Abs(mp.translation.z));
            i++;
        }
	}
	
	public void RemoveAll()
	{
		DungeonPart[] rc = gameObject.GetComponentsInChildren<DungeonPart>();
		
		for (int i=0; i<rc.Length; i++)
		{
			DestroyImmediate(rc[i].gameObject);
		}
	}
	
    private MountPoint getRandomOpen()
    {
        int index = UnityEngine.Random.Range(0, opens.Count - 1);
        MountPoint mp = opens[index];
        opens.Remove(mp);
        return mp;
    }

    private void createFirstDungeonPart()
    {
        GameObject firstGO = Instantiate(dungeonParts[getRandomIndex()]) as GameObject;
        firstGO.name = "part-0";
        firstGO.transform.parent = transform;
        firstGO.transform.position = new Vector3(0, 0, 0);

        foreach (Transform t in firstGO.GetComponent<DungeonPart>().mountPoints)
        {
            opens.Add(t.GetComponent<MountPoint>());
        }
    }

	private int getRandomIndex()
	{
		return UnityEngine.Random.Range(0, dungeonParts.Length);
	}

    private int getRandomIndex(Transform[] mps)
    {
        return UnityEngine.Random.Range(0, mps.Length);
    }

    private void addToOpensExept(Transform[] mps, int index)
    {
        for (int i = 0; i < mps.Length; i++)<commit_msg>Minimun dungeon size guaranteed<commit_after>using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[ExecuteInEditMode]
public class DungeonCreator : MonoBehaviour
{
	public GameObject[] dungeonParts;
	public int minimumDungeonSize = 10;
	
    private List<MountPoint> opens = new List<MountPoint>();
    private int roomIndex = 2;

    public void Generate()
	{
        opens = new List<MountPoint>();
        createFirstDungeonPart();
        int missingParts = minimumDungeonSize;
        int i = 1;
        while (missingParts > 0 )
		{
            MountPoint currentMountPoint = getRandomOpen();

            int dungeonPartIndex = getRandomIndex();
            
            if (opens.Count == 1 && missingParts > 0)
            {
                dungeonPartIndex = getRandomIndexWithFilter(new int[roomIndex]);
            }
            GameObject dungeonPart = Instantiate(dungeonParts[dungeonPartIndex]) as GameObject;
			dungeonPart.name = String.Format("part-{0}", i);
			dungeonPart.transform.parent = transform;
            int index = getRandomIndex(dungeonPart.GetComponent<DungeonPart>().mountPoints);
            Transform mpTransform = dungeonPart.GetComponent<DungeonPart>().mountPoints[index];
            MountPoint mp = mpTransform.GetComponent<MountPoint>();
            TranslateAndRotation tr = getTranslateAndRotation(currentMountPoint.direction, mp.direction);
            
            dungeonPart.transform.Rotate(tr.rotation);
            updateMountPointDirections(dungeonPart.GetComponent<DungeonPart>(), tr.rotation);
            mpTransform = dungeonPart.GetComponent<DungeonPart>().mountPoints[index];
            mp = mpTransform.GetComponent<MountPoint>();
            dungeonPart.transform.position = currentMountPoint.transform.position + new Vector3(tr.translationScale.x * Math.Abs(mp.translation.x), tr.translationScale.y * mp.translation.y, tr.translationScale.z * Math.Abs(mp.translation.z));

            addToOpensExept(dungeonPart.GetComponent<DungeonPart>().mountPoints, index);
            missingParts--;
            i++;
		}
        
        while (opens.Count > 0)
        {
            MountPoint currentMountPoint = getRandomOpen();

            // Completo con habitaciones.
            GameObject dungeonPart = Instantiate(dungeonParts[roomIndex]) as GameObject;
            dungeonPart.name = String.Format("part-{0}", i);
            dungeonPart.transform.parent = transform;

            int index = getRandomIndex(dungeonPart.GetComponent<DungeonPart>().mountPoints);
            addToOpensExept(dungeonPart.GetComponent<DungeonPart>().mountPoints, index);
            Transform mpTransform = dungeonPart.GetComponent<DungeonPart>().mountPoints[index];
            MountPoint mp = mpTransform.GetComponent<MountPoint>();
            TranslateAndRotation tr = getTranslateAndRotation(currentMountPoint.direction, mp.direction);
            
            dungeonPart.transform.Rotate(tr.rotation);
            updateMountPointDirections(dungeonPart.GetComponent<DungeonPart>(), tr.rotation);
            mpTransform = dungeonPart.GetComponent<DungeonPart>().mountPoints[index];
            mp = mpTransform.GetComponent<MountPoint>();
            dungeonPart.transform.position = currentMountPoint.transform.position + new Vector3(tr.translationScale.x * Math.Abs(mp.translation.x), tr.translationScale.y * mp.translation.y, tr.translationScale.z * Math.Abs(mp.translation.z));
            i++;
        }
	}
	
	public void RemoveAll()
	{
		DungeonPart[] rc = gameObject.GetComponentsInChildren<DungeonPart>();
		
		for (int i=0; i<rc.Length; i++)
		{
			DestroyImmediate(rc[i].gameObject);
		}
	}
	
    private MountPoint getRandomOpen()
    {
        int index = UnityEngine.Random.Range(0, opens.Count - 1);
        MountPoint mp = opens[index];
        opens.Remove(mp);
        return mp;
    }

    private void createFirstDungeonPart()
    {
        GameObject firstGO = Instantiate(dungeonParts[getRandomIndex()]) as GameObject;
        firstGO.name = "part-0";
        firstGO.transform.parent = transform;
        firstGO.transform.position = new Vector3(0, 0, 0);

        foreach (Transform t in firstGO.GetComponent<DungeonPart>().mountPoints)
        {
            opens.Add(t.GetComponent<MountPoint>());
        }
    }

    private int getRandomIndex()
    {
        return UnityEngine.Random.Range(0, dungeonParts.Length);
    }

    private int getRandomIndexWithFilter(int[] indexesToFilter)
	{
        if (dungeonParts.Length == indexesToFilter.Length)
            return 0;

        int index = UnityEngine.Random.Range(0, dungeonParts.Length);
        while (contains(indexesToFilter, index))
        {
            index = UnityEngine.Random.Range(0, dungeonParts.Length);
        }
        return index;
	}

    private bool contains(int [] list, int value)
    {
        foreach (int elem in list)
        {
            if (elem == value)
                return true;
        }
        return false;
    }

    private int getRandomIndex(Transform[] mps)
    {
        return UnityEngine.Random.Range(0, mps.Length);
    }

    private void addToOpensExept(Transform[] mps, int index)
    {
        for (int i = 0; i < mps.Length; i++)
{'fraction_non_alphanumeric': 0.10740278644208776, 'fraction_numerical': 0.004990642545227698, 'mean_word_length': 2.8661575562700965, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '103428', 'n_tokens_mistral': 2787, 'n_tokens_neox': 2688, 'n_words': 487}