在井字棋人工智能使用C# [英] Artificial Intelligence in Tic-Tac-Toe using C#

查看:246
本文介绍了在井字棋人工智能使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了井字棋游戏 2的球员。现在,我想给游戏人工智能。

I have made a Tic-Tac-Toe game for 2 players. Now, I want to give the game Artificial Intelligence.

让游戏能 1播放器和电脑。结果
请帮助我如何开始?

So that game can be played between 1 player and computer.
Please, help How do I start?

推荐答案

通过井字它没有那么多一个AI,但是一个查找表:对于每一个可能的电路板布局,找到最佳点。

With Tic Tac Toe it's not so much an AI but a lookup table: For each possible board layout, find the best spot.

XKCD有这样一个查找表。基本上每个电路板布局得到一个唯一的ID,并现场在哪里设置一个标记的地址。维基百科有另一种格式表

XKCD has such a lookup table. Basically each Board Layout gets a unique ID and the address of the field where to set the next mark. Wikipedia has that table in another format.

表是这样的:X先走,然后O. $ b $宽x把他的X到9细胞之一。当O都,现在有9种可能的电路板布局,这取决于电池具有X:

The table works like this: X goes first, then O. X puts his X into one of the 9 cells. When O goes, there are now 9 possible Board Layouts, depending on which Cell has the X:

 X  |    |
----+----+----
    |    |
----+----+----
    |    |

如果你看一下在澳的地图,也有这9大网格,和一个在左上角在左上角点的X,所以这是要使用的一个。 。将O中东

If you look at the map of O, there are 9 big grids in it, and the one in the top left has X in the top left spot, so that is the one to use. Place O in the Middle.

现在当X又来了,它需要找到这款主板的布局:

Now when X goes again, it needs to find this board layout:

 X  |    |
----+----+----
    | O  |
----+----+----
    |    |

您会在中间找到。红色是放在哪里的X XKCD图像,并显示你把它放在右下:

You will find this in the middle. Red is where to put the X in the XKCD image, and that shows you put it in the lower right:

 X  |    |
----+----+----
    | O  |
----+----+----
    |    | X 

现在,澳又来了,看起来对上述电路板布局,这是在右下角的小电网在上面留下的大电网。 O需求被放置在底部中间:

Now, O goes again and looks for the above board layout, which is in the bottom right small grid in the top left big grid. O needs to be placed into the middle bottom:

 X  |    |
----+----+----
    | O  |
----+----+----
    | O  | X 



等等。该图是位很难在第一次阅读(点击它放大),因为它的嵌套,而是说:你创建一个具有各自独特的电路板布局和信息在哪里放置一个标记查找表

And so forth. The diagram is a bit hard to read at first (click on it to enlarge it) as it's nested, but as said: You create a Lookup table that has each unique board layout and information where to put the next mark.

这虽然创建了一个完美的对手:计算机永远不会失去。如何让他更多的人则是微调(例如,随机丢弃的选择和放置标记以随机电池)

This creates a perfect opponent though: The computer will never ever lose. How to make him more human is then fine-tuning (e.g., randomly discard the choice and place the mark in a random cell)

这篇关于在井字棋人工智能使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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