<commit_before>import java.util.*;

/*
 * Commands: L,4
Commands: L,4
Commands: L,6
Commands: R,10
Commands: L,6

== A

Commands: L,4
Commands: L,4
Commands: L,6
Commands: R,10
Commands: L,6

== A

Commands: L,12
Commands: L,6
Commands: R,10
Commands: L,6
Commands: R,8
Commands: R,10
Commands: L,6

== B

Commands: R,8
Commands: R,10
Commands: L,6

== C

Commands: L,4
Commands: L,4
Commands: L,6
Commands: R,10
Commands: L,6

== A

Commands: R,8
Commands: R,10
Commands: L,6

== C

Commands: L,12
Commands: L,6
Commands: R,10
Commands: L,6
Commands: R,8
Commands: R,10
Commands: L,6

== B

Commands: L,12
Commands: L,6
Commands: R,10
Commands: L,6

== B
 */

public class MovementLogic
{
    public static final int NUMBER_OF_FUNCTIONS = 3;

    public static final int ROUTINE_A = 0;
    public static final int ROUTINE_B = 1;
    public static final int ROUTINE_C = 2;

    public static final int MAX_CHARACTERS = 20;

    private static final int MOVED_OK = 0;
    private static final int MOVE_FINISHED = 1;
    private static final int DIRECTION_BLOCKED = 2;
    private static final int MOVE_ERROR = 3;
    private static final int LOCATION_VISITED = 4;

    public MovementLogic (Map theMap, boolean debug)
    {
        _theMap = theMap;
        _robotTrack = new Trail(_theMap);
        _path = new Stack<String>();
        _routeTaken = "";
        _robotFacing = CellId.ROBOT_FACING_UP;
        _currentMoveDirection = "";
        _currentPosition = new Coordinate(_theMap.findStartingPoint());
        _debug = debug;
    }

    public void createMovementFunctions ()
    {
        createPath();

        /*
         * Now convert the path into a series of commands
         * such as L,4 or R,8.
         */

        Vector<String> commands = getCommands();

        /*
         * Now turn the series of commands into functions
         * A, B and C based on repeated commands.
         * 
         * There are only 3 possible functions.
         * This means one function always starts at the beginning.
         * One function always ends at the ending (!) assuming it's not a repeat
         * of the first.
         * Then using both the first and the last fragment to find the third
         * and split the entire sequence into functions.
         * 
         * Also it's possible to give the Robot more commands than it can
         * execute before it gets to end of the route.
         */

        String fullCommand = "";

        for (int i = commands.size() -1; i >= 0; i--)
        {
            fullCommand += commands.elementAt(i);
        }

        System.out.println("Full command "+fullCommand);

        String[] functions = new String[NUMBER_OF_FUNCTIONS];

        /*
         * Find repeated strings. Assume minimum of 2 commands.
         */

        int start = 0;
        int numberOfCommands = 2;
        int functionIndex = 0;

        for (int i = 0; i < NUMBER_OF_FUNCTIONS; i++)
        {
            String repeat = getRepeatString(commands, 0, 2);
        }
    }

    public void createMovementRoutine ()
    {
        
    }

    private String getRepeatString (Vector<String> commands, int start, int number)
    {
        String str = "";

        for (int i = start; i < number; i++)
        {
            str += commands.elementAt(i);
        }

        return str;
    }

