Last active
March 9, 2016 11:51
-
-
Save ElectricCoffee/0056e9636ead6cb118db to your computer and use it in GitHub Desktop.
A simple idea for a city name generator I came up with based on Ben "Yahtzee" Croshaw's idea in The Consuming Shadow. The basic premise is that it takes common city prefixes and suffixes and mashes them together at random, causing generic sounding city names. The fun bit is when you start mixing cities from different countries together!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package eu.wausoft.city.gen | |
import scala.util.Random | |
import java.io._ | |
/** | |
* Created by coffee on 3/8/16. | |
*/ | |
object Generator { | |
val prefixes = Vector ( | |
"Alt", "Alten", "Olden", "Groß", "Großen", "Hoh", "Hohen", | |
"Höch", "Hoch", "Klein", "Lütten", "Neu", "Neuen", "Nien", | |
"Nieder","Ober", "Oberst", "Wendisch", "Windisch", "Unter", | |
"Aber", "Ast", "Auch", "Ach", "Auchter", "Bal", "Balla", | |
"Bally", "Ball", "Brad", "Bre", "Caer", "Car", "Cut", "Cwm", | |
"Cum", "Dal", "Din", "Dinas", "Dol", "Drum", "Dun", "Dum", "Don", | |
"Doune", "Fin", "Inver", "Inner", "Kill", "Kin", "Kyle", "Kyles", | |
"Lang", "Mynydd", "Nan", "Nans", "Nant", "Nor", "Pen", "Pit", | |
"Pol", "Pont", "Porth", "Shep", "Ship", "Stan", "Strath", "Sud", | |
"Sut", "Tre", "Tilly", "Tullie", "Tulloch", "Wes", "Win", "Lan", | |
"Lhan", "Llan", "Lin", "Llyn" | |
) | |
val suffixes = Vector ( | |
"ach", "au", "aue", "bach", "bek", "beck", "brücken", "brück", | |
"burg", "berg", "dorf", "torf", "ey", "feld", "felde", "furt", | |
"hagen", "halde", "halden", "heim", "haven", "hafen", "hof", | |
"hofen", "hufe", "hut", "hausen", "ing", "ingen", "ungen", | |
"ung", "ens", "kirchen", "kirch", "oog", "öhe", "oie", "ee", | |
"ow", "roth", "rath", "rode", "reuth", "rade", "stadt", "stedt", | |
"stätt", "stetten", "tal", "thal", "wald", "welde", "wang", | |
"wangen", "wängle", "wend", "winden", "werder", "werth", "wörth", | |
"ort", "shaw", "bost", "carden", "caster", "chester", "cester", | |
"ceter", "cot", "cott", "dale", "dean", "den", "don", "field", | |
"firth", "frith", "ham", "ing", "keth", "cheth", "mouth", "ness", | |
"pool", "port", "stead", "ster", "thwaite", "twatt", "wick", "wich", | |
"wych", "wyke", "ay", "y", "ey", "dubh", "dow", "dhu", "duff", | |
"craig", "crag", "creag", "toft", "worth", "worthy", "wardine", "by", | |
"bjerg", "køping", "havn", "owo", "owa", "grad" | |
) | |
// generates every possible combination of cities | |
// by taiking the cross-product of the two vectors | |
// this generates over 8000 city names! | |
lazy val combinations = for { | |
prefix <- prefixes | |
suffix <- suffixes | |
} yield prefix + suffix | |
// spits out a randomised vector of however many cities you want | |
def mkCities(amount: Int): Vector[String] = { | |
val cities = Random shuffle combinations | |
cities take amount | |
} | |
// prints all the cities to a file | |
def write(path: String): Either[String, String] = write(path, -1) | |
// prints a randomised list of however many cities you want to a file | |
def write(path: String, amount: Int): Either[String, String] = { | |
val cities = if(amount < 0) Random.shuffle(combinations).mkString(", ") | |
else combinations.take(amount).mkString(", ") | |
try { | |
val writer = new FileWriter(path, false) | |
val printer = new PrintWriter(writer) | |
println(cities) | |
printer print cities | |
printer.close() | |
Right("Successfully wrote to file") | |
} | |
catch { | |
case _: FileNotFoundException => Left(s"The file $path was not found") | |
case e: Exception => Left(s"Could not write to file because $e") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment