Encontre hace tiempo el juego del 3 en raya o Gato implementado con el algoritmo MiniMAx.
Aqui sus créditos del autor del Gato con Minimax
* Autor: Francisco I. Leyva
* Página web:
http://www.panchosoft.comIndagando con google logré implementar la
Poda Alfa-Beta a este juego, y
la opción de cambiar la apariencia con LookAndFeel dejo los créditos
del autor inicial por supuesto.
Sobre
Poda Alfa-Beta hay mucho material en la web, pero no muchos ejemplos concretos dejo el proyecto completo =).
Capturas:
// Poda Alfa-Beta con profundidad
private Movement MiniMaxAlphaBetaDepth(Board board,int player,int depth,int alpha,int beta)
{ if (board.GameEnded() || depth==6)
{ Movement mov = new Movement();
//mov.Value = board.Winner();
mov.Value = Utilidad(board.iTablero);
return mov;
}
else
{ Vector successors
= board.
GetAllowedMovements(true); Movement best = null;
for ( Iterator ite
= successors.
iterator(); ite.
hasNext(); ) { int successor
= (Integer)(ite.
next()); Board successorBoard = (Board)board.Clone();
successorBoard.ApplyMovement(successor);
Movement tmp = MiniMaxAlphaBetaDepth(successorBoard, -player, depth+1, alpha, beta);
if (best == null || (player == -1 && tmp.Value < best.Value) ||
(player == 1 && tmp.Value > best.Value))
best = tmp;
}
if (player == -1 && best.Value < beta)
{ beta = best.Value; }
if (player == 1 && best.Value > alpha) alpha = best.Value;
if (alpha > beta) return best;
}
return best;
}
}
Proyecto en google docs