how to repair move function

c ansi-c

40 просмотра

1 ответ

hello guys i am trying to build a dynamic two players tic tac toe game and i have a problem with the move function that need to get the player move and check the board if the reqested spot is clear, if clear print the board with the move and tells the other player to put in the move...

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

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

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

int main()
  int i, j;//indexs
  int row = 1, column = 1;//first set for the size of the rows\columns.
  char board[row][column];
    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]);



  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;
     printf("\nplayer %d, enter next move: \n", count % 2 + 1);
       scanf("%d%*c%d", row, column);
     }while(i > 0 && j > 0);
    return player;
Автор: user3451179 Источник Размещён: 08.11.2019 11:28

Ответы (1)

0 плюса


You probably need to allocate memory for char board[row][column] dynamically, may be like this:

  for (int i=0; i<size; i++)

Hence, you could check in the same way if cell is empty or not;

for (int i=0; i<col_size; i++)
        for (int c=0; c<row_size; c++)
             if board[i][c]==filled
             else ...
Автор: Anatoly Strashkevich Размещён: 20.08.2016 03:20
Вопросы из категории :