Mình làm game bằng j2me trên mobile.Mình đã làm được hai người chơi trên cùng 1 máy.bây giờ phải dùng thuật toán để sinh nước đi cho máy tự đánh
vấn đề của mình là khi sinh nước đi cho mỗi bên mthuwrminhf không biết lưu và duyệt nó như thế nào cho đúng.
Ai làm rồi giúp mình với
Mình code thuật toán như sau:


public int is = 1;
public Pos bestMove;
int u = 0;
int LEVER = 2;


Vector listMove = new Vector();
public int AlphaBeta(int alpha, int beta, int depth) {

if (depth == 0) {
return Eval(depth);
} else {
int best, value = 0;
best = -100000;

is = 1 - is;



if (depth == LEVER) {
listMove = genPos(is);
u = listMove.size() - 1;
}


if (depth > 0 && depth < LEVER) {
Vector m = new Vector();
m = genPos(is);
if (m.size() != 0) {
for (int i = 0; i < m.size(); i++) {
listMove.addElement(m.elementAt(i));

}
}
u = listMove.size() - 1;
}

while (u > 0 && (best < beta)) {

if (best > alpha) {
alpha = best;
}
doMove(((Pos) listMove.elementAt(u)).p, ((Pos) listMove.elementAt(u)).hangcu, ((Pos) listMove.elementAt(u)).cotcu, ((Pos) listMove.elementAt(u)).hangmoi, ((Pos) listMove.elementAt(u)).cotmoi);

if (depth > 1) {
((Pos) listMove.elementAt(u)).cha = true;
}

value = -AlphaBeta(-beta, -alpha, depth - 1);



undoMove(((Pos) listMove.elementAt(u)).p, ((Pos) listMove.elementAt(u)).hangcu, ((Pos) listMove.elementAt(u)).cotcu, ((Pos) listMove.elementAt(u)).hangmoi, ((Pos) listMove.elementAt(u)).cotmoi);

if (value > best) {
best = value;

if (depth == LEVER) {

bestMove = new Pos(((Pos) listMove.elementAt(u)).p, ((Pos) listMove.elementAt(u)).hangcu, ((Pos) listMove.elementAt(u)).cotcu, ((Pos) listMove.elementAt(u)).hangmoi, ((Pos) listMove.elementAt(u)).cotmoi,((Pos) listMove.elementAt(u)).cha);
}
}
listMove.removeElementAt(u);
u--;



if (u >= 0) {
if (((Pos) listMove.elementAt(u)).cha == true) {
undoMove(((Pos) listMove.elementAt(u)).p, ((Pos) listMove.elementAt(u)).hangcu, ((Pos) listMove.elementAt(u)).cotcu, ((Pos) listMove.elementAt(u)).hangmoi, ((Pos) listMove.elementAt(u)).cotmoi);

depth = depth + 1;
listMove.removeElementAt(u);
u--;

is = 0;
}



}

return best;
}
}
}