I have a 2D array i put a '*' char in 0,1 cell.
My program reads the board(2d array) from 1..size
so i subtract 1 from each of the "uncover" input coordinate.
If i dont step on a mine it replaces the value of the cell with the number of the
surrounding cells which has '*' in them.
i wrote this simple case code to demonstrate it
it should print the board with '*' in board[1][0] and '1' in board[0][0]
but it shows me a blank array .
why??
Code:#include <stdio.h> #define N 9 void printBoard(char board[N][N],int size); int unCover(char board[N][N],int size,int x,int y); int main(){ int index,kndex; int x; char board[N][N]; for(index=0;index<N;index++){ for(kndex=0;kndex<N;kndex++){ board[index][kndex]=' '; } } board[1][0]='*'; x=unCover(board,5,1,1); } int unCover(char board[N][N],int size,int x,int y){ int count=0; if (board[y-1][x-1]=='*'){ printf("you lost"); board[y-1][x-1]=='X'; printBoard(board, size); return 0; } else { if (board[y][x]!='*'){ if (((y-2)>0) && ((x-2)>0) && (board[y-2][x-2]=='*')){ //counting how many mines surrounds the cell count++; } if (((y-2)>0) && ((x-1)>0) && (board[y-2][x-1]=='*')){ count++; } if (((y-2)>0) && ((x)<size) && (board[y-2][x]=='*')){ count++; } if (((y)<size) && ((x-2)>0) && (board[y][x-2]=='*')){ count++; } if (((y)<size) && ((x-1)>0) && (board[y][x-1]=='*')){ count++; } if (((y)<size) && ((x)<size) && (board[y][x]=='*')){ count++; } if (((y-1)>0) && ((x-2)>0) && (board[y-1][x-2]=='*')){ count++; } if (((y-1)>0) && ((x)<size) && (board[y-1][x]=='*')){ count++; } board[y-1][x]=(char)count; printBoard(board, size); return 1; } } } void printBoard(char board[N][N],int size){ int index,kndex; for(index=0;index<size;index++){ for(kndex=0;kndex<size;kndex++){ printf("+-+"); } printf("\n"); for(kndex=0;kndex<size;kndex++){ printf("|%c|",board[index][kndex]); } printf("\n"); } for(kndex=0;kndex<size;kndex++){ printf("+-+"); } }



LinkBack URL
About LinkBacks


