Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Game of Life

Game of Life

Scheduled Pinned Locked Moved The Lounge
5 Posts 4 Posters 0 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    G Poulose
    wrote on last edited by
    #1

    Does anyone have a C++ implementaion of John Conway's Game of Life? Thanks much. Georg

    A D B 3 Replies Last reply
    0
    • G G Poulose

      Does anyone have a C++ implementaion of John Conway's Game of Life? Thanks much. Georg

      A Offline
      A Offline
      Alex
      wrote on last edited by
      #2

      Yes, here it is: /* * * CS2123 - C Programming - 10:30 MWF * David John Davis * Chapter 5 - Exercise 18 * * Start Date: October 15, 1996 * Last Changed: October 16, 1996 * * John H. Conway (Scientific American, October 1970, p. 120) invented a game called * Life to model the process of birth, survival, and death. The idea is that * organisms require others in order to survive and procreate but that overcrowding * results in death. This program simulates the game Life. It ask the user for an * integer which it uses to seed a random number generator. This random number * generator is used to generate a random first generation in the game. After this * the game continues for the number of generations defined by N. The games follows * these rules: * * A) Birth Rule: An organism is born into any empty cell that has exactly three * living neighbors. * B) Survival Rule: An organism with either two or three neighbors survives from * one generation to the next. * C) Death Rule: An organism with four or more neighbors dies from overcrowding. * An organism with fewer than two neightbors dies from loneliness. * * This program uses a 10x10 array to represent the environment, and each cell can * have a * to represent a life, or be blank. * */ #include #include #define LIFE_GRID 10 /* Defines the width x height of the arrays used. */ #define N 20 /* Defines the number of generations the program should simulate. */ void load_init(char [LIFE_GRID][LIFE_GRID]); /* Function to setup initial generation. */ void step_generation(char [LIFE_GRID][LIFE_GRID]); /* Function to move forward one generation. */ void print_grid(char [LIFE_GRID][LIFE_GRID]); /* Function to print the array. */ int neighbors(char [LIFE_GRID][LIFE_GRID],int,int); /* Function to figure the number of neighbors for a given cell. */ void copy_array(char [LIFE_GRID][LIFE_GRID],char [LIFE_GRID][LIFE_GRID]); /* Function to copy the contents of one array to another. */ void main(void) { char life[LIFE_GRID][LIFE_GRID]; /* Array used for the simulation. */ int i; unsigned int seed; /* Holds the user entered seed for the random number generater. */ /* Get a unsigned int from the user and use it to seed the random number generator. */ printf("\nPlease enter a postive integer: "); scanf("%u",&seed); srand(seed); /* Print a message to the screen and run load_init to setup the initial generation. */ printf("\n\nGenerating inital grid...\n

      G 1 Reply Last reply
      0
      • A Alex

        Yes, here it is: /* * * CS2123 - C Programming - 10:30 MWF * David John Davis * Chapter 5 - Exercise 18 * * Start Date: October 15, 1996 * Last Changed: October 16, 1996 * * John H. Conway (Scientific American, October 1970, p. 120) invented a game called * Life to model the process of birth, survival, and death. The idea is that * organisms require others in order to survive and procreate but that overcrowding * results in death. This program simulates the game Life. It ask the user for an * integer which it uses to seed a random number generator. This random number * generator is used to generate a random first generation in the game. After this * the game continues for the number of generations defined by N. The games follows * these rules: * * A) Birth Rule: An organism is born into any empty cell that has exactly three * living neighbors. * B) Survival Rule: An organism with either two or three neighbors survives from * one generation to the next. * C) Death Rule: An organism with four or more neighbors dies from overcrowding. * An organism with fewer than two neightbors dies from loneliness. * * This program uses a 10x10 array to represent the environment, and each cell can * have a * to represent a life, or be blank. * */ #include #include #define LIFE_GRID 10 /* Defines the width x height of the arrays used. */ #define N 20 /* Defines the number of generations the program should simulate. */ void load_init(char [LIFE_GRID][LIFE_GRID]); /* Function to setup initial generation. */ void step_generation(char [LIFE_GRID][LIFE_GRID]); /* Function to move forward one generation. */ void print_grid(char [LIFE_GRID][LIFE_GRID]); /* Function to print the array. */ int neighbors(char [LIFE_GRID][LIFE_GRID],int,int); /* Function to figure the number of neighbors for a given cell. */ void copy_array(char [LIFE_GRID][LIFE_GRID],char [LIFE_GRID][LIFE_GRID]); /* Function to copy the contents of one array to another. */ void main(void) { char life[LIFE_GRID][LIFE_GRID]; /* Array used for the simulation. */ int i; unsigned int seed; /* Holds the user entered seed for the random number generater. */ /* Get a unsigned int from the user and use it to seed the random number generator. */ printf("\nPlease enter a postive integer: "); scanf("%u",&seed); srand(seed); /* Print a message to the screen and run load_init to setup the initial generation. */ printf("\n\nGenerating inital grid...\n

        G Offline
        G Offline
        G Poulose
        wrote on last edited by
        #3

        Alex, Thanks very much. >ps: if you port it to a window appl, please send me a copy I will. George

        1 Reply Last reply
        0
        • G G Poulose

          Does anyone have a C++ implementaion of John Conway's Game of Life? Thanks much. Georg

          D Offline
          D Offline
          David Kinder
          wrote on last edited by
          #4

          Although it's C not C++, the best life implementation I've seen is still XLife: http://www.cs.jhu.edu/~callahan/lifepage.html Which uses a much better algorithym than just making an n by x array, making it run 100s of times faster for big patterns like "breeder". I've got a Windows version (sort of) working based on a half-finished X11 implementation I wrote some time back - email me if you're interested

          1 Reply Last reply
          0
          • G G Poulose

            Does anyone have a C++ implementaion of John Conway's Game of Life? Thanks much. Georg

            B Offline
            B Offline
            Buck
            wrote on last edited by
            #5

            Unsure but maybe this helps http://www.geocities.com/simesgreen/gllife/index.html regardz Colin Davie

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups