Hi! Can any c programmers there help me with this assignment please? I really do not get my lecturer.

Conway's life is a special kind of game. It isn't really a game - just a spectator sport. It is played on a chess board, where each cell is either alive or dead. Each turn consists of deciding which squares on the board stay the same or change (becoming either alive or dead) and then admiring the new pattern they produce.

A live square stays alive if it has exactly two or exactly three live neighbours, otherwise it dies.
A dead square becomes alive if it has exactly three live neighbours, otherwise it stays dead.

All births and deaths occur simultaneously. The next round depends only on the positions at the end of the previous round. A neighbouring square is one step away in any direction (including diagonals).

Write a program that uses a 20x20 board, initialised to a given pattern, to play the game. After each turn print out the board pattern using a . for a dead square and a * for a live square. Squares off the board are considered permanently dead.

Hint: you need two 2-D arrays (both global variables). Each one being an array of strings. Form the second array from the first array, using the above rules, then copy it back to the first array, print it and repeat. After each repetition ask the user whether they want to continue or stop.

If your program is working correctly this pattern should show a glider hitting a brick

**..................
**..................
....................
....................
....................
....................
....................
........***.........
........*...........
.........*..........
....................

all the remaining rows are filled with dead squares.

Find another shape, like the brick, that is stable from one generation to another. Include it in a comment in your program.

You need two matrices, one holds the current generation, other to hold the new generation as you create it.

You need two matrices, one holds the current generation, other to hold the new generation as you create it.

Thanks! Would you be able to give me an example though? And how I can get it to have the asterisks (*) and the dots (.)? And, I would need to use a for loop for this aye? Sorry for asking too many questions. I'm new to this, and I just do not get my lecturer!

Tots08:

You have to know the basics of printing out a char array, and putting a value into a char array, or you can't do a program on Conway's Game of Life - because that's the heart of the program, right there.

You need to hit the books, and /or run through some basic C tutorials on the net. You also need to get yourself rested, and ready to learn from your lecturer. You're not being fair to yourself, if you're not set up and ready to do your best with your studies.

Edited 6 Years Ago by Adak: n/a

yeah, and don't forget to take your vitamins.


now as for printing an array, just use a loop:

for (i=0; i<NUM_ROWS; i++)
{
    for(j=0; j<NUM_COLS, j++)
    {
        printf("%c", current_board[i][j]);
    }
    printf("\n");
}

Edited 6 Years Ago by jephthah: n/a

This article has been dead for over six months. Start a new discussion instead.