Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

323
Visualizações
Minimax heuristic vs. alpha-beta pruning and computation time

I am working on a minimax solver for tic-tac-toe on a 5x5 board. My first attempt had to be limited to a recursive depth of 7 to limit computation time to about 20 seconds on my laptop. I then implemented alpha-beta pruning as well as a function to sort moves prior to recursively scoring them according to a heuristic (basically sorting moves earlier that brought the player close to an unblocked 5-in-a-row, or blocked rows/columns/diagonals that the opponent was close to winning). These two changes dramatically reduced processing time, and I know worked as intended because the total number of moves evaluated by the algorithm also dropped significantly, indicating that pruning was taking place.

My question concerns my next step, was to implement a heuristic board evaluator to calculate a heuristic score for a board once I've reached the set limit on recursive depth (before this I simply returned a score of 0). This heuristic was similar to the move sorter, but different because it simply scored an entire board, without considering the latest move that produced the board.

My question is, even a well-designed heuristic board evaluator would not improve processing time/reduce the number of moves to evaluate, but rather should just help the algorithm to choose a better move, right?

Since it is only applied at the recursive depth limit, it wouldn't have an impact on alpha-beta pruning, nor would the heuristic score affect move sorting, since the sorting occurs before the recursive calls, and the heuristic scorer is only called in one of the recursive base cases? I just want to make sure I'm understanding what effect I should hope for if I design my heuristic evaluator well.

On that note, I'm really just guessing as to how to heuristically score a 5x5 tic-tac-toe board, by giving points for the number of Maximizer's pieces in a given win condition that includes no Minimizer pieces, and subtracting points for the reverse. My code for this is below, I would also appreciate any suggestions!

const heuristic = (board) => {
    let score = 0
    for (let i = 0; i < 25; i++) {
        if (board[0][i]) {
            abConditions[i].forEach(array => {
                if (board[0][i] === 'o') {
                    let oScore = 0
                    for (let j = 0; j < 4; j++) {
                        if (board[0][array[j]] === 'o' || board[0][array[j]] === null) {
                            oScore++
                        } else {
                            oScore = 0
                            break
                        }
                    }
                    score += oScore
                } else {
                    let xScore = 0
                    for (let j = 0; j < 4; j++) {
                        if (board[0][array[j]] === 'x' || board[0][array[j]] === null) {
                            xScore++
                        } else {
                            xScore = 0
                            break
                        }
                    }
                    score -= xScore
                }
            })
        }
    }
    return score
}

Just trust me that the abConditions array is properly used to check all the win conditions on a 5x5 board :)

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda