summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-11-15 13:41:05 +0100
committerAlexis211 <alexis211@gmail.com>2009-11-15 13:41:05 +0100
commitc268aeb9779b6e0562a2f0ab7668cffd62a27943 (patch)
tree242f1e82446b49ef94a9980938198439f70f0f65 /Source
parente48f1166ae7402f973ea4aab8e53c7612459048c (diff)
downloadMelon-c268aeb9779b6e0562a2f0ab7668cffd62a27943.tar.gz
Melon-c268aeb9779b6e0562a2f0ab7668cffd62a27943.zip
Game Of Life simulator fixed
Diffstat (limited to 'Source')
-rw-r--r--Source/Applications/Demos/GOL.cpp31
-rw-r--r--Source/Library/Common/Rand.ns.cpp2
2 files changed, 18 insertions, 15 deletions
diff --git a/Source/Applications/Demos/GOL.cpp b/Source/Applications/Demos/GOL.cpp
index 5848c2c..32eb30a 100644
--- a/Source/Applications/Demos/GOL.cpp
+++ b/Source/Applications/Demos/GOL.cpp
@@ -40,20 +40,24 @@ int main(Vector<String> args) {
outvt << String(tmp, w*h) << "Press Ctrl+h for help";
//Compute next generation
- for (u32int y = 0; y < h; y++) {
- for (u32int x = 0; x < w; x++) {
+ for (int y = 0; y < h; y++) {
+ for (int x = 0; x < w; x++) {
u8int n = 0;
- for (u32int yy = y - 1; yy <= y + 1; yy++) {
- for (u32int xx = x - 1; xx <= x + 2; xx++) {
- if (xx < w and yy < h and cells[xx * h + yy]) n++;
+ for (int yy = y - 1; yy < y + 2; yy++) {
+ for (int xx = x - 1; xx < x + 2; xx++) {
+ if (xx < w and yy < h and xx >= 0 and yy >= 0
+ and cells[xx * h + yy]) n++;
}
}
- if (cells[x * h + y]) n--;
- if ((cells[x * h + y] and n == 2) or n == 3) {
- newcells[x * h + y] = true;
+ newcells[x * h + y] = cells[x * h + y];
+ if (cells[x * h + y]) {
+ n--;
+ if (n < 2) newcells[x * h + y] = false;
+ if (n > 3) newcells[x * h + y] = false;
} else {
- newcells[x * h + y] = false;
+ if (n == 3) newcells[x* h + y] = true;
}
+
}
}
for (u32int x = 0; x < w; x++) {
@@ -73,11 +77,10 @@ int main(Vector<String> args) {
cells[x * h + y] = true;
}
} else if (kp.character == WChar("R")) {
- for (u32int i = 0; i < h; i++) {
- cells[i] = true;
- cells[(2 * i) % (h - i)] = true;
- cells[(w * i) % (h * w - i)] = true;
- cells[(w * i) % (h * w - i) + w] = true;
+ for (u32int i = 0; i < 150; i++) {
+ u64int x = Rand::rand() * w / Rand::max();
+ u64int y = Rand::rand() * h / Rand::max();
+ cells[x * h + y] = true;
}
} else if (kp.character == WChar("h")) {
outvt << "\n\n** Melon's demo Game Of Life Simulator help :\n";
diff --git a/Source/Library/Common/Rand.ns.cpp b/Source/Library/Common/Rand.ns.cpp
index 6323ccc..65b450c 100644
--- a/Source/Library/Common/Rand.ns.cpp
+++ b/Source/Library/Common/Rand.ns.cpp
@@ -2,7 +2,7 @@
namespace Rand {
-u32int m = 2073741824, a = 50000, b = 1534;
+u32int m = 2073741978, a = 50023, b = 1534097;
u64int current = RANDOM_SEED;
u64int rand() {