Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

322
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda