life simulation

This is a discussion on life simulation within the C Programming forums, part of the General Programming Boards category; hi, My Challenge: to populate a 20x20 array with 100 random numbers which will represent organisms which will then die ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    14

    Question life simulation

    hi,

    My Challenge: to populate a 20x20 array with 100 random numbers which will represent organisms which will then die out based on their neighbours' existence.

    My approach: I've generated the 100 numbers between 0 and 400 using srand, which to my simple mind I would like to use to represent the random positions in the array, then I would like to place an asterisk in the positions, representing the life-forms.

    Is this too complex an approach 'cause for the life of me I can't get them read into the array.

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    > I can't get them read into the array.

    Use two for-loops to enter the data into the array.

    Code:
    for (x = 0; x < 20; x++)
      for (y = 0; y < 20; y++)
        array [x][y] = value;

  3. #3
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    It's a multi-dimensional array, you could first populate him, by asking the user, or just generating instead one random number, two random numbers, like this:
    Code:
    int x,y;
    x = rand()%20+1;
    y = rand()%20+1; 
    
    colony[x][y] = '*';
    Also, it's not difficult to make the game... you need few functions, some of them to see how many neighbours a simple citizen have. The most funny in this game is the rules, this game is used in a lot of researches, really funny.

    Remember, you don't fill all the array in the first time, just add some citizens and see the evolution.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Artificial Life: Where to Start?
    By Mr.Sellars in forum General AI Programming
    Replies: 11
    Last Post: 09-22-2007, 03:03 AM
  2. Game of life
    By JoshR in forum C++ Programming
    Replies: 30
    Last Post: 04-03-2005, 03:17 PM
  3. The Meaning of Life: A Trick Question?
    By chix/w/guns in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 07-12-2004, 08:53 PM
  4. The more intelligent risks you take in life, the more you'll achieve
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 05-20-2003, 06:23 PM
  5. Life, The Universe, and everything else
    By ZooTrigger1191 in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 03-29-2003, 05:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21