stuck on minimax algorithm
I'm attempting my first chess engine. Anyone who is familiar with the subject will know a thing or two about the minimax algorithm. I need to generate a combination of every possible move on the board for every piece. I've looked up a number of examples but can't get mine to work. I don't know what I am doing wrong. I'm just focused on the generation of every possible moves, to a certain depth, to get the leaf nodes.
The problem I'm facing is that my current implementation is making one move for black then making continuous moves for white without letting the black move again when it should be alternating back and fourth. I use Direct recursion to and loop through the available moves. I expect the function to start from the top every time but the direct recursion isn't working the way I thought it would. The loop keeps getting iterated through without starting from the top of the function and I don't know why. This means that the getAvailableMoves(maximizer) isn't being called every time like it should be (I think).
if anyone could point out what I'm doing wrong it would be appreciated.
public int miniMax(int depth, boolean maximizer)
{
if(depth == 0) { return 1234; }
int countMoves = 0;
Map<ChessPiece, Position> availableMoves = getAvailableMoves(maximizer);
int bestMove = 0;
for(Map.Entry<ChessPiece, Position> entry : availableMoves.entrySet())
{
ChessPiece piece = entry.getKey();
Position pos = entry.getValue();
piece.move(board, pos.getX(), pos.getY());
maximizer = !maximizer;
miniMax(depth-1, maximizer);
}
return 1234;
}
链接地址: http://www.djcxy.com/p/84632.html
下一篇: 坚持minimax算法