Advertisement

minimax with alpha beta pruning implementation stuck.

Started by October 08, 2012 07:21 PM
27 comments, last by alvaro 12 years, 1 month ago
@alvaro

...
EDIT: Wait, why are you passing a sign around?


Sign value is: +1 or -1 (it alternates between MAX = +1 and MIN = -1 teams).
It's not correct ?
What do you do with it? I don't see it in your code...

The whole point of NegaMax is that it makes all the nodes max nodes, with the resulting code being simpler.

EDIT: Oh, I see you are passing it to your evaluation function. One typically uses whose turn it is, which is part of the board class.
Advertisement
yes, that's correct.
thanks for all the help !
i really appreciate that.
Hello,
I'm sorry i keep coming back to this subject, but i have some issues wich i help you can give me an answer.
I have this EvalFunction :


[source lang="java"] public int evaluateBoard(int sign) // -1 = "computer" and +1 = "human"
{
int total = 0;

int computer_closedmills = this.checkMills(-1); // count how many closed mills AI has (3 tokens in a row/column).
int computer_openmills = this.checkFormers(-1); // count how many 2 in a row/column tokens AI has.
int computer_blockers = this.checkBlockers(-1); // count if one AI token -> blocks 2 player's tokens
int computer_tokensleft = this.checkTokens(-1); // count how many tokens AI has.
int computer_openspaces = this.checkOpenSpaces(-1); // count how many move possibilities AI has (in current board)


int player_closedmills = this.checkMills(1); // count how many mills "human" has
int player_openmills = this.checkFormers(1); // count how many 2 in a row/column "human" has.
int player_blockers = this.checkBlockers(1); // etc.
int player_tokensleft = this.checkTokens(1);
int player_openspaces = this.checkOpenSpaces(1);

// compute total score
total -= ((computer_closedmills * 20)+ (computer_openmills * 40) + (computer_blockers * 30) + (computer_tokensleft * 10) + (computer_openspaces*5));
total += ((player_closedmills * 20) + (player_openmills * 40) + (player_blockers * 30) + (player_tokensleft * 10) + (player_openspaces*5));

if(sign==-1) return total;
else return -total;
}
[/source]

Ok, now i have this situation as you can see below represented in this Picture :

http://imageshack.us...notworking.jpg/


Note that red tokens represent "computer".
Instead of moving token 22 to position 19 (wich will form a new mill) , my evalFunction() makes another decision
and moves something let's say like token 21 to position 9 , or 18 to position 10.

Can you help me improve my eval function so that token 22 moves to 19 ?
( so that mill 21-22-23 breaks and token 22 forms a new mill on 18-19-20)

thanks !
Why are you not using `sign' in your evaluation function?
@alvaro : correction made to code.(sorry)
Advertisement
It looks to me like you got the sign wrong. But you should learn how to debug your code. That position seems to be solvable with a depth-1 search, and that should be relatively easy to debug.

It looks to me like you got the sign wrong. But you should learn how to debug your code. That position seems to be solvable with a depth-1 search, and that should be relatively easy to debug.


What do you mean by wrong sign ? Where ?
For both players ("computer" or "human") the function returns a positive score, i.e. everybody is trying to maximize score, right?

You're saying that at depth=1 , the function should return best move (score) ? If so, i can confirm that (it returns biggest score for current player) !
Please help .
This looks like the wrong sign:
if(sign==-1) return total;
else return -total;


But perhaps I didn't understand your sign convention.

I am not sure how to help further. You need to find a situation where the program reproducibly does the wrong thing, then carefully analyze what the program is doing, probably with the help of a debugger or perhaps just by adding a bunch of print statements to your program. Try to figure out where the program is doing something different than what you expected.

This topic is closed to new replies.

Advertisement