如何在java中评价四子棋游戏的情况
我正在尝试为“四人”游戏编写一个简单的人工智能。 基本的游戏原理已经完成,所以我可以扔进不同颜色的硬币,它们相互堆叠并填充一个二维数组等等。 到目前为止,该方法是这样的:
public int insert(int x, int color) //0 = empty, 1=player1 2=player2"
X 是水平坐标,因为 y 坐标由数组中已有的石头数量确定,我认为这个想法很明显。
现在的问题是我必须对特定的游戏情况进行评分,因此找出在特定情况下我可以得到多少个新的对、三胞胎和可能的连续 4 个,然后为每种情况赋予一个特定的值。 有了这些值,我可以设置一个“游戏树”,然后决定下一步最好的举动(稍后实施 Alpha-Beta-Pruning)。 我当前的问题是我想不出一种有效的方法来在 java 方法中实现当前游戏情况的评级。
任何想法将不胜感激!
I am trying to write a simple AI for a "Get four" game.
The basic game principles are done, so I can throw in coins of different color, and they stack on each other and fill a 2D Array and so on and so forth.
until now this is what the method looks like:
public int insert(int x, int color) //0 = empty, 1=player1 2=player2"
X is the horizontal coordinate, as the y coordinate is determined by how many stones are in the array already, I think the idea is obvious.
Now the problem is I have to rate specific game situations, so find how many new pairs, triplets and possible 4 in a row I can get in a specific situation to then give each situation a specific value. With these values I can setup a "Game tree" to then decide which move would be best next (later on implementing Alpha-Beta-Pruning).
My current problem is that I can't think of an efficient way to implement a rating of the current game situation in a java method.
Any ideas would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我猜这是一个家庭作业,你的意思是你想编写评估函数但不知道要使用什么技巧?
这个游戏的英文名为“Connect 4”,所以你可以google一下
“连接4个评估函数”。
你可以找到足够多的人讨论启发法。
请不要复制实际的源代码,这是一个重要的练习:)
I'm guessing that this is a homework assignment, and that you mean you want to write the evaluation function and don't know what tricks to use?
The game is called "Connect 4" in English, so you can google for
"connect 4 evaluation function".
You can find enough people discussion heuristics.
Please don't copy an actual source code, it's an important exercise :)
Connect 4 的搜索空间并不是大得不可思议。 对于一个简单的实现,尽管需要一段时间才能运行(可能几十分钟),但仍会进行极小极大搜索,直到有人获胜或游戏结束。 为一名玩家或另一名玩家获胜分配 +1 或 -1,为平局分配 0。
The search space for Connect 4 isn't impossibly large. For a simple implementation, albeit one that'll take a while to run (perhaps tens of minutes) do a minimax search until someone wins, or the game ends. Assign +1 or -1 for a win for one player or the other, and 0 for a draw.
胡说。 搜索空间巨大。 如果您想这样做,则需要使用预定义的表。
bollocks. search space is huge. you need to use a predefined table if you want to do that.