Click here to Skip to main content
13,764,207 members

C / C++ / MFC

 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder12-Jul-09 23:37
adminChris Maunder12-Jul-09 23:37 
PinnedHOW TO ASK A QUESTION PinPopular
Chris Maunder12-Feb-09 18:19
adminChris Maunder12-Feb-09 18:19 
Questionfacing issue in “Ajantha” font on windows10 in GDIplus Pin
Avinash.Pandey12-Nov-18 23:06
memberAvinash.Pandey12-Nov-18 23:06 
QuestionRe: facing issue in “Ajantha” font on windows10 in GDIplus Pin
Richard MacCutchan19hrs 30mins ago
protectorRichard MacCutchan19hrs 30mins ago 
AnswerRe: facing issue in “Ajantha” font on windows10 in GDIplus Pin
leon de boer18hrs 14mins ago
memberleon de boer18hrs 14mins ago 
QuestionElevate Process from user to Admins Rights without UAC Elevation Pin
Drakelor12-Nov-18 22:22
memberDrakelor12-Nov-18 22:22 
AnswerRe: Elevate Process from user to Admins Rights without UAC Elevation Pin
Richard MacCutchan12-Nov-18 22:35
protectorRichard MacCutchan12-Nov-18 22:35 
QuestionOk im back with another problem... Pin
Member 140474359-Nov-18 13:36
memberMember 140474359-Nov-18 13:36 
AnswerRe: Ok im back with another problem... Pin
Richard MacCutchan9-Nov-18 22:44
protectorRichard MacCutchan9-Nov-18 22:44 
AnswerRe: Ok im back with another problem... Pin
leon de boer10-Nov-18 20:21
memberleon de boer10-Nov-18 20:21 
QuestionMobile app Pin
valentineNandang9-Nov-18 3:45
membervalentineNandang9-Nov-18 3:45 
AnswerRe: Mobile app Pin
Richard MacCutchan9-Nov-18 3:52
protectorRichard MacCutchan9-Nov-18 3:52 
QuestionHello I am having a problem Pin
Member 140474357-Nov-18 13:30
memberMember 140474357-Nov-18 13:30 
AnswerRe: Hello I am having a problem Pin
David Crow7-Nov-18 18:34
memberDavid Crow7-Nov-18 18:34 
QuestionScript generation from Objects using C++ Pin
FrankStar895-Nov-18 13:30
memberFrankStar895-Nov-18 13:30 
AnswerRe: Script generation from Objects using C++ Pin
CPallini5-Nov-18 22:06
mvpCPallini5-Nov-18 22:06 
GeneralRe: Script generation from Objects using C++ Pin
FrankStar8912-Nov-18 12:19
memberFrankStar8912-Nov-18 12:19 
GeneralRe: Script generation from Objects using C++ Pin
CPallini12-Nov-18 22:18
mvpCPallini12-Nov-18 22:18 
AnswerRe: Script generation from Objects using C++ Pin
leon de boer6-Nov-18 15:30
memberleon de boer6-Nov-18 15:30 
GeneralRe: Script generation from Objects using C++ Pin
FrankStar8912-Nov-18 12:22
memberFrankStar8912-Nov-18 12:22 
QuestionGames Pin
Member 140425973-Nov-18 6:24
memberMember 140425973-Nov-18 6:24 
AnswerRe: Games Pin
OriginalGriff3-Nov-18 6:27
protectorOriginalGriff3-Nov-18 6:27 
AnswerRe: Games Pin
CPallini4-Nov-18 22:50
mvpCPallini4-Nov-18 22:50 
QuestionConways Game of life game in C Pin
Abhinav99933-Nov-18 2:27
memberAbhinav99933-Nov-18 2:27 
============================================================================
Name : new.c
Author : Abhinav
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/

include <stdio.h>

include <stdlib.h>


void compute(int N[6][6],int Z[6][6])
{
//compute neighbours
int i,j;
for (i = 1; i <=6; i++)
{
    for (j = 1; j <= 6; j++)
    {
        N[i][j]=Z[i-1][j-1]+Z[i][j-1]+Z[i+1][j-1]
           + Z[i-1][j] +Z[i+1][j]+ Z[i-1][j+1]
           +Z[i][j+1]+Z[i+1][j+1];
    }
}

}

// This method is going to print the Matrix that we have defined in the main method
void show(int Z[6][6])
{
printf("************************************************************\n");
int i,j;
// Incrementing the value of integer i so that it can be used as an index value for matrix 'Z'.
for (i = 0; i < 6; i++)
{
    // Incrementing the value of integer j to be used as the second index value for matrix 'Z'.
    for (j = 0; j < 6; j++)
    {
        // This will print the elements present in th array line wise.
        printf("%d ", Z[i][j]);
    }
    printf("\n");
}

printf("************************************************************\n");
}
/* This method is going to take the value of elements
from the array and compute the output according to
some conditions. Like for the rule of UnderPopulation
we have to check that if the element at some index is surrounded
by less than two live elements than the element is going to die.
*/
void iteration(int Z[6][6]){
int N[6][6]= {{0}};
int i,j;
compute(N,Z);

for (i = 0; i < 6; i++)
{
    for (j = 0; j < 6; j++)
    {
        if((Z[i][j] == 1)&&(N[i][j] < 2 || N[i][j] > 3))
        {
            Z[i][j] = 0;
        }
        else if((Z[i][j] == 0)&&(N[i][j] == 3))
        {
            Z[i][j] = 1;
        }
    }
}

/*
for (i = 0; i < 6; i++)
{
for (j = 0; j < 6; j++)
{
if((N[i][j] < 2 )) // Rule number 1 - Under population
{
if (Z[i][j]==1&&((N[i][j] ==2 )||(N[i][j] == 3 ))) // Rule 4 - Next generation
{
Z[i][j] = 1;
}
else
{
Z[i][j] = 0;
}
        }
        else if ((Z[i][j] == 0)&&(N[i][j]==3)) // Rule 2 - Dead cell become live
        {
            Z[i][j] = 1;
        }
        else if ((N[i][j]>3)) // Rule 3 - Overpopulation
        {
            Z[i][j] = 0;
        }
    }
}
*/

}
/*
In this main method all the method are called to execute
all the methods.
*/
int main()
{
// Here I have declared a 6x6, 2D array which contains 36 elements.
int Z[6][6]=
{
    // In this array '1' denotes live cell where as '0' denotes dead cell.

    {1, 0, 0, 0, 0, 0},
    {0, 0, 0, 1, 0, 0},
    {0, 1, 0, 1, 0, 0},
    {0, 0, 1, 1, 0, 0},
    {0, 0, 0, 0, 0, 0},
    {0, 0, 0, 0, 0, 0},
};
// This will pass the value of elements of array into the method 'show()'

int i;
printf("Here is the array that i have declared for the GAME.\n");
show(Z);
printf("\n");

printf("****************************************************************\n");
printf("Actual output after computing the results\n");
for(i=1; i<= 5; i++) // This will tell us the number of generations to skip before the answer
{
    //clear(); //clear screen
    iteration(Z);
    printf("#################################################");
    printf("This is the %d generation",i);
    show(Z);

}

printf("****************************************************************\n");
return 0;

}
AnswerRe: Conways Game of life game in C Pin
Richard MacCutchan3-Nov-18 4:57
protectorRichard MacCutchan3-Nov-18 4:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.181113.4 | Last Updated 14 Nov 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid