minimax

Is there something wrong with my quiescence search?

断了今生、忘了曾经 提交于 2021-02-10 20:14:23
问题 I keep getting weird behavior in my negamax-based AI when I try to implement QuiesenceSearch. I based it on the pseudo-code from here: int Quiesce( int alpha, int beta ) { int stand_pat = Evaluate(); if( stand_pat >= beta ) return beta; if( alpha < stand_pat ) alpha = stand_pat; until( every_capture_has_been_examined ) { MakeCapture(); score = -Quiesce( -beta, -alpha ); TakeBackMove(); if( score >= beta ) return beta; if( score > alpha ) alpha = score; } return alpha; } And this is my code:

Python minimax for tictactoe

拈花ヽ惹草 提交于 2021-01-28 04:46:59
问题 After completely failing the minimax implementation for tic tac toe, I fail to see what's wrong. Right now, my AI just goes around in a circle... import collections class InvalidLocationError(Exception): pass import copy class Board(object): def __init__(self, board=None): if board is None: self.clear() else: self._board = board[:] def place(self, i, row, column): if not ((0 <= row <= 2) and (0 <= column <= 2)): raise InvalidLocationError("Invalid Location.") if self._board[row][column]:

How to implement a transposition table for connect 4?

帅比萌擦擦* 提交于 2021-01-27 08:00:07
问题 I'm making a connect 4 AI in python, and I'm using minimax with iterative deepening and alpha beta pruning for this. For greater depths it's still quite slow, so I wanted to implement a transposition table. After reading up on it I think i get the general idea but i haven't been able to quite make it work. Here's part of my code: (the maximizing part of the minimax): if(isMaximizing): maxEval = -99999999999 bestMove = None # cache.get(hash(board)) Here's where i'd check to see if the hash is

How to implement a transposition table for connect 4?

寵の児 提交于 2021-01-27 07:56:04
问题 I'm making a connect 4 AI in python, and I'm using minimax with iterative deepening and alpha beta pruning for this. For greater depths it's still quite slow, so I wanted to implement a transposition table. After reading up on it I think i get the general idea but i haven't been able to quite make it work. Here's part of my code: (the maximizing part of the minimax): if(isMaximizing): maxEval = -99999999999 bestMove = None # cache.get(hash(board)) Here's where i'd check to see if the hash is

Solving TicTacToe with minimax algorithm in Javascript

空扰寡人 提交于 2020-12-27 06:44:12
问题 let _board = [[null, null, null], [null, null, null], [null, null, null]]; let _flag = true; let _AIrowIndex = null; let _AIcellIndex = null; const _wrapper = document.querySelector(".wrapper"); const _changeTurn = function () { if (_flag == true) { _flag = false; return playerOne.getSign(); } else { _flag = true; return playerTwo.getSign(); } }; const _displayTurn = function () { let turn = document.querySelector(".playerInfo__turn") if (_flag == true) { turn.innerHTML = `${playerOne.getName

Game AI works powerfully on one side and becomes dumb on the other in Tic-Tac-Toe

笑着哭i 提交于 2020-06-23 18:06:08
问题 I am trying to make a Tic-Tac-Toe game in Python using PyGame and the MiniMax algorithm. The AI plays really well when given the first chance (playing as 'X'), but becomes dumb enough to help the user win when not given the first chance (playing as 'O'). I think I know what the problem is but changing it is messing with the whole program and is not going by the given docstrings. I've made two python files - one for the GUI (runner.py) and the other for the logic behind the game and the AI

Game AI works powerfully on one side and becomes dumb on the other in Tic-Tac-Toe

跟風遠走 提交于 2020-06-23 18:05:29
问题 I am trying to make a Tic-Tac-Toe game in Python using PyGame and the MiniMax algorithm. The AI plays really well when given the first chance (playing as 'X'), but becomes dumb enough to help the user win when not given the first chance (playing as 'O'). I think I know what the problem is but changing it is messing with the whole program and is not going by the given docstrings. I've made two python files - one for the GUI (runner.py) and the other for the logic behind the game and the AI

TicTacToe and Minimax

眉间皱痕 提交于 2020-06-01 06:08:00
问题 I am a young programmer that is learning python and struggling to implement an AI (using minimax) to play TicTacToe. I started watching a tutorial online, but the tutorial was on JavaScript and thus couldn't solve my problem. I also had a look at this question ( Python minimax for tictactoe ), but it did not have any answers and the implementation was considerably different from mine. EDIT: the code you will find below is an edit suggested by one of the answers (@water_ghosts). EDIT #2: I

TicTacToe and Minimax

六眼飞鱼酱① 提交于 2020-06-01 06:04:55
问题 I am a young programmer that is learning python and struggling to implement an AI (using minimax) to play TicTacToe. I started watching a tutorial online, but the tutorial was on JavaScript and thus couldn't solve my problem. I also had a look at this question ( Python minimax for tictactoe ), but it did not have any answers and the implementation was considerably different from mine. EDIT: the code you will find below is an edit suggested by one of the answers (@water_ghosts). EDIT #2: I

How can I programme a minimax algorithm for nim game python?

泄露秘密 提交于 2020-01-06 06:50:00
问题 I tried to programme a minimax algorithm in python. But it is so confusing. I am new to recursion functions. My mind structure has some error at somewhere but I could not solve it. My minimax tree returns with '-100' that must be 100 to achieve true answer. If anything is missing or not clear, please just let me know. Thank you def startposition(): return 2, 'max' def terminalstate(state): if state == (0, 'min') or state == (0, 'max'): return True else: return False def minimax(state): if