Object iS = map.get("initialState");
if (!(iS instanceof ICARulesGrid)) {
return;
}
ICARulesGrid grid = (ICARulesGrid) iS;
// dimension
int[] dimensions = grid.getSize();
// TODO sr137: change return type to boolean or result set or similar
if (dimensions.length != 2) {
return;
}
File f = Files.getFileFromURI(location);
try {
BufferedWriter writer =
new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f),
"UTF8"));
try {
for (int d = 0; d < dimensions.length; d++) {
if (d != 0) {
writer.write(" ");
}
writer.write(String.valueOf(dimensions[d]));
}
writer.write("\n");
// states
List<Integer> states = createStateMapping(grid);
for (int p = 0; p < states.size(); p++) {
if (p != 0) {
writer.write("\t");
}
writer.write((char) (states.get(p) + 'a') + ";" + states.get(p));
}
writer.write("\n");
// grid
// TODO sr137: store grid
for (int y = 0; y < dimensions[1]; y++) {
for (int x = 0; x < dimensions[0]; x++) {
writer.write(grid.getState(new int[] { x, y }) + 'a');
}
writer.write("\n");
}
} catch (IOException e) {
SimSystem.report(e);