2016-08-20 5 views
0

안녕하세요 너희들은 역동적 인 두 선수가 tic tac toe 게임을 만들려고 노력하고 있는데, 나는 이사를해야하고 보드를 확인해야하는 이동 기능에 문제가있다. 당신은 아마 문자 보드 [행] 메모리를 할당 할 필요가이동 기능을 복구하는 방법

#include <stdio.h> 
#include <stdlib.h> 

#define SIGN '_' 
#define FIRST 'X' 
#define SECOND 'O' 

void isValid(void); 
int turn(); 
void printMsg(); 

int main() 
{ 
    printMsg(); 
    int i, j;//indexs 
    int row = 1, column = 1;//first set for the size of the rows\columns. 
    char board[row][column]; 
do 
    { 
    scanf("%d", &row); 
    column = row; 
    }while(row <= 0 || row > 10); 

    for(i = 0; i < row; i++)//for loop to build the board for the game 

    { 

    for(j = 0; j < column; j++) 

     { 
      board[i][j] = SIGN; 
      printf("%c", board[i][j]); 

     } 

     printf("\n"); 
    } 
    turn(); 

    return 0; 
    } 

void printMsg() //prints openning massage. 
{ 
    printf("Enter board size (1 to 10): \n"); 
} 

int turn(int i, int j) 
{ 
    int count = 0; 
    int player = 0; 
    do 
    { 
    printf("\nplayer %d, enter next move: \n", count % 2 + 1); 
     scanf("%d%*c%d", row, column); 
     count++; 
    }while(i > 0 && j > 0); 
    return player; 
} 

답변

0

... 분명 인쇄 이동과 보드 경우 이동에 넣어 다른 플레이어를 말한다 [칼럼] 동적으로 다음과 같이 할 수있다 :

char**board=malloc(col_size); 
    for (int i=0; i<size; i++) 
     *(board+i)=malloc(row_size); 

따라서 셀이 비어 있는지 여부와 동일한 방법으로 체크인 할 수 있습니다.

for (int i=0; i<col_size; i++) 
     for (int c=0; c<row_size; c++) 
      if board[i][c]==filled 
         ... 
      else ...