    private Vector<String> getCommands ()
    {
        Vector<String> commands = new Vector<String>(_path.size());
        String pathElement = null;

        /*
         * Pop the track to reverse it and get commands from the
         * starting position.
         */

        do
        {
            try
            {
                pathElement = _path.pop();
<commit_msg>Update MovementLogic.java<commit_after>import java.util.*;

/*
 * Commands: L,4
Commands: L,4
Commands: L,6
Commands: R,10
Commands: L,6

== A

Commands: L,4
Commands: L,4
Commands: L,6
Commands: R,10
Commands: L,6

== A

Commands: L,12
Commands: L,6
Commands: R,10
Commands: L,6
Commands: R,8
Commands: R,10
Commands: L,6

== B

Commands: R,8
Commands: R,10
Commands: L,6

== C

Commands: L,4
Commands: L,4
Commands: L,6
Commands: R,10
Commands: L,6

== A

Commands: R,8
Commands: R,10
Commands: L,6

== C

Commands: L,12
Commands: L,6
Commands: R,10
Commands: L,6
Commands: R,8
Commands: R,10
Commands: L,6

== B

Commands: L,12
Commands: L,6
Commands: R,10
Commands: L,6

== B
 */

public class MovementLogic
{
    public static final int NUMBER_OF_FUNCTIONS = 3;

    public static final int ROUTINE_A = 0;
    public static final int ROUTINE_B = 1;
    public static final int ROUTINE_C = 2;

    public static final int MAX_CHARACTERS = 20;

    private static final int MOVED_OK = 0;
    private static final int MOVE_FINISHED = 1;
    private static final int DIRECTION_BLOCKED = 2;
    private static final int MOVE_ERROR = 3;
    private static final int LOCATION_VISITED = 4;

    public MovementLogic (Map theMap, boolean debug)
    {
        _theMap = theMap;
        _robotTrack = new Trail(_theMap);
        _path = new Stack<String>();
        _routeTaken = "";
        _robotFacing = CellId.ROBOT_FACING_UP;
        _currentMoveDirection = "";
        _currentPosition = new Coordinate(_theMap.findStartingPoint());
        _debug = debug;
    }

    public void createMovementFunctions ()
    {
        createPath();

        /*
         * Now convert the path into a series of commands
         * such as L,4 or R,8.
         */

        Vector<String> commands = getCommands();

        /*
         * Now turn the series of commands into functions
         * A, B and C based on repeated commands.
         * 
         * There are only 3 possible functions.
         * This means one function always starts at the beginning.
         * One function always ends at the ending (!) assuming it's not a repeat
         * of the first.
         * Then using both the first and the last fragment to find the third
         * and split the entire sequence into functions.
         * 
         * Also it's possible to give the Robot more commands than it can
         * execute before it gets to end of the route.
         */

        String fullCommand = "";

        for (int i = commands.size() -1; i >= 0; i--)
        {
            fullCommand += commands.elementAt(i);
        }

        System.out.println("Full command "+fullCommand);

        String[] functions = new String[NUMBER_OF_FUNCTIONS];

        /*
         * Find repeated strings. Assume minimum of 2 commands.
         */

        System.out.println("got "+getFunction(commands, fullCommand, 0, 2));
    }

    public void createMovementRoutine ()
    {
        
    }

    private String getFunction (Vector<String> commands, String fullCommand, int start, int numberOfCommands)
    {
        String repeat = getCommandString(commands, start, numberOfCommands);

        if (fullCommand.contains(repeat))
        {
            System.out.println("Repeat: "+repeat);

            String next = getFunction(commands, fullCommand, start, numberOfCommands +1);

            if (next == null)
                return repeat;
            else
                return next;
        }
        else
            System.out.println("Does not repeat: "+repeat);

        return null;
    }

    private String getCommandString (Vector<String> commands, int start, int number)
    {
        String str = "";

        for (int i = start; i < number; i++)
        {
            str += commands.elementAt(i);
        }

        return str;
    }

    private Vector<String> getCommands ()
    {
        Vector<String> commands = new Vector<String>(_path.size());
        String pathElement = null;

        /*
         * Pop the track to reverse it and get commands from the
         * starting position.
         */

        do
        {
            try
            {
                pathElement = _path.pop();

{'fraction_non_alphanumeric': 0.09398782343987823, 'fraction_numerical': 0.018645357686453576, 'mean_word_length': 2.0861056751467713, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 18, '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': '3624116', 'n_tokens_mistral': 2429, 'n_tokens_neox': 2383, 'n_words': 791}