9 package micropolisj.engine;
11 import java.io.Serializable;
12 import java.util.Arrays;
13 import java.util.Comparator;
14 import java.util.EnumMap;
16 import java.util.Random;
21 public class CityEval implements Serializable {
27 this.
PRNG = engine.PRNG;
75 void cityEvaluation() {
101 void calculateAssValue() {
137 problemTable.put(CityProblem.UNEMPLOYMENT, getUnemployment());
142 CityProblem[] probOrder = CityProblem.values();
143 Arrays.sort(probOrder,
new Comparator<CityProblem>() {
144 public int compare(CityProblem a, CityProblem b) {
150 while (c < probOrder.length &&
problemVotes.get(probOrder[c]).intValue() != 0 && c < 4)
154 for (
int i = 0; i < c; i++) {
159 EnumMap<CityProblem, Integer> voteProblems(Map<CityProblem, Integer> probTab) {
160 CityProblem[] pp = CityProblem.values();
161 int[] votes =
new int[pp.length];
164 for (
int i = 0; i < 600; i++) {
165 if (
PRNG.nextInt(301) < probTab.get(pp[i % pp.length])) {
166 votes[i % pp.length]++;
168 if (countVotes >= 100)
173 EnumMap<CityProblem, Integer> rv =
new EnumMap<CityProblem, Integer>(CityProblem.class);
174 for (
int i = 0; i < pp.length; i++) {
175 rv.put(pp[i], votes[i]);
199 int getUnemployment() {
205 b = (int) Math.floor((r - 1.0) * 255);
214 return Math.min(255, z);
217 static double clamp(
double x,
double min,
double max) {
218 return Math.max(min, Math.min(max, x));
221 void calculateScore() {
230 x = Math.min(256, x);
232 double z = clamp((256 - x) * 4, 0, 1000);
280 z = clamp(z, 0, 1000);
288 for (
int i = 0; i < 100; i++) {