Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7604167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:50:28+00:00 2026-05-30T23:50:28+00:00

I am currently trying to make a good AI for Othello, and have done

  • 0

I am currently trying to make a good AI for Othello, and have done so using the Minimax algorithm. However, when I tried to make a deeper search using alpha-beta pruning, it seemed like the algorithm was playing terribly. I checked it with other sources like Wiki and Berkely.edu , and I think I have implemented it correctly, but I still can’t find the problem.

def alphabeta(board, player, a, b, lev):
        h = heur(board, player)
        if lev == 0:
                return h, None
        poss = get_legal_moves(board, player)
        if len(poss) == 0:
                return h, None
        move = 0
        for x in poss:
                cpboard = board[:]
                cpboard[x] = player
                bracket(cpboard, player, x)
                a1, q = alphabeta(cpboard, opponent_color(player), a, b, lev-1)
                if player is me:
                        if a1 > a:
                                a, move = a1, x
                else:
                        if a1 < b:
                                b, move = a1, x
                if b <= a:
                        break
        if player is me:
                return a, move
        else:
                return b, move
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:50:29+00:00Added an answer on May 30, 2026 at 11:50 pm

    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.

    Did you call the recursion with the alpha and beta values switched?
    Mine works like this (Java 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) && (currentPlayer == OthelloBoard.BLACK))                    
            return INFINITY;        
        if ((state == OthelloBoard.STATE_WHITE_WINS) && (currentPlayer == OthelloBoard.WHITE))
            return INFINITY;
        if ((state == OthelloBoard.STATE_BLACK_WINS) && (currentPlayer == OthelloBoard.WHITE))
            return -INFINITY;
        if ((state == OthelloBoard.STATE_WHITE_WINS) && (currentPlayer == OthelloBoard.BLACK))
            return -INFINITY;
    
        if (depth == maxDepth)
            return OthelloHeuristics.eval(currentPlayer, board);
    
        ArrayList<OthelloMove> moves = board.getAllMoves(currentPlayer);
    
        for (OthelloMove mv : moves)
        {            
            board.makeMove(mv);
            alpha = - minimax(board, garbage, -beta, -alpha, depth + 1);
            board.undoMove(mv);
    
            if (beta <= alpha)
                return alpha;
            if (alpha > bestResult)
            {                
                best.setFlipSquares(mv.getFlipSquares());
                best.setIdx(mv.getIdx());        
                best.setPlayer(mv.getPlayer());
                bestResult = alpha;
            }
        }
    
         return bestResult;
    }
    

    The call is like:

     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);
    

    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.

    Hope it helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so I'm currently trying to make an OpenID provider. I've tried using two Java
I'm currently trying to find good way to make calls to WCF services in
I am currently learning jsp/servlet, and trying to make an online bookstore. Using jquery,
I'm currently trying to make a set of conversion functions which, through one call,
I'm currently trying to make an orientation calculator in java and I'm having a
I am currently trying to make a sectioned table like this: Section 1: Entry
I am currently trying to make a dropbox-esque application from a tutorial and I
I am currently trying to make an application that allows the user to create
i'm currently trying to make a asp.net mvc3 app. in the sample application which
The graph I'm currently trying to make falls a little between two stools. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.