07-11-2005, 04:07 AM
i had a mac that had a game like yours red_Marvin. you would click out a bunch of black dots and watch them multiply! yes more fun then watching grass grow or paint dry.
Life! V1.0
|
07-11-2005, 04:07 AM
i had a mac that had a game like yours red_Marvin. you would click out a bunch of black dots and watch them multiply! yes more fun then watching grass grow or paint dry.
07-11-2005, 12:22 PM
wow red_Marvin - that was great... well.. i guess so far you win - this is an open-ended competition - if anybody else wants to code an entry - you're welcome to!
seriously that's some nice code - very cool
07-11-2005, 08:29 PM
thats odd...it doesn't seem to work right when I run it. it just makes them all die, regardless of whether they have 2/3 neighbors or not...
edit: here's my version, its longer, but supports an infinite (not limited by map size, rather by the maxcells constant) cell system and works for me. edit edit: new code in lower thread.
07-11-2005, 11:07 PM
@Deleter: I suppose it's my program you're talking about?
Have you tried leaving the line blank? Does the problem occur for every pattern? To check: Do the R-pentamino: --## ##-- --#-- It shouldn't stabilize any time soon... Could you perhaps change the code to make it output what the contents of the life and birth strings are? Anyone else have this problem? Edit: Also Deleter: Esc doesn't seem to quit the program for me, both in edit mode and running...
/post]
07-12-2005, 12:16 AM
new code: (I forgot to add until multikey(1) after the loop :oops: )
also, hold right mouse and move the mouse around when in edit mode, it moves the camera. you can now see the world to the exent of an Integer's boundaries edit: yeah I pressed enter, and I tried making the default 23/3 mover #-- -## ##- it just turns things blue and thats it. it also does this to the flasher -#- -#- -#- Code: 'Based on Conway's Game of Life
07-12-2005, 02:00 AM
That's weird, does it do that with other configs too like 1/1
and one dot?
/post]
07-12-2005, 06:21 AM
yep 1/1 and one dot turns blue, I am supposed to press space after I make the thing right?
07-12-2005, 05:12 PM
Umm to the left there should be the text Mode: Evolution or Mode: Edit.
You change the mode with spacebar and edit is the mode where you can change the "patterns" (with LMB to make a cell alive and RMB to"kill" it). If the pattern hasn't changed at all since the last iteration in evolution mode, the word STABLE should be printed at the bottom of the screen and the mode should change to edit. Does this happen?
/post]
07-13-2005, 07:07 AM
I press spacebar once, and it flashed evolution really fast, then turns everything blue, without changing a thing on the configuration. It then goes back to saying edit.
07-13-2005, 07:20 PM
What fbc version are you using? I'm using fbc .13
I also have a new version here with some changes and bugfixes (But not your's Deleter, I'm completely clueless :-? ) [syntax="qbasic"]' ' Conway's Game of Life by red_Marvin 2005 ' ' ATTENTION: Coded for FreeBASIC only! ' ' In the beginning please enter the Life/Birth criteria wich specifies ' when a cell survives and is born. Example: 23/3 (Conway's original ' rules) means that a living cell survives to the next iteration if ' it has two or three neighbours and a dead cell becomes living if ' it has exactly 3 neighbours. If left blank, Conway's original ' rules is used. ' ' Toggle between edit and evolution mode with space bar. ' ' Press c to clear the board during edit mode. ' ' Press left mouse button on the board during edit mode to set a ' cell as alive. Press right mouse button to set a cell as dead. ' ' The board is (theoretically) shaped as a torus which means that cells ' at the edges of the board affect each other. ' ' The colors symbolizes the age of the cell/empty space ' White is a living cell and the colours goes towards yellow as time flows. ' Blue is a dead cell/empty space which goes towards black with time. ' ' Press ESC to quit DUH ' ' *---------------------------------------------------------------------------* ' | | ' | This space is for rent, 50â¬/month. Contact me at red_Marvin@hotmail.com | ' | | ' *---------------------------------------------------------------------------* ' option explicit ' I was taught on a programming course that it's always good to ' declare your variables, no mather what. It's also a good place ' to explain what they do if sometimes a little cryptic . dim world(0 to 2, 0 to 199, 0 to 199) as integer ' The "Map" (2,x,y) is the age. dim criteria as string ' A "life and death" kind of important variable. dim div as integer ' The small difference between life and death. dim life as string ' If the sum of neighbours is in this string it will survive if alive. dim birth as string ' If the sum of neighbours is in this string it will be born if dead. dim current as integer ' Points to which part of the world matrix is the one to read from. dim keytrap as string ' What it says. dim mx as integer ' Mouse coordinates dim my as integer ' ^ dim mb as integer ' ^ dim omx as integer ' Old mouse coordinates dim omy as integer ' ^ dim omb as integer ' ^ dim mc as integer ' Color of the pixel that the mouse pointer overwrites dim omc as integer ' Old ^ dim x as integer ' Variously used coordinates dim y as integer ' ^ dim action as integer ' Stops the loop if nothing happened during the iteration dim wx as integer ' World matrix coordinates dim wy as integer ' ^ dim rx as integer ' Relative coordinates dim ry as integer ' ^ dim tx as integer ' Neighbour state test coordinates =(wcoord and rcoord) dim ty as integer ' merged and checked for out of this world values. dim neighboursum as integer ' Sum of the cells around the one being checked. dim actcell as integer ' The state of the currently checked cell. dim futcell as integer ' The future state of the currently checked cell. dim iteration as integer ' The number of iterations dim i as integer ' Uh whatever screen 14,32,2,1 ' Set up the screen: 320x240 32bpp two pages and fullscreen setmouse ,,0 ' Hide the default cursor, it's way too clumsy! windowtitle "Conway's Game of Life by red_Marvin 2005" ' Guess! ' --- Start screen where you enter the life/birth criteria color &hff00 locate 2,2 print "Conway's Game of Life" color &hff0000 locate 4,2 print "by red_Marvin 2005" color &h404040 locate 6,2 print "Please look at the comments at the" locate 7,2 print "beginning for instructions on how" locate 8,2 print "to use this program." locate 10,2 color &hffffff input "Life/Birth Criteria:",criteria ' --- Dividing of the criteria string into the life/birth strings div=instr(criteria,"/") if div=1 then life="" birth=right$(criteria,len(criteria)-1) elseif div>1 then life=left$(criteria,div-1) birth=right$(criteria,len(criteria)-div) else criteria="23/3" life="23" birth="3" end if cls current=0 ' we start reading from the first part of the "map" ' --- Main loop do do:keytrap=inkey$:loop until keytrap="" ' To make shure the user releases the key. screenset 0,0 'I won't do dubble buffering when the mouse is shown, it would be too slow. color &hffffff ' Make sure the user knows what mode it is. ...and stuff locate 2,30 print criteria color &h404040 locate 4,30rint "Mode:" color &hff00 locate 5,30rint "Edit " line (0,0)-(201,201),&h404040,b ' Redraw the frame. ' --- The edit loop do keytrap=inkey$ ' Oh like you don't know. locate 27,2 ' Print what iteration it is color &hffffff print "Iteration:";iteration;space$(16) getmouse mx,my,,mb ' Check the mouse coordinates if mx<>omx or my<>omy or mb<>omb then ' If the mouse status has changed... pset (omx,omy),omc ' Eradicate the old mouse pixel. omc=point(mx,my) ' Make sure the new mouse background is saved ' If mouse clicked on the board then put/erase a cell at the place... if mb=1 and mx>0 and mx<201 and my>0 and my<201 then world(current,mx-1,my-1)=1:world(2,mx-1,my-1)=1:omc=&hffffff if mb=2 and mx>0 and mx<201 and my>0 and my<201 then world(current,mx-1,my-1)=0:world(2,mx-1,my-1)=0:omc=0 ' If the mouse clicked then eradicate all traces of the "STATIC" label. if mb then locate 28,2: print space$(6) ' V Change mouse pixel color depending on if it's on the board or not. if mx>0 and mx<201 and my>0 and my<201 then mc=&hff00 else mc=&hff0000 pset (mx,my),mc ' Draw the cursor. ' Move values on the variable conveyor belt omx=mx omy=my omb=mb end if if lcase$(keytrap)="c" then ' If ce is pressed then clear the world... for i=0 to 1 for y=0 to 199 ' Clear the array for x=0 to 199 world(i,x,y)=0 world(2,x,y)=0 next next next pset (omx,omy),omc ' Eradicate the old mouse pixel. line (1,1)-(200,200),0,bf ' Clear the visible board. omc=point(mx,my) ' Make sure the new mouse background is saved pset (mx,my),mc ' Draw the cursor. iteration=0 ' Reset the iteration counter and make sure we know it. locate 27,2 color &hffffff print "Iteration:";iteration;space$(16) locate 28,2 ' Eradicate all traces of the "STATIC" label. print space$(6) end if loop until keytrap=chr$(32) or keytrap=chr$(27) if keytrap=chr$(27) then end ' D U H do:keytrap=inkey$:loop until keytrap="" ' To make sure the user releases the key. screenset 1,0 ' Set double buffer mode. color &hffffff ' Make sure the user knows what mode it is. ...and stuff locate 2,30 print criteria color &h404040 locate 4,30rint "Mode:" color &hff0000 locate 5,30rint "Evolution" locate 28,2 ' Recognize this? Hmmm. What can it be? print space$(6) line (0,0)-(201,201),&h404040,b ' Redraw the frame. ' --- The evolution loop do action=0 'Nothing has moved yet, we're in the beginning of the loop DUH for wy=0 to 199 ' Check every map position... for wx=0 to 199 neighboursum=0 ' Reset the counter. You're all aloooone Mwahahaaa for ry=-1 to 1 'Check the neighbours for rx=-1 to 1 if ry=0 and rx=0 then actcell=world(current,wx,wy) ' The middle cell else tx=wx+rx:if tx>199 then tx=0 else if tx<0 then tx=199 ' Edge merging ty=wy+ry:if ty>199 then ty=0 else if ty<0 then ty=199 neighboursum=neighboursum+world(current,tx,ty) ' Sum it up end if next next futcell=0 ' Assume the cell dies. (It does if it doesn't meet the criteria) 'If the neighboursum is in the list... if instr(life,trim$(str$(neighboursum)))>0 and actcell=1 then 'Surviveal? futcell=1 ' It survives. elseif instr(birth,trim$(str$(neighboursum)))>0 and actcell=0 then 'Birth? futcell=1 ' It is born. end if if actcell=futcell then ' If it hasn't changed since last time... ' ...it gets older... if world(2,wx,wy)<255 and world(2,wx,wy)>0 then world(2,wx,wy)=world(2,wx,wy)+1 else world(2,wx,wy)=1 ' ...Else reset the age action=1 ' Oooh movement! Continue iterating... end if world(current+1 and 1,wx,wy)=futcell ' Set the state on the map. select case futcell ' Draw the cell. case 1 pset(wx+1,wy+1),rgb(255,255,256-world(2,wx,wy)) case 0 pset(wx+1,wy+1),rgb(0,0,256-world(2,wx,wy)) end select next next locate 27,2 ' Show the number of iterations. color &hffffff print "Iteration:";iteration;space$(16) if action=0 then ' Tell if there's no movement locate 28,2 color &hff0000 print "STATIC" ' <--- end if wait &h3da,8 ' You want to see what's happening, do'nt you screencopy current=current+1 and 1 ' Flip the read/write positions iteration=iteration+1 ' Add ...whatever the number is to the iteration counter keytrap=inkey$ loop until keytrap=chr$(32) or keytrap=chr$(27) or action=0 ' Well what did you expect? loop while keytrap <> chr$(27)[/syntax]
/post]
|
« Next Oldest | Next Newest »
|