<commit_before>/*
 * Copyright 2013 Centro de Investigación en Tecnoloxías da Información (CITIUS).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package es.usc.citius.hipster.util.examples.maze;

import java.awt.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import java.util.List;

/**
 * <p>
 * This class defines a 2D ASCII Maze used to easily validate the search algorithms.
 * Example usage:</p>
 *
 * <pre>
 *     {@code public static String[] example = new String[]{
 *                  "XXSXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
 *                  "XX XXXXXXXXXXXXX     XXXXXXXXXXX",
 *                  "XX    XXXXXXXXXX XXX XX     XXXX",
 *                  "XXXXX  XXXXXX    XXX XX XXX XXXX",
 *                  "XXX XX XXXXXX XX XXX XX  XX XXXX",
 *                  "XXX     XXXXX XXXXXX XXXXXX XXXX",
 *                  "XXXXXXX       XXXXXX        XXXX",
 *                  "XXXXXXXXXX XXXXX XXXXXXXXXXXXXXX",
 *                  "XXXXXXXXXX XX    XXXXX      XXXX",
 *                  "XXXXXXXXXX    XXXXXXXX XXXX XXXX",
 *                  "XXXXXXXXXXX XXXXXXXXXX XXXX XXXX",
 *                  "XXXXXXXXXXX            XXXX XXXX",
 *                  "XXXXXXXXXXXXXXXXXXXXXXXX XX XXXX",
 *                  "XXXXXX              XXXX XX XXXX",
 *                  "XXXXXX XXXXXXXXXXXX XX      XXXX",
 *                  "XXXXXX XXG   XXXXXX XXXX XXXXXXX",
 *                  "XXXXXX XXXXX   XXX            XX",
 *                  "XXXXXX XXXXXXX XXXXXXXXXXX XXXXX",
 *                  "XXXXXX XXXXXXX XXXXXXXXXXXXXXXXX",
 *                  "XXXXXX            XXXXXXXXXXXXXX"};
 *
 *            Maze2D maze = new Maze2D(example);
 *     }
 * </pre>
 *
 * Symbol connected used by Maze2D:
 * <ul>
 *     <li>"X": occupied tile</li>
 *     <li>" ": empty tile</li>
 *     <li>"S": initial state (starting point)</li>
 *     <li>"G": goal state</li>
 *     <li>".": visited tile</li>
 * </ul>
 *
 * @author <NAME> <<a href="mailto:<EMAIL>"><EMAIL></a>>
 */
public class Maze2D {

    private char maze[][];
    private Point initialLoc;
    private Point goalLoc;
    private int rows;
    private int columns;
    private static Set<Character> FREE_TILES = new HashSet<Character>(Arrays.asList(' ', 'S', 'G', '.'));

    /**
     * Symbols allowed to create a maze
     */
    public static enum Symbol {
        OCCUPIED('X'),
        EMPTY(' '),
        START('S'),
        GOAL('G'),
        VISITED('.');
        public final char character;

        Symbol(char symbol) {
            this.character = symbol;
        }

        public char value() {
            return character;
        }

        public static Symbol parse(char c) {
            for (Symbol s : Symbol.values()) {
                if (s.character == c) {
                    return s;
                }
            }
            // If the symbol is not recognized, it is considered as an occupied tile
            return OCCUPIED;
        }
    }

    /**
     * Creates a new 2D ASCII Maze.
     *
     * @param maze    2D Byte array of that represents the maze using {@link Symbol}
     */
    public Maze2D(char maze[][]) {
        this.maze = maze;
        this.rows = maze.length;
        this.columns = findMaxRowLength(maze);
        this.initialLoc = charToPoint(Symbol.START.value());
        this.goalLoc = charToPoint(Symbol.GOAL.value());
    }

