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

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

问题描述

事情是这样的:

我不知道如何code这个,因为我只有codeD非游戏应用程序。举例来说,你如何确定最佳的移动后的玩家提出了他的举动?我不需要完美的动作,只是足够的挑战性。

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如果可胜,0平局
  • 在每个子节点是从它的父
  • 法律举措的结果
  • each node is a board position
  • each leaf node is a finished game with a score of +1 is X wins, -1 if O wins, 0 for a draw
  • each child node is the result of a legal move from its parent

则X是寻找一个此举将最大限度地最小结果,知道澳的搜索(他后来转)的举措,这将在最大结果最小化,知道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...

这是极大极小算法。

在井字棋,树只能得到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.

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

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