gpt4 book ai didi

C:已完成 Tic Tac Toe 程序,正在寻找改进的技巧

转载 作者:行者123 更新时间:2023-11-30 21:39:14 24 4
gpt4 key购买 nike

自从上次以来我已经完成了我的代码(感谢大家的帮助!)。

最佳答案

我不能 100% 确定您的代码应该是一个完整的游戏,但我可以更改返回值,以便您的代码编译并启动 Tic-Tac-Toe。

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

char **display_board(char **board) { //Create board function

const char NUM_COLS = 3;
const char NUM_ROWS = 3;
const char BLANK_SPACE = '*';

int i, j, k, l;
board = (char **) malloc(NUM_ROWS * sizeof(char *));
for (i = 0; i < NUM_ROWS; i++) {
board[i] = (char *) malloc(NUM_COLS * sizeof(char));

for (j = 0; j < NUM_COLS; j++) {
board[i][j] = BLANK_SPACE;
}

//Display board function
}

for (k = 0; k < NUM_ROWS; k++) {
for (l = 0; l < NUM_ROWS; l++) {
printf("%c", board[k][l]);
}
printf("\n");
}
return board;
}

int main() {
char **board;
int row, col;
const char BLANK_SPACE = '*';

int turn, i;
turn = 0;

display_board(board);

//need while !game_not_over conditional statement

for (i = 0; i < 20; i++) {
turn + 1;
}

if (turn % 2 == 0) {
printf("O's turn\n");
printf("Make your move");
scanf("%d, %d", &row, &col);

if ((row == 0 && col == 0) && (board[0][0] == BLANK_SPACE)) {
display_board(board);
board[0][0] = '0';
}
return 0;
}
}

测试

Debug/gnu
***
***
***
O's turn
Make your move***

关于C:已完成 Tic Tac Toe 程序,正在寻找改进的技巧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37625372/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com