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

  • SEARCH
  • Home
  • 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 6941435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:53:07+00:00 2026-05-27T12:53:07+00:00

I was having a headache understanding why certain nodes on a lesson example were

  • 0

I was having a headache understanding why certain nodes on a lesson example were being printed as a result of alpha-beta pruning, so I implemented Peter Norvig’s version of alpha beta pruning in Java.

With a tree like this:

                     max
                  /    |     \
    min               min            min
  / / |              / | \          / | \
 3 12 8             2  3  9        14 1  8

The textbook says that the only terminal nodes that should be expanded are

3, 12, 8, 2, 14, 1

in that order.

My algorithm prints:

visited leaf with value 3
visited leaf with value 12
visited leaf with value 2
visited leaf with value 3
visited leaf with value 14
visited leaf with value 1
visited leaf with value 8
Root value 3

The root is the correct value for the minimax root. I’ve debugged for a couple of hours and can’t seem to find fault. Have I overlooked something or is the textbook incorrect?

package alphabeta;

import java.util.ArrayList;

class Node {

    boolean isMin;
    boolean isMax;
    boolean isTerminal;
    int value;
    int depth;
    ArrayList <Node> children = new ArrayList <Node>();

}
public class AlphaBeta {


    static Node alphaBetaSearch(Node state){

        state.value = max_value(state,-99999,99999);

        System.out.println(state.value);

    return null;
    } 


    static int max_value(Node state, int alpha, int beta){


        if (state.isTerminal){
            System.out.println("visited leaf with value " + state.value);
            return state.value;
        }

        state.value = -99999;

        for (Node a: state.children){

            state.value = Math.max(state.value , min_value(a, alpha, beta));
            if (state.value >= beta){

                return state.value;                
            }
            alpha = Math.max(alpha, state.value);
        }
        return state.value;
    }

    static int min_value(Node state, int alpha, int beta){


        if (state.isTerminal) 
            return state.value;

        state.value = 99999;

        for (Node a: state.children){

            state.value = Math.min(state.value, max_value(a, alpha, beta));
            if (state.value >= beta){

                return state.value;

            }
            beta = Math.min(beta, state.value);
        }
        return state.value;
    }


    public static void main(String[] args) {

        Node t1 = new Node();
//            t1.value = 4; 
            t1.value = 3;
            t1.depth =2;
            t1.isTerminal = true;

        Node t2 = new Node();
//             t2.value = 8;
             t2.value = 12;
             t2.depth=2;
             t2.isTerminal= true;

        Node t3 = new Node();
            // t3.value = 7;
             t3.value = 8;
             t3.depth=2;
             t3.isTerminal= true;

        Node min1 = new Node();
             min1.isTerminal=false;
             min1.depth=1;
             min1.children.add(t1);
             min1.children.add(t2);
             min1.children.add(t3);

        Node t4 = new Node();
//            t4.value = 5;
            t4.value = 2;
            t4.depth =2;
            t4.isTerminal = true;

        Node t5 = new Node();
             //t5.value = 2;
             t5.value =3;
             t5.depth=2;
             t5.isTerminal= true;

        Node t6 = new Node();
//             t6.value = 1;
             t6.value=9;
             t6.depth=2;
             t6.isTerminal= true;

        Node min2 = new Node();
             min2.isMin=true;
             min2.isTerminal=false;
             min2.depth=1;
             min2.children.add(t4);
             min2.children.add(t5);
             min2.children.add(t6);  


        Node t7 = new Node();
//             t7.value = 1; 
             t7.value=14;
             t7.depth =2;
             t7.isTerminal = true;

        Node t8 = new Node();
//             t8.value = 6;
             t8.value=1;
             t8.depth=2;
             t8.isTerminal= true;

        Node t9 = new Node();
//             t9.value = 0;
             t9.value=8;
             t9.depth=2;
             t9.isTerminal= true;

        Node min3 = new Node();
             min3.isMin=true;
             min3.isTerminal=false;
             min3.depth=1;
             min3.children.add(t7);
             min3.children.add(t8);
             min3.children.add(t9);

         Node max1 = new Node();
              max1.isMax=true;
              max1.isTerminal=false;
              max1.depth=0;
              max1.children.add(min1);
              max1.children.add(min2);
              max1.children.add(min3);



              alphaBetaSearch (max1);



    }
}
  • 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-27T12:53:08+00:00Added an answer on May 27, 2026 at 12:53 pm

    You have two lines:

    if (state.value >= beta){

    One of those lines should have alpha instead of beta.

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

Sidebar

Related Questions

I'm having a headache trying to figure out why vim isn't copying to a
I'm having a headache figuring how to retrieve the gwt Radio Buttons values in
I am having a real headache trying to set a node's local position to
Wow, I'm having a bit of a headache with Access 2007. I have two
I am having a real headache. I have written a small and simple menu
I'm having a lot of headache with the problem described in this topic title.
Having a headache with IE. I have an image (24x24) which I'd like to
I am really having a headache since the other day on how to fix
OK so having a real headache with this one and most of the day
I'm having some major headache trying to apply CSS3 transitions to a slideshow trough

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.