MinMax Algorithm for Tic Tac Toe

I'm trying to do the MinMax for the tic tac toe (Always computer win) but I can't get it to work. All the successors simply return 0 (draw) as score and so the computer always chooses to move in the natural direction of the matrix. PS: Matrix (class) is the board where they play, that contains an array of 9 positions. | X | O | X | O | ... | like this. Global Variable that ha

Tic Tac Toe的MinMax算法

我正在尝试为井字游戏(总是赢得计算机)做MinMax,但我无法让它工作。 所有的后继者只是返回0(draw)作为分数,因此计算机总是选择在矩阵的自然方向上移动。 PS:矩阵(类)是他们玩的棋盘,包含9个阵位。 | X | O | X | O | ... | 喜欢这个。 处理Tic Tac Toe板的全局变量称为Main,是Matrix的一个实例。 public void minMax(Matrix p) { Matrix bestvalue = maxValue(p); print(bestvalue); System.out.p

Finding the best move using MinMax with Alpha

I'm working on an AI for a game and I want to use the MinMax algorithm with the Alpha-Beta pruning. I have a rough idea on how it works but I'm still not able to write the code from scratch, so I've spend the last two days looking for some kind of pseudocode online. My problem is that every pseudocode I've found online seems to be based on finding the value for the best move w

使用MinMax与Alpha一起寻找最佳举措

我正在为一款游戏开发人工智能,并且我想使用Alpha-Beta修剪的MinMax算法。 我对它是如何工作有一个粗略的想法,但我仍然无法从头开始编写代码,所以我花了最近两天在线寻找某种伪代码。 我的问题是,我在网上找到的每一个伪代码似乎都是基于找到最佳移动的价值,而我需要返回最佳移动本身而不是数字。 我目前的代码是基于这个伪代码(源代码) minimax(level, player, alpha, beta){ // player may be "computer" or "op

MinMax algorithm not working properly

I am working on a chess engine and now trying to implement Minimax algorithm. At the moment I have put together a mimimax code but it's not really working properly. I beat the engine within minutes given that I'm not a good chess player. I would like someone to kindly look into my minimax code and tell me what I've written correctly. Thanks in advance. Here is my code: privat

MinMax算法不能正常工作

我正在研究一个国际象棋引擎,现在正在努力实现Minimax算法。 目前我已经编写了一个mimimax代码,但它并不能正常工作。 考虑到我不是一个好的棋手,我几分钟之内就击败了引擎。 我希望有人善意地研究我的极小极大码,并告诉我我写的是正确的。 提前致谢。 这是我的代码: private int MiniMax(Game game, int depth){ return Max(depth); } private int Max(int depth){ if (depth <= 0 || this

Minimax Algorithm Tic Tac Toe Intermediate State

I have been trying to understand the working of the minimax algorithm at the intermediate states of a game of tic tac toe. But I am unable to do so. I understand that the min max algorithm returns the best possible state for the player at every step. If the states were like this At the final stages of the game, it is easier to understand that the state that leads to an advantage or maximum p

Minimax算法井字中间状态

我一直在尝试理解在游戏的井字游戏的中间状态下运行minimax算法。 但我无法这样做。 我明白min max算法会在每一步中为玩家返回最佳状态。 如果国家是这样的 在游戏的最后阶段,更容易理解的是,导致玩家获得优势或最大分数的状态是最佳配置。 在这个例子中,我们可以看到叶子上得分'1'的状态是最好的状态。 但是在中间阶段或游戏开始时会发生什么。 假设我们有3个位置开始,或者玩家可以通过玩某个位置来进入这

generating game tree

I try to write a MinMax program in Java for connect-four game, but this program should also be applicable to other games. But, I encountered a problem, which I cannot pass for few days. The values for nodes are not set properly. I am sharing my piece of code which is responsible for generating a tree. Maybe you will notice where I made a mistake. If anyone could help me with this, I will b

生成游戏树

我尝试用Java写一个MinMax程序来连接四个游戏,但这个程序也应该适用于其他游戏。 但是,我遇到了一个问题,我几天无法通过。 节点的值设置不正确。 我分享我负责生成树的代码片段。 也许你会注意到我犯了一个错误。 如果有人能帮助我,我会很高兴。 public Node generateTree(Board board, int depth) { Node rootNode = new Node(board); generateSubtree(rootNode, depth); minMax(rootNode, depth);

Adding Alpha Beta pruning to Negamax in Java

I am making a chess game in Java and (I think) have successfully implemented Negamax for the AI player. I am having some trouble adding alpha beta pruning to this to improve the algorithm. I have tried following tutorials and example code but just can't get my head around how it works. Below is the code I currently have to get the best move: private Move getBestMove() { System.out.pr

在Java中添加Alpha Beta修剪到Negamax

我正在Java中进行国际象棋游戏,并且(我认为)已经成功实现了AI玩家的Negamax。 我在添加alpha beta修剪时遇到了一些麻烦,以改进算法。 我已经尝试了下面的教程和示例代码,但仅仅是无法让我的头脑发现它的工作原理。 以下是我目前必须采取的最佳做法: private Move getBestMove() { System.out.println("Getting best move"); System.out.println("Thinking..."); List<Move> validMoves = generateM

Alpha beta pruning for minimax implementation

I'm trying to create an AI player for a game using the minimax algorithm with alpha-beta pruning. I'm having some trouble trying to implement it properly. I have 2 functions to work with, one to evaluate the current state of my board for a given player (that returns some score) getBoardScore, and another to return all the possible board states created by every possible move (from a give

阿尔法贝塔修剪minimax实施

我正在尝试使用alpha-beta修剪的minimax算法为游戏创建一个AI玩家。 我尝试正确实施它遇到了一些麻烦。 我有两个功能可供使用,一个用于评估给定玩家的当前棋盘状态(返回一些分数)getBoardScore,另一个用于返回所有可能的棋盘状态(从给定棋盘状态一个给定的玩家)getPossibleBoards。 我的AI通过首先调用alphaBeta来传递当前棋盘状态。 然后它从alphaBeta函数递归修改的变量'bestBoard'中设置一个新的棋盘状态

Concurrently search a game tree using minimax and AB pruning. Is that possible?

I'm going be competing in a board game AI competition at my school and am trying to come up with some ideas for concurrency to gain an edge. I will most likely be at a disadvantage because I will be implementing it in java and I understand c or c++ would be much faster. It doesn't seem like you could just split the game tree in half because of the move ordering which should leave the b

同时使用minimax和AB修剪搜索游戏树。 那可能吗?

我将在我的学校参加一场棋盘游戏AI竞赛,并试图提出一些想要获得优势的并发思想。 我很可能会处于劣势,因为我将在java中实现它,并且我明白c或c ++会更快。 看起来你不可能把游戏树分成两半,因为移动顺序应该使得最好的移动首先出现,而且看起来很难或者甚至不可能在给定的深度传达当前的alpha / beta 。 我将要使用换位表以及需要同步的换位表。 除了搜索,是否有第二个线程可以做的事情可以帮助搜索或提供某种类型的速

Implementing alpha beta pruning in a TicTacToe minimax algorithm

In my method newminimax49 I have a minimax algorithm that utilizes memoization and other general improvements which were suggested to me in this post. The method uses a simple heuristic board evaluation function. My question is basically regarding alpha beta pruning, namely whether or not my minimax method utilizes alpha beta pruning. To my knowledge I believe that it does, however what I'

在TicTacToe minimax算法中实现alpha beta修剪

在我的方法newminimax49我有一个minimax算法,利用memoization和其他一般的改进,这在这篇文章中建议给我。 该方法使用简单的启发式板评估函数。 我的问题基本上是关于alpha beta修剪,即我的minimax方法是否使用alpha beta修剪。 据我所知,我相信它确实如此,但是我用来实现它的过程似乎太简单而不真实。 此外,其他人建议我使用alpha beta修剪,正如我所说,我曾认为我的minimax方法已经做了,这使我相信我在这里做的是别

Tree Implementation in MinMax with Alpha

I want to implement an AI (Artificial Intelligence) for a checkers-like game I have written the follow methods: -the method public List<Move> allMoves(){ ... } that returns me the list of all valid moves sorted by weight, where the weight is calculated according the kind of moves and the position -the method public int apply(Move m){ ... } to apply the moves t

用MinMax实现Alpha

我想为类似跳棋的游戏实施AI(人工智能) 我写了以下方法: -方法 public List<Move> allMoves(){ ... } 它返回按重量排序的所有有效移动的列表,其中权重根据移动的种类和位置计算 -方法 public int apply(Move m){ ... } 如果某些棋子已经被杀死,则将棋子应用于棋盘并返回1 -方法 public void undo(){ ... } 恢复董事会以前的状态。 这是一个零和游戏,所以AI应该最大化玩家