Results 1 to 20 of 20

Thread: [RESOLVED] Game Of Life

  1. #1

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Resolved [RESOLVED] Game Of Life

    Several weeks ago someone asked about this and I became intrigued. Since then I have made 3 different versions, one console, two forms. I kept the last one, and continue to work on it. It is stable, with a not very refined front end, so if anyone would like me to post it I will.

    It includes about 130 automaton.

    Reference - http://en.wikipedia.org/wiki/Conway's Game of Life

    update - 3/18/2010 - Restart. When completed I'll post in the codebank and place a link here.

    update - 2/28/2010 - Getting closer.

    update 3/1/2010 - better drawing.


    Last edited by dbasnett; Mar 18th, 2010 at 06:00 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  2. #2

    Re: Game Of Life

    I'd like to see it posted, just to see how the logic flow of the program actually works.

  3. #3

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Game Of Life

    Just so you know, the program takes the resources and converts them to a file in my documents.
    Last edited by dbasnett; Feb 18th, 2010 at 10:38 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Game Of Life

    @formless - if you look at the program, you might wonder why I approached the file handling in the manner I did.

    I am an old programmer, so old that I remember when memory was not abundant, and you didn't have an option to read the entire file, as lines, into memory. So I did it just to see if I still had it. It would have been easier to read the entire file.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Game Of Life

    Heh, I made one too a few days ago just for the fun of it. Posted it in the codebank. Mine doesn't include any automaton yet though, but you can save and load grids, and it supports different grid and cell sizes and it remembers the grid before you play it, so it resets when you stop it (though you can also pause it).

    It's probably not the most efficient, but it works flawlessly for relatively small grids (< 100 rows/columns) and a little slow for larger grids.

    http://www.vbforums.com/showthread.php?p=3731969

  6. #6

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Game Of Life

    Well, as usual, I found some flaws after I posted. So I deleted that and added the new version here.

    I'll re-post the attachment when I am happy

    My PC is not the fastest, and I am seeing 30+ life changes per second with some pretty complex patterns like:

    BTW - I am drawing a grid of 269 x 269 with a block size of 3 x 3 squares.

    Code:
    #Life 1.05
    
    #D Rake for the Breeder
    
    #D
    
    #D Uses a different puffer train
    
    #D than the other rakes.
    
    #N
    
    #P 7 -12
    
    .******
    
    *.....*
    
    ......*
    
    *....*
    
    ..**
    
    #P 11 -4
    
    **
    
    .**
    
    **
    
    *
    
    .
    
    *
    
    **
    
    .**
    
    **
    
    #P 6 -6
    
    ..*
    
    .*
    
    **
    
    *.*
    
    .*
    
    .
    
    .
    
    .
    
    .*
    
    *.*
    
    **
    
    .*
    
    ..*
    
    #P 7 8
    
    ..**
    
    *....*
    
    ......*
    
    *.....*
    
    .******
    
    #P -4 -16
    
    ..**
    
    *....*
    
    ......*
    
    *.....*
    
    .******
    
    #P -4 12
    
    .******
    
    *.....*
    
    ......*
    
    *....*
    
    ..**
    
    #P -29 -13
    
    ..*
    
    *...*
    
    .....*
    
    *....*
    
    .*****
    
    #P -29 9
    
    .*****
    
    *....*
    
    .....*
    
    *...*
    
    ..*
    
    #P -89 -11
    
    ..*
    
    *...*
    
    .....*
    
    *....*
    
    .*****
    
    #P -89 7
    
    .*****
    
    *....*
    
    .....*
    
    *...*
    
    ..*
    Last edited by dbasnett; Feb 19th, 2010 at 06:20 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Game Of Life

    I am working on exposing world wrap and block size. If anyone is interested I'll post it when I am done.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  8. #8

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Game Of Life

    I'll re-post the entire project when I stop changing it.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Game Of Life

    The FPS calculation is off. Will fix it, and any other errors, later.

    Also working on some basic drawing.
    Last edited by dbasnett; Feb 25th, 2010 at 10:22 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  10. #10
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Game Of Life

    What kind of format is the file stored in?

  11. #11

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Game Of Life

    Quote Originally Posted by minitech View Post
    What kind of format is the file stored in?
    The file is a dump of all the resources. Each resource in the file starts with Chr(0)#D
    The name is next, then lines of the pattern.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  12. #12

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Game Of Life

    Quote Originally Posted by dbasnett View Post
    The file is a dump of all the resources. Each resource in the file starts with Chr(0)#D
    The name is next, then lines of the pattern.
    The patterns can be in Life 1.05 or 1.06 format.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  13. #13
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Game Of Life

    What is the format though? I don't know what the Life 1.05/06 formats are.

  14. #14
    Lively Member
    Join Date
    Oct 2009
    Posts
    73

    Re: Game Of Life

    Hi I was wondering if anyone had tried to write any code for the Game of life in a console app.

  15. #15

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Game Of Life

    Format

    http://psoup.math.wisc.edu/mcell/ca_...ml#Life%201.05

    basically they are text files with a few control commands starting with #.

    * = on
    . = off

    Here is a sample named glider

    ***
    *..
    .*.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  16. #16

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Game Of Life

    See post #1 in this thread for the latest version. Crude drawing and life birth/survival control added.

    Warning, I have allowed the cell size to be 1. On my PC that is a grid of 839 x 839 (703,921 cells). It can get pretty slow at those sizes, but some beautiful patterns can be created with low birth rates.

    Enjoy.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  17. #17

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Game Of Life

    Moved to post #1
    Last edited by dbasnett; Mar 18th, 2010 at 05:57 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  18. #18

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Game Of Life

    Using the CellularAutomaton Module from the screen version, here is a console application.

    Code:
    Module Module1
    
        Dim theWorld As New CellUniverse(Console.LargestWindowHeight - 16, True) 'create world wrapped
        Dim LDP As New List(Of CellXYState) 'store the states
    
        Sub Main()
            Console.SetWindowSize(theWorld.Size + 2, theWorld.Size + 2) 'set the window size
            Dim ptrn As New List(Of String) 'our pattern - glider
            ptrn.Add("#! -10 -10") 'non standard - global offset x y
            ptrn.Add("***")
            ptrn.Add("..*")
            ptrn.Add(".*")
            theWorld.LoadPattern(ptrn) 'load the pattern
            LDP = theWorld.GetTick() 'get all on pixels
            drawgrid() 'draw the grid
            drawpoints() 'draw the points
            Dim s As ConsoleKeyInfo
            s = Console.ReadKey 'wait for user input (Enter key)
            Do
                LDP = theWorld.NextGeneration() 'get the next generation
                drawpoints() 'draw the points
                s = Console.ReadKey 'wait for enter
            Loop While s.Key = ConsoleKey.Enter 'if not eneter key - end
        End Sub
    
        Sub drawpoints()
            For x As Integer = 0 To LDP.Count - 1 'loop through all the points returned
                Console.SetCursorPosition(LDP(x).X, LDP(x).Y) 'move the cursor
                If LDP(x).State Then 'check state
                    'on
                    Console.Write("*")
                Else
                    'off
                    Console.Write(".")
                End If
            Next
            Console.SetCursorPosition(0, Console.WindowHeight - 1)
        End Sub
    
        Sub drawgrid() 'draw grid representing worlds
            Console.Clear()
            For y As Integer = 0 To theWorld.Size
                For x As Integer = 0 To theWorld.Size
                    Console.SetCursorPosition(x, y)
                    Console.Write(".")
                Next
            Next
            Console.SetCursorPosition(0, Console.WindowHeight - 1)
        End Sub
    End Module
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  19. #19

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Game Of Life

    1. This should be moved to the Code Bank

    2. Just when you think all is well you find

    Code:
    #D Replicator - Nathan Thompson
    #R 23/36
    #P -2 -2
    .OOO
     O...
     O...
     O...
    I think I have it fixed, but ....
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  20. #20

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [RESOLVED] Game Of Life

    See post #1 for updates.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width