Click here to Skip to main content
13,834,966 members

C / C++ / MFC

 
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
mveCPallini12-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
mveCPallini4-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 
AnswerRe: Conways Game of life game in C Pin
元昊 潘3-Nov-18 5:04
member元昊 潘3-Nov-18 5:04 
GeneralRe: Conways Game of life game in C Pin
Victor Nijegorodov3-Nov-18 7:33
memberVictor Nijegorodov3-Nov-18 7:33 
GeneralHow to solve memory resource management problems in C++ Pin
元昊 潘2-Nov-18 23:55
member元昊 潘2-Nov-18 23:55 
GeneralRe: How to solve memory resource management problems in C++ Pin
Richard MacCutchan3-Nov-18 4:56
protectorRichard MacCutchan3-Nov-18 4:56 
AnswerRe: How to solve memory resource management problems in C++ Pin
元昊 潘3-Nov-18 5:39
member元昊 潘3-Nov-18 5:39 
GeneralRe: How to solve memory resource management problems in C++ Pin
Richard MacCutchan3-Nov-18 5:51
protectorRichard MacCutchan3-Nov-18 5:51 
AnswerRe: How to solve memory resource management problems in C++ Pin
元昊 潘3-Nov-18 6:04
member元昊 潘3-Nov-18 6:04 
GeneralRe: How to solve memory resource management problems in C++ Pin
Richard MacCutchan3-Nov-18 11:02
protectorRichard MacCutchan3-Nov-18 11:02 
AnswerRe: How to solve memory resource management problems in C++ Pin
元昊 潘3-Nov-18 17:26
member元昊 潘3-Nov-18 17:26 
GeneralRe: How to solve memory resource management problems in C++ Pin
Richard MacCutchan3-Nov-18 22:17
protectorRichard MacCutchan3-Nov-18 22:17 
AnswerRe: How to solve memory resource management problems in C++ Pin
元昊 潘3-Nov-18 23:00
member元昊 潘3-Nov-18 23:00 
GeneralRe: How to solve memory resource management problems in C++ Pin
Richard MacCutchan3-Nov-18 23:18
protectorRichard MacCutchan3-Nov-18 23:18 
GeneralRe: How to solve memory resource management problems in C++ Pin
元昊 潘3-Nov-18 23:30
member元昊 潘3-Nov-18 23:30 
GeneralRe: How to solve memory resource management problems in C++ Pin
Richard MacCutchan3-Nov-18 23:34
protectorRichard MacCutchan3-Nov-18 23:34 
PraiseRe: How to solve memory resource management problems in C++ Pin
元昊 潘4-Nov-18 0:44
member元昊 潘4-Nov-18 0:44 
GeneralRe: How to solve memory resource management problems in C++ Pin
Stefan_Lang13-Nov-18 23:52
memberStefan_Lang13-Nov-18 23:52 

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
Web03 | 2.8.190114.1 | Last Updated 22 Jan 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid