From 2f8ea8dfba7f2f36791179313c53a7f49ed19c26 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Mon, 21 Jan 2013 21:15:37 -0500 Subject: [PATCH] Better setup() for Conway4; fix funky markdown in readme; safety. --- README.md | 2 +- src/edu/stuy/goldfish/Goldfish.java | 2 ++ src/edu/stuy/goldfish/rules/Conway4.java | 14 ++++++-------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0db73cc..1c8a7fb 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ goldfish ======== -**goldfish** (*GoLdfish*) is a simple Game of Life implementation in Java. +**goldfish** (GoLdfish) is a simple Game of Life implementation in Java. Setup ----- diff --git a/src/edu/stuy/goldfish/Goldfish.java b/src/edu/stuy/goldfish/Goldfish.java index d627b8c..394ea65 100644 --- a/src/edu/stuy/goldfish/Goldfish.java +++ b/src/edu/stuy/goldfish/Goldfish.java @@ -20,7 +20,9 @@ public class Goldfish { setup(_render.rule); while (true) { if (_render.reset) { + _render.acquireLock(0); setup(_render.rule); + _render.releaseLock(0); _render.reset = false; } if (!_render.paused) { diff --git a/src/edu/stuy/goldfish/rules/Conway4.java b/src/edu/stuy/goldfish/rules/Conway4.java index 26e1d7a..6d3f8eb 100644 --- a/src/edu/stuy/goldfish/rules/Conway4.java +++ b/src/edu/stuy/goldfish/rules/Conway4.java @@ -1,5 +1,7 @@ package edu.stuy.goldfish.rules; +import java.util.Random; + import edu.stuy.goldfish.Grid; import edu.stuy.goldfish.Patch; @@ -27,14 +29,10 @@ public class Conway4 extends RuleSet { } public static void setup(Grid g) { - int[][] pattern = { - {1,1,1,1,0,1}, - {1,0,1,1,1,1} - }; - for (int i = 0; i < 6; i++) { - for (int j = 0; j < 2; j++) { - g.getPatch(i + ((g.getWidth() - 6) / 2), - j + ((g.getHeight() - 2) / 2)).setState(pattern[j][i]); + Random random = new Random(); + for (int i = 0; i < g.getWidth(); i++) { + for (int j = 0; j < g.getHeight(); j++) { + g.getPatch(i, j).setState(random.nextInt(2)); } } }