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 7593611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:12:47+00:00 2026-05-30T21:12:47+00:00

I have a problem with implementing a simple NegaMax in my chess programm. According

  • 0

I have a problem with implementing a simple NegaMax in my chess programm.

According to several websites negamax should look as follows in my code:

int Position::negaMax(int curr_depth, int depth) {
    cd = curr_depth-1;
    if (curr_depth==depth) return evaluate();

    int max = -500000;

    calc_moves(true);
    doBackup(cd);
    for (int i=0;i<mvSize[cd];i++) {
        move_figure(mvD[cd][i][0],mvD[cd][i][1],mvD[cd][i][2],mvI[cd][i][0],mvI[cd][i][1]);    
        int score = -negaMax(curr_depth+1,depth);
        cd--; undoMove(cd);

        if (curr_depth==1)
            cout << "Move: " << getMoveString(i) << ", Score: " << score << endl;        

        if (score>max)
            max=score;
   }
   return max;
}

But with this code I get this output:

Move: a2a3, Score: 0
Move: a2a4, Score: 0
Move: b2b3, Score: 0
Move: b2b4, Score: 0
Move: c2c3, Score: 0
Move: c2c4, Score: 0
Move: d2d3, Score: 0
Move: d2d4, Score: 0
Move: e2e3, Score: 0
Move: e2e4, Score: 0
Move: f2f3, Score: 0
Move: f2f4, Score: 0
Move: g2g3, Score: 0
Move: g2g4, Score: 0
Move: h2h3, Score: 0
Move: h2h4, Score: 0
Move: b1a3, Score: 0
Move: b1c3, Score: 0
Move: g1h3, Score: 0
Move: g1f3, Score: 0
score: 0

That can’t be right, if I negaMax for ply3 from the starting position.

If I remove the minus sign in front of the recursive function call, I get a more better result. But in my opinion that can’t be right, because without the minus sign in the above code, I only maximize the score for one player, but not for the both.

Move: a2a3, Score: 0
Move: a2a4, Score: 30
Move: b2b3, Score: 0
Move: b2b4, Score: 30
Move: c2c3, Score: 0
Move: c2c4, Score: 30
Move: d2d3, Score: 295
Move: d2d4, Score: 295
Move: e2e3, Score: 295
Move: e2e4, Score: 295
Move: f2f3, Score: 0
Move: f2f4, Score: 30
Move: g2g3, Score: 0
Move: g2g4, Score: 30
Move: h2h3, Score: 0
Move: h2h4, Score: 30
Move: b1a3, Score: 30
Move: b1c3, Score: 30
Move: g1h3, Score: 30
Move: g1f3, Score: 30
score: 295

I’ve tried to implement different versions of MinMax, NegaMax and AlphaBeta. But I always get a score of 0. I would be very thankful for any hints.

  • 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-30T21:12:48+00:00Added an answer on May 30, 2026 at 9:12 pm

    The actual skeleton of negamax appears to be implemented correctly. (However, I’m more used to seeing a single depth variable passed to the recursive function that is subtracted each ply – and returns the evaluated score when it equals 0). But it is hard to diagnose your problem as an outsider due to the large dependency on other code.

    Rather than fishing for you, I feel it would be better to teach you how to fish. I would suggest spending some time to build a routine that outputs the tree structure and cumulative score visually somehow. It seems as though you already have the building blocks of such a thing, too. It might be time consuming to do this initially, but in the long run will help greatly with debugging – and believe me, with a chess engine, trawling through this tree will be an unfortunately frequent reality, especially when you implement more obscure moves like en-passant – these can cause all sorts of troubles within the tree (I’ve been there).

    Try to output something like this:

    <move-white ---->
        <move-black ----><eval score>
        <move-black ----><eval score>
        <move-black ----><eval score>
        <best black score>
    <move-white ---->
        <move-black ----><eval score>
        <move-black ----><eval score>
        <move-black ----><eval score>
        <move-black ----><eval score>
        <move-black ----><eval score>
        <move-black ----><eval score>
        <best black score>
    <move-white ---->
        <move-black ----><eval score>
        <move-black ----><eval score>
        <best black score>
    <best white score>
    

    …where ---- denotes the move.

    Obviously this is going to be much larger and deeper, but at least you can see what is happening in a more human friendly way. Hopefully it will help you with other issues in the long run, too. Setting up a good debugging system with a chess engine is vital, as you will probably find.

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

Sidebar

Related Questions

I have the weirdest problem. I am implementing a simple gallery with a use
We have a strange problem when implementing sessions with ColdFusion in IE6. After login
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
The problem is quite simple, I have a method that returns a list. I
First of all I have a simple ListView . Implementing the BaseAdapter and utilizing
Very simple problem but I'm making no progress so I thought I should ask...
I am implementing a very simple file database. I have 2 basic operations: void
in my Silverlight 4 project, I have a simple class implementing the interface like:
i am currently implementing a simple ray tracer in c++. I have a class
I have a problem implementing the following in python: I have a nxn matrix

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.