[Avida-SVN] r2984 - development/source/main
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Fri Nov 28 22:44:00 PST 2008
Author: brysonda
Date: 2008-11-29 01:43:59 -0500 (Sat, 29 Nov 2008)
New Revision: 2984
Modified:
development/source/main/cEnvironment.cc
Log:
Process state grid row ordering so that the it is more intuitive. Allows the grid to be entered with line continuations such that the grid:
a a
b a
can be entered as a,a,b,a -- or:
..:grid=\
a,a,\
b,a
Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc 2008-11-28 17:49:22 UTC (rev 2983)
+++ development/source/main/cEnvironment.cc 2008-11-29 06:43:59 UTC (rev 2984)
@@ -813,15 +813,15 @@
}
// Load the state grid itself
- tArray<int> grid(width * height);
+ tArray<int> lgrid(width * height);
cString gridstr = args->GetString(1);
int cell = 0;
- while (gridstr.GetSize() && cell < grid.GetSize()) {
+ while (gridstr.GetSize() && cell < lgrid.GetSize()) {
statename = gridstr.Pop(',');
statename.Trim();
for (int i = 0; i < states.GetSize(); i++) {
if (statename == states[i]) {
- grid[cell++] = i;
+ lgrid[cell++] = i;
break;
}
}
@@ -829,11 +829,24 @@
<< (cell % width) << ") in state grid " << name << endl;
return false;
}
- if (cell != (grid.GetSize() - 1) || gridstr.GetSize() > 0) {
+ if (cell != (lgrid.GetSize() - 1) || gridstr.GetSize() > 0) {
cerr << "error: grid definition size mismatch for state grid " << name << endl;
return false;
}
+ // Invert row ordering so that it is interpreted as the highest indexed row comes first. i.e. -
+ // | a a |
+ // | b a |
+ // would be a,a,b,a
+ tArray<int> grid(lgrid.GetSize());
+ for (int y = 0; y < height; y++) {
+ int off = y * width;
+ int toff = (height - y - 1) * width;
+ for (int x = 0; x < width; x++) {
+ grid[off + x] = tgrid[toff + x];
+ }
+ }
+
m_state_grids.Push(new cStateGrid(name, width, height, initx, inity, initfacing, states, state_sense, grid));
return true;
More information about the Avida-cvs
mailing list