Posts: 144
Threads: 17
Joined: Jan 2004
First read this:
http://encyclopedia.thefreedictionary.co...0of%20Life
Read it? Now make a Life simulator. =D You can use any set of rules listed on that page.
You can use FB or QB...... And...
The rest is up to you.
I've been messing with this stuff for the last few hours... I managed to make a semi-complicated maze-like pattern in 37 generations with some random rules... Let's see what you can do!
Posts: 2,765
Threads: 138
Joined: Nov 2002
Here:
http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
I think that's a better resource =P
I'll study it and try some stuff later
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 2,765
Threads: 138
Joined: Nov 2002
whoops! I forgot about this
I finished the prog awhile ago but it's painfully slow (it scans a huge array. I have and idea to make it faster.)
You can specify the rule and the starting pattern
it's shiney ^^
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 144
Threads: 17
Joined: Jan 2004
Posts: 2,765
Threads: 138
Joined: Nov 2002
Quote:Ahh... gunna post it?
auuuw do I have to.. It's bad....and sloooow...
Code: OPTION EXPLICIT
DECLARE FUNCTION getNumOfNeighbors(x AS INTEGER,y AS INTEGER)
DECLARE SUB drawWorld
DECLARE SUB checkRules
#define SCRWIDTH 320
#define SCRHEIGHT 200
#define ALIVE 1
#define DEAD 0
SCREENRES SCRWIDTH,SCRHEIGHT,32,2,1
DIM SHARED world(1 TO SCRWIDTH, 1 TO SCRHEIGHT) AS INTEGER
DIM SHARED AS INTEGER xlb, xub, yub, ylb, generation
DIM SHARED Birthrule AS STRING, StayRule AS STRING
DIM AS STRING press, rule
DIM AS INTEGER x,y,mouse_btns,mouse_x,mouse_y,tmp,f
DIM AS SINGLE t,delay
xub = UBOUND(world,1):xlb = LBOUND(world,1)
yub = UBOUND(world,2):ylb = LBOUND(world,2)
generation=1
delay=1
rule="23/3"
birthrule=right$(rule$,LEN(rule$)-INSTR(rule$,"/"))
stayrule=left$(rule$,INSTR(rule$,"/")-1)
SETMOUSE ,,0
SCREENSET 1, 0
DO
READ tmp
IF tmp=2 THEN y=y+1:x=0 ELSE IF tmp=3 THEN EXIT DO ELSE x=x+1:world(x+100,y+100)=tmp
LOOP
DATA 1,1,1,2,1,0,0,2,0,1,0,3
'############ 1=Cell is alive
'############ 2=end of line
'############ 3=stop reading
DO
t = TIMER
DO
press=inkey$
drawWorld
IF press="+" THEN delay=delay*2
IF press="-" THEN delay=delay/2
if press="q" then end
LOCATE 3,1: PRINT "Delay:";delay
FLIP
LOOP UNTIL TIMER-t>=delay
checkRules
LOOP
SUB checkRules
generation+=1
DIM AS INTEGER x, y, neighbors,i,okay
DIM tmpworld(xlb TO xub,ylb TO yub) AS INTEGER
FOR y = ylb+1 TO yub-1
FOR x = xlb+1 TO xub-1
neighbors=getNumOfNeighbors(x,y)
DO
FOR i = 1 TO LEN(birthrule)
IF neighbors=VAL(mid$(birthrule,i,1)) THEN tmpworld(x,y)=ALIVE:EXIT DO
NEXT i
FOR i = 1 TO LEN(stayrule)
IF neighbors=VAL(mid$(stayrule,i,1)) THEN tmpworld(x,y)=world(x,y):EXIT DO
NEXT i
tmpworld(x,y)=DEAD
EXIT DO
LOOP
NEXT x
NEXT y
FOR y = ylb TO yub
FOR x = xlb TO xub
world(x,y)=tmpworld(x,y)
NEXT x
NEXT y
END SUB
SUB drawWorld
DIM AS INTEGER x, y, i
FOR y = ylb TO yub
FOR x = xlb TO xub
IF world(x,y)=ALIVE THEN i=i+1: PSET(x,y),RGB(0,0,255):ELSE PSET(x,y),RGB(0,0,0)
NEXT x
NEXT y
LOCATE 1,1: PRINT "Generation:";generation
LOCATE 2,1: PRINT "Cells:";i
IF i=0 THEN PRINT "All life is dead!":SLEEP:END
END SUB
FUNCTION getNumOfNeighbors(x AS INTEGER, y AS INTEGER)
DIM neighbors AS INTEGER, i AS INTEGER
FOR i = 1 TO 8
SELECT CASE i
CASE 1
IF world(x-1,y-1)=ALIVE THEN neighbors=neighbors+1
CASE 2
IF world(x,y-1)=ALIVE THEN neighbors=neighbors+1
CASE 3
IF world(x+1,y-1)=ALIVE THEN neighbors=neighbors+1
CASE 4
IF world(x+1,y)=ALIVE THEN neighbors=neighbors+1
CASE 5
IF world(x+1,y+1)=ALIVE THEN neighbors=neighbors+1
CASE 6
IF world(x,y+1)=ALIVE THEN neighbors=neighbors+1
CASE 7
IF world(x-1,y+1)=ALIVE THEN neighbors=neighbors+1
CASE 8
IF world(x-1,y)=ALIVE THEN neighbors=neighbors+1
END SELECT
NEXT i
getNumOfNeighbors = neighbors
END FUNCTION
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 1,080
Threads: 87
Joined: Feb 2002
Hmmm I made a variant in c++ and allegro a while ago, maybe I'll port it...
/post]
Posts: 142
Threads: 6
Joined: Aug 2001
Well I see several spots that could be optimized. The most obvious one was the function that counted neighbors.
Code: FUNCTION getNumOfNeighbors(x AS INTEGER, y AS INTEGER)
DIM neighbors AS INTEGER
IF world(x-1,y-1)=ALIVE THEN neighbors=neighbors+1
IF world(x,y-1)=ALIVE THEN neighbors=neighbors+1
IF world(x+1,y-1)=ALIVE THEN neighbors=neighbors+1
IF world(x+1,y)=ALIVE THEN neighbors=neighbors+1
IF world(x+1,y+1)=ALIVE THEN neighbors=neighbors+1
IF world(x,y+1)=ALIVE THEN neighbors=neighbors+1
IF world(x-1,y+1)=ALIVE THEN neighbors=neighbors+1
IF world(x-1,y)=ALIVE THEN neighbors=neighbors+1
getNumOfNeighbors = neighbors
END FUNCTION
Why did you even have the loop?
Posts: 2,765
Threads: 138
Joined: Nov 2002
xD oh yeah becuase I was using it somewhere else and it did some other junk
but I cut it out and put it in the function (and obviously did a bad job at it)
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 1,080
Threads: 87
Joined: Feb 2002
Followed links to here and there and found John von Neumanns
self replicator/universal constructor
http://www.sq3.org.uk/Evolution/JvN/
http://encyclopedia.thefreedictionary.co...onstructor
:o
/post]
Posts: 1,080
Threads: 87
Joined: Feb 2002
Sorry to bump it, I don't know if it's dead or not, but here's
my verision of life...
[syntax="qbasic"]' The code here is obsolete, scroll down for latest release...[/syntax]
/post]
|