#!/bin/sh## life.sh -- Jun 25 2010, by Patsie# awk implementation of the Game of Life. A simple automata# Usage: life.sh [<nr of runs> [<sleep interval>] ]## On a rectangular grid, let each cell be either living or dead.# Designate a living cell with a dot and a dead one with a blank space.# Begin with an arbitrarily drawn dot-and-blank grid, and let this be# the starting generation. Determine each successive generation by the# following rules:# 1) Each cell has 8 neighbors, the adjoining cells.# 2) A living cell with either 2 or 3 living neighbors remains alive.# 3) A dead cell with 3 living neighbors comes alive (a birth).# 4) All other cases result in a dead cell for the next generation.

and finally 3 basic, static seed files.(I tried putting the seed files between code tags, but they were still mangled up, so you'll have to do with the seed generator)Any feedback on the scripts is kindly appreciated.

So it failed at the line cols = int(size/lines); with a division by zero, which means the number of lines read from the pipe (genlife.sh) is zero. It looks like genlife.sh is producing zero output on your PC.I think it could be because the scripts use /bin/sh as a shell, your default sh isn't bash and I'm using bash'ism parameters for the default width, height and percentage parsing.If the output of genlife is empty, try to change the sha-bang to #!/bin/bash and try again.The same goes for life.sh ofcourse.I also don't know if cygwin's version of sleep can handle floating point arguments (sleep 0.5)

<rant>Cygwin is a really bad excuse for a *nix-like environment in my opinion. If you're running some form of Microsoft product and want to play with a *nix OS, I suggest running it through something like Virtualbox.</rant>

Hello.I tried to run this script , although it runs without any problem i thought that it would do another thingI thought that there would be rows running like the authentic game of lifeCan someone explain to me how does this works?

What should happen you can see in the animated image here.In your image I only see a static screen and no animation, so I can't really tell what's happening.I do see that you're using Ubuntu. The default /bin/sh in Ubuntu is 'dash' (and not bash). Since those to shells are not 100% compatible with each other, you could try to change the first line of both scripts to #!/bin/bash instead of the #!/bin/sh that is there now.

well, it's clear now. you have switched around your scripts. First time around I thought that your printscreen looked funny. you run ./test 30 30 but the field doesn't neerly look anything like a 30x30 screen. More like something 50'ish by 10. Then I noticed that you pipe it through ./test2 50Your 'test2' script is actually the seed generator and your 'test' script is the life.sh script.So please name them accordingly and switch the order of them around (it's ./genlife.sh 30 30 | ./life.sh 50 not the other way around )

Is it easy to make these 2 scripts as 1? becouse i want to try it.andcan u explain to me what do the numbers at the genlife script mean? its the number of the slots? for example if its 10 10 there will be 100 slots? and the start alive slots will be random?

Well, in my personal opinion it shouldn't be too hard to integrate both scripts into one. But that's of course if you have an intermediary knowledge level of awk.As for your second question, the (first) 2 numbers for 'genlife.sh' are the width and height of the generated grid. So yes, genlife.sh 10 10 will create a field of 10 by 10 cells for a total of 100 cells.This is also described in the first couple of comment lines of the script itself

Code:

# usage: genlife.sh [<width> [<height> [<fill percentage>] ] ]

You can optionally also pass a third parameter telling genlife how 'full' the grid must be. The number 0 will keep the grid empty, while 100 will fill every cell of the grid. Usually something between 15 and 75 percent fillrate will work best with 'life.sh' script.You can run genlife.sh as a standalone script so you can see what it does. There is no need to pipe the output to life.sh.

Who is online

Users browsing this forum: No registered users and 6 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum