【发布时间】:2018-10-29 22:41:58
【问题描述】:
抱歉,如果这是一个简单的修复,但我似乎无法在这里找到错误。我正在用 C 语言制作井字游戏。我的程序中的所有内容似乎都运行良好,除了数组中的左上角位置([0][0] 或 1,1,其中 row-1 和 col- 1)。人类玩家和计算机玩家都可以在该位置输入他们的标记,但它会在玩家下一次移动时移除标记。我的代码如下:
我遇到的问题是这样的:
The current state of the game is:
_ _ _
_ _ _
_ _ _
Player 1 enter your selection [row, col]: 2,1
The current state of the game is:
_ _ _
O _ _
_ _ _
Player 2 has entered [row, col]: 3,1
The current state of the game is:
_ _ _
O _ _
X _ _
Player 1 enter your selection [row, col]: 1,1
The current state of the game is:
O _ _
O _ _
X _ _
Player 2 has entered [row, col]: 3,3
The current state of the game is:
_ _ _
O _ _
X _ X
这里到底有什么问题?感谢您的帮助。
【问题讨论】:
-
你用什么编译器来做这个?它应该对此代码发出警告。当我对其进行测试时,我收到报告称
check_table_full、check_end_of_game和check_three_in_a_row都可以在没有正确返回值的情况下结束。我的快速调试表明check_three_in_a_row肯定也会通过无效的代码路径运行。仅此一项就可能导致此问题。 -
我使用的是 gcc 版本 7.3.0 (Ubuntu 7.3.0-16ubuntu3)
标签: c