Example #1
0
    // Decodes the genome populating the lists of arenas, corridors and tiles.
    private void ParseGenome()
    {
        arenas    = new List <ABRoom>();
        corridors = new List <ABRoom>();
        tiles     = new List <ABTile>();

        string currentValue = "";
        int    currentChar  = 0;

        // Parse the arenas.
        while (currentChar < seed.Length && seed[currentChar] == '<')
        {
            ABRoom arena = new ABRoom();
            currentChar++;

            // Get the x coordinate of the origin.
            while (Char.IsNumber(seed[currentChar]))
            {
                currentValue += seed[currentChar];
                currentChar++;
            }
            arena.originX = Int32.Parse(currentValue);

            currentValue = "";
            currentChar++;

            // Get the y coordinate of the origin.
            while (Char.IsNumber(seed[currentChar]))
            {
                currentValue += seed[currentChar];
                currentChar++;
            }
            arena.originY = Int32.Parse(currentValue);

            currentValue = "";
            currentChar++;

            // Get the size of the arena.
            while (Char.IsNumber(seed[currentChar]))
            {
                currentValue += seed[currentChar];
                currentChar++;
            }
            arena.dimension = Int32.Parse(currentValue);

            // Add the arena to the list.
            UpdateMapSize(arena.originX, arena.originY, arena.dimension, true);
            arenas.Add(arena);

            currentValue = "";
            currentChar++;
        }

        int rollbackCurrentChar = currentChar;

        // Parse the corridors.
        if (currentChar < seed.Length && seed[currentChar] == '|')
        {
            currentChar++;

            while (currentChar < seed.Length && seed[currentChar] == '<')
            {
                ABRoom corridor = new ABRoom();
                currentChar++;

                // Get the x coordinate of the origin.
                while (Char.IsNumber(seed[currentChar]))
                {
                    currentValue += seed[currentChar];
                    currentChar++;
                }
                corridor.originX = Int32.Parse(currentValue);

                currentValue = "";
                currentChar++;

                // Get the y coordinate of the origin.
                while (Char.IsNumber(seed[currentChar]))
                {
                    currentValue += seed[currentChar];
                    currentChar++;
                }
                corridor.originY = Int32.Parse(currentValue);

                currentValue = "";
                currentChar++;

                // Stop parsing the corridors if what I have is a tile.
                if (!(seed[currentChar] == '-' || Char.IsNumber(seed[currentChar])))
                {
                    currentChar = rollbackCurrentChar;
                    break;
                }

                // Get the size of the corridor.
                if (seed[currentChar] == '-')
                {
                    currentValue += seed[currentChar];
                    currentChar++;
                }
                while (Char.IsNumber(seed[currentChar]))
                {
                    currentValue += seed[currentChar];
                    currentChar++;
                }
                corridor.dimension = Int32.Parse(currentValue);

                // Add the arena to the list.
                UpdateMapSize(corridor.originX, corridor.originY, corridor.dimension, false);
                corridors.Add(corridor);

                currentValue = "";
                currentChar++;
            }
        }

        // Parse the tiles.
        if (currentChar < seed.Length && seed[currentChar] == '|')
        {
            currentChar++;

            while (currentChar < seed.Length && seed[currentChar] == '<')
            {
                ABTile tile = new ABTile();
                currentChar++;

                // Get the x coordinate of the origin.
                while (Char.IsNumber(seed[currentChar]))
                {
                    currentValue += seed[currentChar];
                    currentChar++;
                }
                tile.x = Int32.Parse(currentValue);

                currentValue = "";
                currentChar++;

                // Get the y coordinate of the origin.
                while (Char.IsNumber(seed[currentChar]))
                {
                    currentValue += seed[currentChar];
                    currentChar++;
                }
                tile.y = Int32.Parse(currentValue);

                currentValue = "";
                currentChar++;

                // Get the value of the tile.
                tile.value = seed[currentChar];

                // Add the arena to the list.
                tiles.Add(tile);

                currentValue = "";
                currentChar += 2;
            }
        }

        mainRoom = arenas[0];
    }
Example #2
0
    // Decodes the genome setting the probabilities.
    private void ParseGenome()
    {
        string currentValue = "";
        int    currentChar  = 1;

        // I've already skipped the first char, now get the forward probability.
        while (Char.IsNumber(seed[currentChar]) || seed[currentChar] == '.')
        {
            currentValue += seed[currentChar];
            currentChar++;
        }
        forwardProbability = Mathf.FloorToInt(float.Parse(currentValue) * 100);

        currentValue = "";
        currentChar++;

        // Get the left probability.
        while (Char.IsNumber(seed[currentChar]) || seed[currentChar] == '.')
        {
            currentValue += seed[currentChar];
            currentChar++;
        }
        leftProbability = Mathf.FloorToInt(float.Parse(currentValue) * 100);

        currentValue = "";
        currentChar++;

        // Get the rigth probability.
        while (Char.IsNumber(seed[currentChar]) || seed[currentChar] == '.')
        {
            currentValue += seed[currentChar];
            currentChar++;
        }
        rigthProbability = Mathf.FloorToInt(float.Parse(currentValue) * 100);

        currentValue = "";
        currentChar++;

        // Get the visited probability.
        while (Char.IsNumber(seed[currentChar]) || seed[currentChar] == '.')
        {
            currentValue += seed[currentChar];
            currentChar++;
        }
        visitedProbability = Mathf.FloorToInt(float.Parse(currentValue) * 100);

        currentValue = "";
        currentChar++;

        // Get the stair probability.
        while (Char.IsNumber(seed[currentChar]) || seed[currentChar] == '.')
        {
            currentValue += seed[currentChar];
            currentChar++;
        }
        stairProbability = Mathf.FloorToInt(float.Parse(currentValue) * 100);

        currentValue = "";
        currentChar++;

        // Parse the tiles.
        if (currentChar < seed.Length && seed[currentChar] == '|')
        {
            currentChar++;

            tiles = new List <ABTile>();

            while (currentChar < seed.Length && seed[currentChar] == '<')
            {
                ABTile tile = new ABTile();
                currentChar++;

                // Get the x coordinate of the origin.
                while (Char.IsNumber(seed[currentChar]))
                {
                    currentValue += seed[currentChar];
                    currentChar++;
                }
                tile.x = Int32.Parse(currentValue);

                currentValue = "";
                currentChar++;

                // Get the y coordinate of the origin.
                while (Char.IsNumber(seed[currentChar]))
                {
                    currentValue += seed[currentChar];
                    currentChar++;
                }
                tile.y = Int32.Parse(currentValue);

                currentValue = "";
                currentChar++;

                // Get the value of the tile.
                tile.value = seed[currentChar];

                // Add the arena to the list.
                tiles.Add(tile);

                currentValue = "";
                currentChar += 2;
            }
        }
    }