-
Notifications
You must be signed in to change notification settings - Fork 2
/
City.cs
104 lines (89 loc) · 2.45 KB
/
City.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// City.cs
/*
* Represents a major city, minor city, or town
*
*/
using System;
using System.Reflection;
using System.IO;
using System.Collections;
namespace Rails
{
public enum CityType // used by Milepost class
{
None = 0, // a milepost not on a city
Capital, // the milepost at the center of a major city
City, // minor city
Town, // town
CapitalCorner, // a corner of a major city
}
public class City
{
private int x; // the grid location of the city
private int y;
private string name; // the name of the city
private ArrayList products; // the commodities available at the city
public City(int x, int y, string name, ArrayList products)
{
this.x = x;
this.y = y;
this.name = name;
this.products = products;
}
public int X
{
get { return x; }
}
public int Y
{
get { return y; }
}
public string Name
{
get { return name; }
}
public ArrayList Products
{
get { return products; }
}
/* Linguistic data for eight countries in Europe. Countries selected were those with the
* greatest number of cities with populations of 100 000 or more. See CityNames.txt for
* source data derived from http://www.mongabay.com/igapo/European_cities.htm
*/
private static Trigram[] trigram = GetTrigrams();
// Initialization routine to load CityNames.txt
static Trigram[] GetTrigrams()
{
// get the stream of resource text
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("Rails.CityNames.txt");
StreamReader reader = new StreamReader(stream);
// initialize the trigram structures
Trigram[] temp = new Trigram[8];
for (int i=0; i<8; i++)
{
// skip the country name
/* string country = */ reader.ReadLine();
// read the city names until a blank line is found
temp[i] = new Trigram();
while (true)
{
string name = reader.ReadLine();
if (name == null)
break;
if (name.Length == 0)
break;
temp[i].Add(name.Trim());
}
}
reader.Close();
return temp;
}
// Choose a random city name for a given country. Use the random number generator
// from the Map class so that we generate the same names for a given map seed.
public static string RandomName(int capital, Random rand, Hashtable seen)
{
return trigram[capital].GetSample(rand, seen);
}
}
}