Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your alpha-beta code is probably wrong. Be aware of what happens when a player 'pass the turn' (i.e. has no available moves), i had a tricky bug in my code, due to this. </p> <p>Did you call the recursion with the alpha and beta values switched? Mine works like this (Java code):</p> <pre><code>private float minimax(OthelloBoard board, OthelloMove best, float alpha, float beta, int depth) { float bestResult = -Float.MAX_VALUE; OthelloMove garbage = new OthelloMove(); int state = board.getState(); int currentPlayer = board.getCurrentPlayer(); if (state == OthelloBoard.STATE_DRAW) return 0.0f; if ((state == OthelloBoard.STATE_BLACK_WINS) &amp;&amp; (currentPlayer == OthelloBoard.BLACK)) return INFINITY; if ((state == OthelloBoard.STATE_WHITE_WINS) &amp;&amp; (currentPlayer == OthelloBoard.WHITE)) return INFINITY; if ((state == OthelloBoard.STATE_BLACK_WINS) &amp;&amp; (currentPlayer == OthelloBoard.WHITE)) return -INFINITY; if ((state == OthelloBoard.STATE_WHITE_WINS) &amp;&amp; (currentPlayer == OthelloBoard.BLACK)) return -INFINITY; if (depth == maxDepth) return OthelloHeuristics.eval(currentPlayer, board); ArrayList&lt;OthelloMove&gt; moves = board.getAllMoves(currentPlayer); for (OthelloMove mv : moves) { board.makeMove(mv); alpha = - minimax(board, garbage, -beta, -alpha, depth + 1); board.undoMove(mv); if (beta &lt;= alpha) return alpha; if (alpha &gt; bestResult) { best.setFlipSquares(mv.getFlipSquares()); best.setIdx(mv.getIdx()); best.setPlayer(mv.getPlayer()); bestResult = alpha; } } return bestResult; } </code></pre> <p>The call is like:</p> <pre><code> OthelloMove bestFound = new OthelloMove(); int maxDepth = 8; minimax(board, bestFound, -Float.MAX_VALUE, Float.MAX_VALUE, maxDepth); //Wait for Thread to finish board.makeMove(bestFound); </code></pre> <p>Edit: In case a player has no available moves, getAllMoves() return a 'dummy move', that doesn't change the board at all, just pass the turn.</p> <p>Hope it helps!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload