From c268aeb9779b6e0562a2f0ab7668cffd62a27943 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 15 Nov 2009 13:41:05 +0100 Subject: Game Of Life simulator fixed --- Source/Applications/Demos/GOL.cpp | 31 +++++++++++++++++-------------- Source/Library/Common/Rand.ns.cpp | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) (limited to 'Source') 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 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 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() { -- cgit v1.2.3 From d3e4ef59cbb45f02e07fe17fb7c58cba3c737900 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 29 Nov 2009 12:23:42 +0100 Subject: Minor edit --- Source/Kernel/VTManager/ScrollableVT.class.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Source') diff --git a/Source/Kernel/VTManager/ScrollableVT.class.cpp b/Source/Kernel/VTManager/ScrollableVT.class.cpp index 264c3a4..5a7de62 100644 --- a/Source/Kernel/VTManager/ScrollableVT.class.cpp +++ b/Source/Kernel/VTManager/ScrollableVT.class.cpp @@ -80,6 +80,8 @@ void ScrollableVT::keyPress(keypress_t kp) { nlup = m_linesup + 1; } else if (kp.command == KBDC_DOWN) { nlup = m_linesup - 1; + } else if (kp.command == KBDC_END) { + nlup = 0; } else { VirtualTerminal::keyPress(kp); } -- cgit v1.2.3