如何对CPU进行编程以随机按按钮?
我正在Matlab应用程序设计师中创建一个游戏,玩家在该游戏中与计算机对手进行比赛。我想编码CPU在轮到它时随机按下按钮。例如,在Tictactoe中,玩家对另一个玩家进行比赛,但在这种情况下,对手是CPU。 CPU能够随机单击按钮,例如,如果有9个按钮,则会按随机的9个按钮,只要尚未按下它。我不确定如何对此进行编程。
我尝试使用回调函数,但不知道如何对CPU进行编程以随机按按钮。
I am creating a game in matlab app designer in which a player plays against the computer opponent. I want to code the CPU to press a button at random when it is its turn. For example, in TicTacToe the player plays against another player but in this case, the opponent is the CPU. The CPU is able to click buttons at random for example if there are 9 buttons it will press on any of those 9 randomly providing it has not been pressed already. I am not sure how to program this any help would be highly appreciated.
I have tried to use the callback function but do not know how to program the cpu to randomly press buttons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第二个思考,这不像触发回调功能那样简单,因为您必须让AI知道何时“按”按钮。因此,有关通知AI的零件也应在回调函数中:
On second thought, this is not as simple as triggering the callback function, because you have to let the AI know when to "press" the button also. So, the part about notifying the AI should be in the callback function as well: