Sign in to follow this  

Minimax move storage

This topic is 2349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I am programming a board game and I am stuck at the the minimax part of the game logic where the computer is supposed to move. I think I've essentially got the minimax algorithm down, but I do not know how to store the moves so that the computer can actually remember to go to the right position. I am trying to store an object that corresponds to a move in a vector. Here is the pseudo/c++ code:

vector list;

int computeNextMove(int depth)
{
if(gameOver() || depth <= 0){
if(playerColor == WHITE){
return whiteScore - blackScore;
}else{
return blackScore - whiteScore;
}
}
int alpha = -1000; //arbitrarily large negative number
int count = 0; //count serves to check if this is the first value we are checking in this level of the game tree

Loop through moves{
if(makeMove()){ //makes a move or skips over if its not a valid move
list.push_back(move);
int val = -computeNextMove(depth-1);
if(val > alpha){
if(count > 0){
list.pop_back();
}else{
for(int i=0; i<depth-1; i++){
list.pop_back();
count = 1;
}
}
list.pop_back();
count = 1;
alpha = val;
list.push_back(m);
}else{
list.pop_back();
}
undoLastMove();
}
return alpha;
}

The problems I have been getting with this have been that I am not getting logical answers in the list and I am not getting the number I am expecting. I am expecting to get depth number of moves in my list but it seems to be random. If there is another way to find the next move without going through dealing with a vector, I am open to any method. I don't know if I given enough information for anyone to help, so please let me know how I can better convey my problem. Thank you.

Share this post


Link to post
Share on other sites

This topic is 2349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this