1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| Public Function negamax(ByVal chessboard As bitboard, ByVal profondeur As Integer, ByVal alpha As Integer, ByVal beta As Integer) As Integer
Dim eval As New evaluation
Dim best As Integer = -(5 * valeur.val_roi)
Dim value As Integer = 0
If profondeur = 0 Then
eval.eval_all_score(chessboard)
Return eval.score
End If
Dim mvts As New mouvement.list_of_move
mvts = chessboard.generate_move
Dim nb_total As Integer = mvts.moves.Count - 1
'pour chaque coup possible
For i = 0 To nb_total
' on ajoute le coup a l echiquier
chessboard.jouer(mvts.moves.Item(i))
' on ajoute une node
add_nodes()
value = -negamax(chessboard, profondeur - 1, -beta, -alpha)
If (value > best) Then
best = value
End If
If (best > alpha) Then
alpha = best
End If
If (best >= beta) Then
' MsgBox("exit for")
Exit For
End If
chessboard.dejouer(mvts.moves.Item(i))
Next
Return best
End Function |
Partager