Bonjour,
Dans le cadre d'un projet je dois implémenter 3 algorithme:
-minmax
-negamax
-alphabeta(j'ai choisi l'alphabeta de negamax)
Minmax et negamax sont implémentés et fonctionnent bien, cependant alphabeta ne fonctionne pas du tout, pourriez vous m'indiquer ce qui ne va pas dans mon code?
Voilà ma fonction alphabeta:
Voilà la fonction où est appelée alphabeta:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 private int alphabeta(AbstractGame game, int depth, int alpha, int beta, boolean IPlay) { if (game.isFinish() || depth <= 0)return this.eval(game); TGame joueurActuel = IPlay?this.getJoueurEnnemi() : this.getJoueur(); ArrayList<Vector2d> actions = game.getPossibleActions(joueurActuel); for (Vector2d pos : actions) { game.insert(pos, joueurActuel); int score = -alphabeta(game,depth - 1, -beta, -alpha,!IPlay); game.cancel(); if (score >= alpha) { alpha = score ; } if (alpha >= beta) { bestMove = pos; return alpha; } } return alpha; }
Merci d'avance pour vos réponses et pour votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 @Override public Vector2d getBestPosition(AbstractGame game) { bestMove = null; this.alphabeta(game, this.getProfondeur(), Integer.MIN_VALUE, Integer.MAX_VALUE, true); return bestMove; }
Partager