    private Point charToPoint(char c){
        for(int row = 0; row < this.rows; row++){
            for(int column = 0; row < this.columns; column++){
                if (maze[row][column] == c) return new Point(column, row);
            }
        }
        return null;
    }
<commit_msg>#179 - Bug in method charToPoint()<commit_after>/*
 * Copyright 2013 Centro de Investigación en Tecnoloxías da Información (CITIUS).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package es.usc.citius.hipster.util.examples.maze;

import java.awt.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
import java.util.List;

/**
 * <p>
 * This class defines a 2D ASCII Maze used to easily validate the search algorithms.
 * Example usage:</p>
 *
 * <pre>
 *     {@code public static String[] example = new String[]{
 *                  "XXSXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
 *                  "XX XXXXXXXXXXXXX     XXXXXXXXXXX",
 *                  "XX    XXXXXXXXXX XXX XX     XXXX",
 *                  "XXXXX  XXXXXX    XXX XX XXX XXXX",
 *                  "XXX XX XXXXXX XX XXX XX  XX XXXX",
 *                  "XXX     XXXXX XXXXXX XXXXXX XXXX",
 *                  "XXXXXXX       XXXXXX        XXXX",
 *                  "XXXXXXXXXX XXXXX XXXXXXXXXXXXXXX",
 *                  "XXXXXXXXXX XX    XXXXX      XXXX",
 *                  "XXXXXXXXXX    XXXXXXXX XXXX XXXX",
 *                  "XXXXXXXXXXX XXXXXXXXXX XXXX XXXX",
 *                  "XXXXXXXXXXX            XXXX XXXX",
 *                  "XXXXXXXXXXXXXXXXXXXXXXXX XX XXXX",
 *                  "XXXXXX              XXXX XX XXXX",
 *                  "XXXXXX XXXXXXXXXXXX XX      XXXX",
 *                  "XXXXXX XXG   XXXXXX XXXX XXXXXXX",
 *                  "XXXXXX XXXXX   XXX            XX",
 *                  "XXXXXX XXXXXXX XXXXXXXXXXX XXXXX",
 *                  "XXXXXX XXXXXXX XXXXXXXXXXXXXXXXX",
 *                  "XXXXXX            XXXXXXXXXXXXXX"};
 *
 *            Maze2D maze = new Maze2D(example);
 *     }
 * </pre>
 *
 * Symbol connected used by Maze2D:
 * <ul>
 *     <li>"X": occupied tile</li>
 *     <li>" ": empty tile</li>
 *     <li>"S": initial state (starting point)</li>
 *     <li>"G": goal state</li>
 *     <li>".": visited tile</li>
 * </ul>
 *
 * @author <NAME> <<a href="mailto:<EMAIL>"><EMAIL></a>>
 */
public class Maze2D {

    private char maze[][];
    private Point initialLoc;
    private Point goalLoc;
    private int rows;
    private int columns;
    private static Set<Character> FREE_TILES = new HashSet<Character>(Arrays.asList(' ', 'S', 'G', '.'));

    /**
     * Symbols allowed to create a maze
     */
    public static enum Symbol {
        OCCUPIED('X'),
        EMPTY(' '),
        START('S'),
        GOAL('G'),
        VISITED('.');
        public final char character;

        Symbol(char symbol) {
            this.character = symbol;
        }

        public char value() {
            return character;
        }

        public static Symbol parse(char c) {
            for (Symbol s : Symbol.values()) {
                if (s.character == c) {
                    return s;
                }
            }
            // If the symbol is not recognized, it is considered as an occupied tile
            return OCCUPIED;
        }
    }

    /**
     * Creates a new 2D ASCII Maze.
     *
     * @param maze    2D Byte array of that represents the maze using {@link Symbol}
     */
    public Maze2D(char maze[][]) {
        this.maze = maze;
        this.rows = maze.length;
        this.columns = findMaxRowLength(maze);
        this.initialLoc = charToPoint(Symbol.START.value());
        this.goalLoc = charToPoint(Symbol.GOAL.value());
    }

    private Point charToPoint(char c){
        for(int row = 0; row < this.rows; row++){
            for(int column = 0; column < this.columns; column++){
                if (maze[row][column] == c) return new Point(column, row);
            }
        }
        return null;
    }

{'fraction_non_alphanumeric': 0.11105882352941177, 'fraction_numerical': 0.004588235294117647, 'mean_word_length': 1.7881272548376517, 'pattern_counts': {'":': 10, '<': 55, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 42, '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': '5939270', 'n_tokens_mistral': 2548, 'n_tokens_neox': 2405, 'n_words': 766}