Problem in C with NegaMax / Alpha-Beta (Connect 4)

Started by
58 comments, last by Jaap85 11 years, 11 months ago
By the way, we discussed the negation of the return value of the initial call to the search function in this forum a while back: http://www.gamedev.net/topic/586896-starting-call-to-negamax/
Advertisement

  • The initial call to IA_NegaMaxAlphaBeta should have "joueur^1" and -scoreCoup as beta, instead of INFINI.



You mean -scoreMeilleur no ?




  • Also, why are you not passing x and y to IA_NegaMaxAlphaBeta as you do in the recursive call? Fix that too.



I do. "colonne" is x and "emplacement" is y.




By the way, we discussed the negation of the return value of the initial call to the search function in this forum a while back: http://www.gamedev.n...all-to-negamax/


Yep i've read it. But every connect 4 i saw work with a positive initial call for negamax, so what's the best solution ?

[quote name='alvaro' timestamp='1337951767' post='4943224']

  • The initial call to IA_NegaMaxAlphaBeta should have "joueur^1" and -scoreCoup as beta, instead of INFINI.



You mean -scoreMeilleur no ?[/quote]

Yes, I do. Sorry about that.


  • Also, why are you not passing x and y to IA_NegaMaxAlphaBeta as you do in the recursive call? Fix that too.



I do. "colonne" is x and "emplacement" is y.
[/quote]

I am afraid that is incorrect. "colonne" and "emplacement" are probably "x" and "y" of the previous move. At least in the code you have provided, there is nothing that sets colonne and emplacement to x and y.


By the way, we discussed the negation of the return value of the initial call to the search function in this forum a while back: http://www.gamedev.n...all-to-negamax/


Yep i've read it. But every connect 4 i saw work with a positive initial call for negamax, so what's the best solution ?
[/quote]

It's not a matter of what option is best. First of all, your program needs to be correct.

You either make a single call to negamax for the root (but then you have to do something to extract the best move) or you write a function that searches the root and remembers the best move. If you use the first option, you don't negate the return value (you don't do much with the value, actually). If you use the second option -as you have-, then you negate the return value.

Yes, I do. Sorry about that.


It doesn't matter, don't be sorry, i'm glag you help me.



I am afraid that is incorrect. "colonne" and "emplacement" are probably "x" and "y" of the previous move. At least in the code you have provided, there is nothing that sets colonne and emplacement to x and y.


Oh i see what you mean, sorry. Actually, my initial call is in a function, which is called after a player move.
So "colonne" contains the last column played by the player, and "emplacement" the line in the colonne.

Oh i see what you mean, sorry. Actually, my initial call is in a function, which is called after a player move.
So "colonne" contains the last column played by the player, and "emplacement" the line in the colonne.


I am afraid something still hasn't clicked in your head and that's why you are having trouble with this. The coordinates that you are passing to your search function are the location of the last move, and when you are calling it in the initial call, the last move performed is the one described in the `InsererJeton' call of the previous line. So that's what you should be passing.

Does that make sense?
Oops yes, you're totally right ! My bad, sorry !

So it would be logically like that:

y = InsererJeton(grille, emplacements, x, joueur);
scoreCoup = -IA_NegaMaxAlphaBeta(MAXPROFONDEUR, -INFINI, -scoreMeilleur, grille, emplacements, x, y, joueur^1);


But it doens't work. The only code that works is this one (and it's not logic):

y = InsererJeton(grille, emplacements, x, joueur^1);
scoreCoup = IA_NegaMaxAlphaBeta(MAXPROFONDEUR, -INFINI, INFINI, grille, emplacements, x, y, joueur);


Have you seen something similar to this before ?
I tried a lot to debug but can't find the crap.
What doesn't work?What happens when you do what we both agree is the right thing to do?

y = InsererJeton(grille, emplacements, x, joueur);
scoreCoup = -IA_NegaMaxAlphaBeta(MAXPROFONDEUR, -INFINI, -scoreMeilleur, grille, emplacements, x, y, joueur^1);


With that code, i get some negatives scores.
So the one who should be chosen won't be because the biggest value is the lower with minus.
You feel me ? I know it's not so clear laugh.png


Let's try an example:
I get -198 and -150 --> it should choose 198 (if it was positive) but the biggest here (because of minus sign) is 150.
No, I don't follow. I want to see a position and the wrong move being picked.
Ok let's do this step by step. The debug is with my initial call to negamax.

1) I'm the red one, and i play first in column 4.

2) AI plays in column 1

p41h.png

and here is the debug produced:

Test column 4
FREE column 4 / SCORE: -199
BEST column 4 (score -199)
Test column 3
FREE column 3 / SCORE: -198
BEST column 3 (score -198)
Test column 5
FREE column 5 / SCORE: -198
Test column 2
FREE column 2 / SCORE: -198
Test column 6
FREE column 6 / SCORE: -198
Test column 1
FREE column 1 / SCORE: -196
BEST column 1 (score -196)
Test column 7
FREE column 7 / SCORE: -196


As you can see, the best column to choose would have been column 4.
But all scores are negatives. So the biggest score (with no minus sign) becomes the lower score (with minus sign).
So it chooses column 1 (first column with lower value) because -198 < -196.

Is it clearer ?

And it continues like that for next steps.

This topic is closed to new replies.

Advertisement