Public Group

# Minimax move storage

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

## 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.

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002291
×