Interestingly enough, I had a lab session on implementing the Game of Life yesterday. Ours was done in Scala (which is based on Java) and was actually an exercise in concurrency.<br><br>Y'see, this is why I keep telling you not to use Bash. Bash is slow, it's incredibly slow. Similar code in almost any other language would run much faster. That said, it does work and it looks right to me. You seem to be blocking at the edges, like Steve's second suggestion. My implementation is as if on a torus, so anything that goes off one edge comes back on the opposite one, but either version works. Most proper implementations I see work on a small section of a potentially very large grid, expanding the section as needed, and presumably blocking at the edges. <br>
<br>Looking at your implementation, I expect pipe-lining so many copies of sed is slower than chaining expressions with the -e option, and that might be slower than writing a multi-line sed script. Bash isn't really equipped to do the transformations itself, unfortunately, so it's probably going to be slow anyway from the overhead of running a function on every cell that spawns processes in serial. The rules can be implemented in a single if-statement, but I doubt that would make a noticeable difference to the framerate. I'm fairly certain, however, that no matter how much careful optimisation you do, you're never going to get Bash to process Life at a reasonable speed. So yeah, it's a nice hack but pretty difficult to understand and very, very slow. <br>
<br>Now you've got the basic algorithm, though, it wouldn't take long to port it to something reasonably fast, then you can try out the more fun custom cellular automata. I made one that simulates forest fires by growing green cells for trees and then randomly switching one to red for fire which spreads and turns the trees to black ash.<br>
<br>Tom<br><br><div class="gmail_quote">2009/2/26 Chris Hayes <span dir="ltr"><<a href="mailto:cbhworld@gmail.com">cbhworld@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
And now we have life, written in Bash: <a href="http://newark.lug.org.uk/wiki/doku.php?id=bash_life" target="_blank">http://newark.lug.org.uk/wiki/doku.php?id=bash_life</a><br><br>It's pretty slow, I haven't even tried to put in anything to boost efficiency. I found on my laptop, running Gnome I got roughly a frame a second on the bigger of the two patterns. On the test pattern I got around 2, maybe 2.5 frames a second.<br>
<br>Please feel free offer critique although bear in mind it isn't meant to be pretty or good - it was really just a quick hack that gets the job done.<br><br><br>Kind Regards,<br><font color="#888888">Chris Hayes</font><div>
<div></div><div class="Wj3C7c"><br><br><div class="gmail_quote">
On Sat, Feb 21, 2009 at 10:16 PM, Steve Caddy <span dir="ltr"><<a href="mailto:steve.m.caddy@ntlworld.com" target="_blank">steve.m.caddy@ntlworld.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>Chris Hayes wrote:<br>
> ... the only thing that I can't quite get my head around regarding life is<br>
> what order to calculate the cells in. I mean; if you work left to right, top<br>
> to bottom you'll get a different outcome than if you - say, do the opposite.<br>
<br>
</div>I'm under the impression that each generation is calculated from the state of<br>
its parent, but the new state isn't written to the grid until the entire next<br>
generation has been calculated. It's unimportant which order you consider the<br>
cells in, because all the neighbours are static during the calculation of the<br>
next generation. What is interesting to consider, is what happens at the edge<br>
of the playing area... should it wrap around, or should you consider the edge<br>
to be composed of permanently dead cells?<br>
<br>
Steve<br>
<font color="#888888"><br>
--<br>
Steven M Caddy, MEng ------------------------------------------------------<br>
Email: <a href="mailto:steve.m.caddy@ntlworld.com" target="_blank">steve.m.caddy@ntlworld.com</a><br>
<br>
_______________________________________________<br>
Newark mailing list<br>
<a href="mailto:Newark@mailman.lug.org.uk" target="_blank">Newark@mailman.lug.org.uk</a><br>
<a href="https://mailman.lug.org.uk/mailman/listinfo/newark" target="_blank">https://mailman.lug.org.uk/mailman/listinfo/newark</a><br>
</font></blockquote></div><br>
</div></div><br>_______________________________________________<br>
Newark mailing list<br>
<a href="mailto:Newark@mailman.lug.org.uk">Newark@mailman.lug.org.uk</a><br>
<a href="https://mailman.lug.org.uk/mailman/listinfo/newark" target="_blank">https://mailman.lug.org.uk/mailman/listinfo/newark</a><br>
<br></blockquote></div><br>