<commit_before>package eco;

import java.util.Random;

/**
 * An object that stores additional information about a city, such as the
 * configuration of buildings and name.
 * 
 * @author phil, nate
 * 
 */

public class City {

	private int[][] map = new int[4][4];

	private String name;

	private int pop = 0;

	public City() {
		Random random = new Random();
		name = NameGen.generateRandom();
	}

	public City(String name) {
		this.name = name;
	}

	public void updatePop(int newpop) {
		Random random = new Random();
		if (newpop - pop > 0) {
			int buildings = (int) Math.round(newpop / 6f);
			int oldbuildings = (int) Math.round(pop / 6f);
			int deltabuildings = buildings - oldbuildings;
			// System.out.println(pop+","+oldbuildings+","+buildings);
			while (deltabuildings > 0) {
				Point rand = new Point(random.nextInt(4), random.nextInt(4));
				while (map[rand.getX()][rand.getY()] == 2) {
					rand = new Point(random.nextInt(4), random.nextInt(4));
				}
				map[rand.getX()][rand.getY()] += 1;
				deltabuildings--;
			}
			pop = newpop;
		}
	}

	// Names generated using mithrilandmages.com
	// Thanks!
	private static final String[] names = new String[] { "Northhallterton",
			"Bath", "Worstead", "Gravesend", "Warton", "Norton", "Dereham",
			"Stratton", "Pebmarsh", "Amersham", "Montgomery", "Wedmore",
			"Chepstow", "Ilchester", "Newmarket", "Stretton", "Cricklade",
			"Saurm", "Waltham", "Barborough", "Deal", "Criccieth", "Manorbier",
			"Brackley", "Trent", "Chirbury", "Petersfield", "Silchester",
			"Plymoth", "Grinstead", "Liverpool", "Swansea", "Wenlock",
			"Furness", "Bridgewater", "Bloxham", "Byland", "Hindon", "Newport",
			"Hawarden", "Bebington", "Brassington", "Eccleshall", "Edmunds",
			"Tintagel", "Craydon", "Mardon", "Fowey", "Otterburn", "Brinkburn", };

	public int getBuilding(int x, int y) {
		return map[x][y];
	}

	public String getName() {
		return name;
	}

}<commit_msg>Update City.java<commit_after>package eco;

import java.util.Random;

/**
 * An object that stores additional information about a city, such as the
 * configuration of buildings and name.
 * 
 * @author phil, nate
 * 
 */

public class City {

	private int[][] map = new int[4][4];

	private String name;
	
	private boolean usename = true;

	private int pop = 0;
	
	private Point loc;
	
	private static String capitalEpithet = "# ";
	
	public boolean castle = false;
	
	public City(Point key){
		new City(key, false);
	}

	public City(Point key, boolean isCastle) {
		name = NameGen.generateSyllables();
		if (isCastle){
			Random random = new Random();
			if (random.nextInt(2) == 0){
				name = castlePrefix[random.nextInt(castlePrefix.length)] + " "+ name;
			}
			else{
				name = name + " "+ castleSuffix[random.nextInt(castleSuffix.length)];
			}
		}
		if (World.cities.size() == 0){
			name = capitalEpithet+name;
		}
		loc = key;
		if (World.cities.get(new Point(loc.getX() + 1, loc.getY())) != null){
			name = World.cities.get(new Point(loc.getX() + 1, loc.getY())).name;
			usename = false;
		}
		if (World.cities.get(new Point(loc.getX() - 1, loc.getY())) != null){
			name =  World.cities.get(new Point(loc.getX() - 1, loc.getY())).name;
			usename = false;
		}
		if (World.cities.get(new Point(loc.getX(), loc.getY() + 1)) != null){
			name = World.cities.get(new Point(loc.getX(), loc.getY() + 1)).name;
			usename = false;
		}
		if (World.cities.get(new Point(loc.getX(), loc.getY() - 1)) != null){
			name = World.cities.get(new Point(loc.getX(), loc.getY() - 1)).name;
			usename = false;
		}
		if (World.cities.get(new Point(loc.getX() + 1, loc.getY() + 1)) != null){
			name = World.cities.get(new Point(loc.getX() + 1, loc.getY() + 1)).name;
			usename = false;
		}
		if (World.cities.get(new Point(loc.getX() - 1, loc.getY() + 1)) != null){
			name =  World.cities.get(new Point(loc.getX() - 1, loc.getY() + 1)).name;
			usename = false;
		}
		if (World.cities.get(new Point(loc.getX() + 1, loc.getY() - 1)) != null){
			name = World.cities.get(new Point(loc.getX() + 1, loc.getY() - 1)).name;
			usename = false;
		}
		if (World.cities.get(new Point(loc.getX() - 1, loc.getY() - 1)) != null){
			name = World.cities.get(new Point(loc.getX() - 1, loc.getY() - 1)).name;
			usename = false;
		}
		this.castle = isCastle;
	}

	public City(String name) {
		this.name = name;
	}

	public void updatePop(int newpop) {
		//System.out.println("updating city");
		Random random = new Random();
		if (newpop - pop > 0) {
			int buildings = (int) Math.ceil(newpop / 6f);
			int oldbuildings = getSize();
			int deltabuildings = buildings - oldbuildings;
			// System.out.println(pop+","+oldbuildings+","+buildings);
			while (deltabuildings > 0) {
				Point rand = new Point(random.nextInt(4), random.nextInt(4));
				while (map[rand.getX()][rand.getY()] == 2) {
					rand = new Point(random.nextInt(4), random.nextInt(4));
				}
				map[rand.getX()][rand.getY()] += 1;
				deltabuildings--;
			}
			pop = newpop;
		}
		else {
			int buildings = (int) Math.floor(newpop / 6f);
			int oldbuildings = getSize();
			int deltabuildings = oldbuildings - buildings;

			while (deltabuildings > 0 && getSize() > 0) {
				Point rand = new Point(random.nextInt(4), random.nextInt(4));
				while (map[rand.getX()][rand.getY()] == 0) {
					rand = new Point(random.nextInt(4), random.nextInt(4));
				}
				map[rand.getX()][rand.getY()] -= 1;
				deltabuildings--;
			}
			pop = newpop;
		}
	}


	public int getBuilding(int x, int y) {
		return map[x][y];
	}

	public String getName() {
		if (usename){
			return name;
		}
		return "";
	}
	
	private static String[] castlePrefix = new String[] {
		"Fort","Castle","Camp",
	};
	
	private static String[] castleSuffix = new String[] {
		"Castle","Citadel","Garrision","Redoubt","Acropolis","Bulwark",
		"Bastion","Fortress","Vallation","Embankment","Stronghold"
	};
	
	public int getSize(){
		int size = 0;
		for (int x = 0; x < 4; x++){
			for (int y = 0; y < 4; y++){
				if (map[x][y] == 1){
					size++;
				}
				if (map[x][y] == 2){
					size += 2;
				}
			}
		}
		return size;
	}

}
{'fraction_non_alphanumeric': 0.18619212390838688, 'fraction_numerical': 0.011369253583786456, 'mean_word_length': 3.3890093998553867, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '6154922', 'n_tokens_mistral': 2619, 'n_tokens_neox': 2273, 'n_words': 528}