【发布时间】:2018-10-30 05:21:29
【问题描述】:
在我的代码中,我总共有十个函数,我只能对其中两个进行完全编码,并且我已经设置了我的主要函数。我完全迷失了其他功能。如果您可以添加示例编码和解释,这将是一个巨大的帮助,以便我更好地理解。
这是我的代码:
#include <stdio.h>
#define SIZE 3
/* main function */
int main ()
{
char board[SIZE][SIZE];
int row, col;
clear_table (board);
display_table (board);
do
{
get_player1_mover (board, row, col);
generate_player2_move (board, row, col);
} while (check_end_of_game (board) == false);
print_winner (board);
return 0;
}
/* display table function */
void display_table (int board[][SIZE], int SIZE)
{
int row, col;
printf ("The current state of the game is:\n");
for (row = 0; row < SIZE; row++)
{
for (col = 0; col < SIZE; col++)
{
char board[row][col];
board[row][col] = '_';
printf ("%c ", board[row][col]);
}
printf ("\n");
}
}
/* clear table function */
void clear_table (int board[][SIZE], int SIZE)
{
int row, col;
char board[row][col];
for (row = 0; row < SIZE; row++) {
for (col = 0; col < SIZE; col++) {
if (board[row][col] == 'x' || array[row][col] == 'o') {
board[row][col] = '_';
}
}
}
}
/* check table full function */
/* return True if board is full */
/* return False if board is not full */
check_table_full (int board[][SIZE], int SIZE)
{
/* update table function */
/* updates board with player moves */
/* return nothing */
void update_table (int board[][SIZE], int SIZE)
{
/* check legal option function */
/* True if legal, False if not */
/* if move is within bounds of board or on empty cell */
check_legal_option (int board[][SIZE], int SIZE)
{
/* generate player2(computer) move function */
/* generate a random move */
/* update board */
/* print out current state of board */
void generate_player2_move (int board[][SIZE], int SIZE)
{
/* check three in a row function */
/* return zero if draw */
/* return one if player1 has three in a row */
/* return two if player2 has three in a row */
check_three_in_a_row (int board[][SIZE], int SIZE)
{
/* check end of game function */
/* return True if game ended */
/* return false if game continues */
check_end_of_game (int board[][SIZE], int SIZE)
{
/* get player 1 move function */
/* if given move is not valid get another move */
/* update board */
/* print out board */
void get_player1_move (int board[][SIZE], int SIZE)
{
int row, col;
printf
("Player 1 enter your selection [row, col]: ");
scanf ("%d,%d", &row, &col);
char board[row][col];
board[row][col] = 'o';
printf ("The current state of the game is:\n");
/* print winner function */
void print_winner (int board[][SIZE], int SIZE)
{
我已经完成的功能是display_table 和clear_table,我几乎完成了get_player1_move,但我不知道如何确保它打印出表格。
【问题讨论】:
-
嗯,没有右括号的空函数比完整函数多。您目前正在打印表格吗? (提示:开始时,每级至少使用 4 个空格缩进,至少我发现这有助于保持逻辑清晰)。
标签: c function multidimensional-array