<commit_before>/**
 * <NAME>
 * Random Car Strategy
 * Picks a random path for the car to follow towards its destination
 * Makes no optimizations
 */
package traffic.strategy;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import traffic.graph.Graph;
import traffic.graph.GraphNode;

public class RandomCarStrategy implements CarStrategy {

	public RandomCarStrategy(){}
	
	/**
	 * Picks random neighbors to move towards until the destination is reached
	 * Returns the path represented as a list of integers
	 */
	public List<Integer> getPath(Graph g, int c, int d) {
		int next = c;
		List<Integer> path = new ArrayList<Integer>();
		while(next != d) {
			List<GraphNode> dest = g.getNeighbors(next);
			Random generator = new Random();
			int rand = generator.nextInt(dest.size());
			next = dest.get(rand).getID();
			path.add(next);
		}
		return path;
	}

}<commit_msg>Fixed RandomCarStrategy to terminate even when no path can be found.<commit_after>/**
 * <NAME>
 * Random Car Strategy
 * Picks a random path for the car to follow towards its destination
 * Makes no optimizations
 */
package traffic.strategy;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import traffic.graph.Graph;
import traffic.graph.GraphNode;

public class RandomCarStrategy implements CarStrategy {

	public RandomCarStrategy(){}
	
	/**
	 * Picks random neighbors to move towards until the destination is reached
	 * Returns the path represented as a list of integers
	 */
	public List<Integer> getPath(Graph g, int c, int d) {
		int next = c;
		List<Integer> path = new ArrayList<Integer>();
		while(next != d && path.size() < g.getNumNodes() ) {
			List<GraphNode> dest = g.getNeighbors(next);
			Random generator = new Random();
			int rand = generator.nextInt(dest.size());
			next = dest.get(rand).getID();
			path.add(next);
		}
		return path.get( path.size() - 1 ) == d ? path : null ;	//The random strategy must terminate even it if can't find a path
	}

}
{'fraction_non_alphanumeric': 0.11144278606965174, 'fraction_numerical': 0.0004975124378109452, 'mean_word_length': 3.941031941031941, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, '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': '3390152', 'n_tokens_mistral': 640, 'n_tokens_neox': 584, 'n_words': 211}