Ok, I'm a little lost as to what to do next. Basically, I can now run my program - It comes up with the original board, asking me to play. I hit 'y' and it makes a new board with the wrong pattern and won't let me create any more from there (will not ask me to play again, even though I included another getchar in the main function! :S)
I'm fairly sure the line:
Is wrong, but I wasn't sure what else to put there, when I first made it.
I've uploaded a screen shot of how the program looks when run:
http://i19.tinypic.com/6f96yid.jpg
And my latest code:
Code:
#include <stdio.h>
#include <string.h>
void display_fctn (char b1[][21], char b2[][21]);
void new_board (char b1[][21], char b2[][21]);
void copy_back (char b1[][21], char b2[][21]);
int neighbours (int p, int q);
char b1[20][21] = {"**..................",
"**..................",
"....................",
"....................",
"....................",
"....................",
"....................",
"........***.........",
"........*...........",
".........*..........",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"....................",
"...................."};
char b2[20][21];
int main() {
char c;
display_fctn(b1, b2);
printf("Would you like to play? (y/n)");
c = getchar();
while (c == 'y') {
new_board(b1, b2);
copy_back(b1, b2);
display_fctn(b1, b2);
c = getchar();
}
}
void display_fctn(char b1[][21], char b2[][21]) {
int i;
for (i=0; i<20; i++) {
printf("%s \n", b1[i]);
}
}
void new_board(char b1[][21], char b2[][21])
{
int i, j, p;
for (i=0; i<20; i++)
{
for (j=0; j<20; j++)
{
p=neighbours(i,j);
if(b1[i][j]=='*')
{
if(p==2||p==3)
{
b2[i][j] = '*';
}
else
{
b2[i][j] = '.';
}
}
else
{
if (p == 3)
{
b2[i][j] = '*'; /* b2 corresponding position gets a '*' */
}
else
{
b2[i][j] = '.'; /*b2 gets a '.' */
}
}
}
}
b2[i][j] = '\0'; /* b2[i][j] = '\0'; ----assign ????? \0 */
}
void copy_back(char b1[][21], char b2[][21]) {
int i;
for (i=0; i<20; i++) {
strcpy(b1[i], b2[i]);
}
}
int neighbours(int p, int q) {
int count;
/* ((8 ifs?????))*/
if (p!=0 && q!=19 && b1[p-1][q+1] == '*') {
count = p + q; /* ??? */
}
return count; /* return count */
}
/* initialise variables eg int i = 0 ?? */
Any tips on where to go from here would be great. Thank you. =)