document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. Public Function negamax(tablero As ClassTablero, jugador As Integer, profundidad As Integer, alfa As Integer, beta As Integer) As Variant[]
  2.  
  3.   Dim alfa_local, max_puntuacion, jugada, puntuacion As Integer
  4.   Dim tableroaux As ClassTablero
  5.   Dim jugada_max As Integer
  6.   Dim JugadasPosibles As Integer[]
  7.   Dim contador As Integer
  8.   Dim opcion As Integer
  9.   Dim valorjugadorContrario As Integer = 0
  10.   Dim valorposicionContrario As Integer = 0
  11.  
  12.   max_puntuacion = - main.maximoInteger - 1
  13.   alfa_local = alfa
  14.  
  15.   \'hago un array de las jugadas que puedo hacer segun el tablero recibido.
  16.   jugadasPosibles = tablero.JugadasPosibles()
  17.  
  18.   \'repite por cada jugada posible
  19.   tableroaux = New ClassTablero(tablero)
  20.   For contador = 0 To jugadasPosibles.max
  21.    
  22.     tableroaux.insertaficha(JugadasPosibles[contador], jugador)
  23.     \'  tableroaux.muestra
  24.     If tableroaux.GameOver() Or profundidad = 0 Then
  25.       Return [EvaluaJugadaMov(tableroaux, jugador), JugadasPosibles[contador]]
  26.     Else
  27.      
  28.       puntuacion = - negamax(tableroaux, jugador * (-1), profundidad - 1, - beta, - alfa_local)[0]
  29.       tableroaux.deshacer(jugadasPosibles[contador])
  30.       If puntuacion > max_puntuacion Then
  31.         max_puntuacion = puntuacion
  32.         jugada_max = JugadasPosibles[contador]
  33.        
  34.       Else If puntuacion = max_puntuacion Then
  35.         \'de un modo aleatorio elijo una de las dos... (para que las partidas no sean iguales)
  36.        
  37.         opcion = Int(Rnd(0, 2))
  38.        
  39.         \'Print opcion; " ";
  40.        
  41.         If opcion = 0 Then
  42.           max_puntuacion = puntuacion
  43.           jugada_max = JugadasPosibles[contador]
  44.         Endif
  45.         \'poda alfa beta
  46.        
  47.         If max_puntuacion > alfa_local Then
  48.           alfa_local = max_puntuacion
  49.         Endif
  50.         \'poda....
  51.         If alfa_local >= beta Then
  52.           \'comprueba si hay lista de jugadas iguales...
  53.          
  54.           Return [alfa_local, jugada_max]
  55.          
  56.         Endif
  57.        
  58.       Endif
  59.      
  60.     Endif
  61.    
  62.   Next
  63.  
  64.   Return [max_puntuacion, jugada_max]
  65.  
  66. End
');