如何为 Windows Phone 棋盘游戏编写简单的 AI? [英] How to code simple AI for a windows phone board game?

查看:24
本文介绍了如何为 Windows Phone 棋盘游戏编写简单的 AI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像这样:

我不知道如何为此编写代码,因为我只编写了非游戏应用程序.例如,您如何确定玩家采取行动后的最佳行动?我不需要完美的动作,只要有挑战性就行.

I am not sure how to code for this as I have only coded non-game apps. For instance how do you determine the best move after the player has made his move? I don't need the perfect moves, just challenging enough.

我不知道我是否必须扫描所有可能的动作等.在如图所示的游戏中,可能的动作数量非常有限,对吗?所以我可以把它们全部计算出来.但我不确定哪一个会更好,等等.

I don't know if I have to scan all the possible moves, etc. In a game like shown in the pic, the number of possible moves are very limited, right? So I could calculate them all. But I am not sure which one would be a better move, etc.

推荐答案

在像井字棋这样的小型简单游戏中,您可以构建一棵树,其中:

In a small, simple game like tic-tac-toe, you can build a tree, where:

  • 每个节点都是一个棋盘位置
  • 每个叶子节点是一个完成的游戏,+1 表示 X 获胜,-1 如果 O 获胜,0 表示平局
  • 每个子节点都是其父节点合法移动的结果

然后 X 正在寻找一个可以最大化最小结果的移动,知道 O 将搜索(在他的后续回合中)一个可以最小化最大结果的移动,知道 X 将搜索(在他随后的回合中)) 的举动将...

Then X is searching for a move which will maximize the minimum result, knowing that O will search (on his subsequent turn) for a move which will minimize the maximum result, knowing that X will search (on his subsequent turn to that) for a move which will...

这是极大极小算法.

在 Tic-Tac-Toe 中,树的深度只能达到 9 层,如果您想变得光滑,可以利用一些棋盘对称性并保持计算和数据结构的可管理性.

In Tic-Tac-Toe, the tree can only get 9 layers deep, and if you want to be slick, you can take advantage of some board symmetries and keep the computations and data structures manageable.

请注意,对于更复杂的游戏,这会因某种原因而失败(国际象棋是确定性的,但太大而无法以这种方式处理;西洋双陆棋需要概率技术等),但许多方法是这一主题的变体.

Note that for more complex games this will fail for one reason or another (chess is deterministic, but too large to handle this way; backgammon needs probabilistic techniques, etc) but many approaches are variations on this theme.

这篇关于如何为 Windows Phone 棋盘游戏编写简单的 AI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