minimax

TicTacToe minimax algorithm returns unexpected results in 4x4 games

a 夏天 提交于 2019-12-08 21:17:30
问题 In my method newminimax499 I have a minimax algorithm that utilizes memoization and alpha beta pruning. The method works normally for 3x3 games, however when I play 4x4 games I get strange, unexpected position choices for the computer. He still never loses, but he doesn't seem to be playing to win. To illustrate the problem here is a scenario from 2 games in 3x3 and 4x4. First here is a scenario from a 3x3 game where the player is X and makes the first move: This isn't bad, in fact it's what

Haskell Recursive Minimax Tree

跟風遠走 提交于 2019-12-06 11:01:04
I'm trying to write a Tic Tac Toe program in Haskell, using the minimax algorithm. I constructed my own "Rose a" data type as follows: data Rose a = a :> [Rose a] This is the data type in which I want to 'store' my minimax tree. I understand how the minimax algorithm works, but can't seem to implement it in a recursive function. minimax :: Player -> Rose Board -> Rose Int minimax p (r :> []) | hasWinner r == Just p = 1 :> [] | hasWinner r == Just (nextPlayer p) = (-1) :> [] | otherwise = 0 :> [] minimax p (r :> rs) = maximum(map root xs) :> xs where xs = map (minimax' (nextPlayer p)) rs

Minimax algorithm doesn't return best move

纵饮孤独 提交于 2019-12-06 10:19:07
I'm writing a Othello engine using minimax with alpha-beta pruning. It's working ok, but i found the following problem: When the algorithm finds that a position is lost, it returns -INFINITY as expected, but in this case i'm not able to track the 'best' move...the position is already lost, but it should return a valid move anyway (preferably a move that survives longer, as the good chess engines does). Here is the code: private float minimax(OthelloBoard board, OthelloMove best, float alpha, float beta, int depth) { OthelloMove garbage = new OthelloMove(); int currentPlayer = board

Tic-Tac-Toe: How to populate decision tree?

本小妞迷上赌 提交于 2019-12-06 08:20:00
I'm making a Tic-Tac-Toe program. I plan to use minimax with it. I made a tree with space for all possible game sequences and I'm looking for a way to populate it. I currently have this type: typedef struct name { char grid [3] [3]; struct name * child [9]; } node; and I'm looking for a way to fill grid just like it's shown here . How would I go filling the grid to make sure that all possible combinations are there? My plan is to have the game recognize every move player can take and then decide what steps to take in order to win (I still need to figure out the decision part, but I'm holding

Minimax algorithm for Tic Tac Toe Python

放肆的年华 提交于 2019-12-06 07:55:18
问题 I kind of understand how the minimax algorithm works for Tic Tac Toe python but I have no idea how to actually code it in Python... this is what I have so far: from copy import deepcopy class TicTacToeBrain : def __init__(self, player = "x") : self._squares = {} self._copySquares = {} self._winningCombos = ( [0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]) def createBoard(self) : for i in range(9) : self._squares[i] = None print(self._squares) def

How to get actual move rather than move value from mini max algorithm

最后都变了- 提交于 2019-12-06 07:14:45
I am currently writing a minimax algorithm with alpha beta pruning for Chess. From all the examples I have seen, minimax algorithm will return an int value that represents that best score or board state that will result from the best move. My question is how can we return the best move that is associated with the score return value? For example, my alphabeta() in pseudo below ... public int alphabeta(int depth, Board b, int alpha, int beta, boolean maxPlayer) { if(depth == 0) return evaluateBoard(b); if(maxPlayer) { for(each of max player's moves) { // make move on a tempBoard int eval =

Converting Minimax to Negamax (python)

[亡魂溺海] 提交于 2019-12-06 06:31:04
I'm making an Othello player, and implemented a minimax algorithm with alpha-beta pruning. Then I did a bunch of research on the best ones online and keep hearing about a "negamax" algorithm that they all use. It seems like most people think negamax is faster than minimax (i think because it doesn't switch between min and max player?), so I'd like to turn my minimax algorithm into negamax if that's not too difficult. I was wondering if people had any insight on how much faster using negamax is, and any tips or code on how to turn my minimax code into a negamax algorithm that'd be appreciated!

Minimax Algorithm Explanation

橙三吉。 提交于 2019-12-06 06:01:15
问题 I'm looking at this pseudocode for the Minimax algorithm: Function Minimax-Decision(state) returns an action ;inputs: state (current game state) ;'E' means element of, 'a' is the action return a E Actions(state) maximizing Min-Value(Result(a, state)) Function Max-Value(state) returns a utility value if Terminal-Test(state) then return Utility(state) v <-- -infinity for a, s in Successors(state) do v <-- Max(v, Min-Value(s)) return v Function Min-Value(state) returns a utility value if

Minimax/ Alpha beta pruning Move Ordering?

青春壹個敷衍的年華 提交于 2019-12-06 00:11:03
I've read (for example, http://radagast.se/othello/Help/order.html ) that searching on the best moves at each level first (which can be found using iterative deepening) makes the search go much faster. How would one go about searching on the best moves possible without using too much additional memory and cpu time? There are basically two strategies: Static move ordering Dynamic move ordering Dynamic move ordering uses information from previous searches, either because you transpose into the same position again, or you have already reached the position in a previous less thorough search. That

Minimax algorithm for Tic Tac Toe Python

你。 提交于 2019-12-04 12:12:25
I kind of understand how the minimax algorithm works for Tic Tac Toe python but I have no idea how to actually code it in Python... this is what I have so far: from copy import deepcopy class TicTacToeBrain : def __init__(self, player = "x") : self._squares = {} self._copySquares = {} self._winningCombos = ( [0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]) def createBoard(self) : for i in range(9) : self._squares[i] = None print(self._squares) def showBoard(self) : print(self._squares[0], self._squares[1], self._squares[2]) print(self._squares[3], self.