Advertisement
Markax

Untitled

May 3rd, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5.  
  6. package othello.Utils;
  7.  
  8. /**
  9. *
  10. * @author user
  11. */
  12. public class Heuristica {
  13.  
  14.  
  15. public static int h1(Tablero tablero, int playerColor)
  16. {
  17.  
  18. int score = Puntos(playerColor, tablero) - Puntos(-playerColor, tablero);
  19. int negras = -1;
  20. int blancas = 1;
  21.  
  22. int filas = tablero.getCantidadFilas();
  23. int columnas = tablero.getCanidadColumnas();
  24.  
  25. // Si el juego se ha terminado.
  26. if (tablero.EsFinalDeJuego()) {
  27. // if player has won
  28. if (score > 0) {
  29. return 100;
  30. } // if player has lost (or tied)
  31. else {
  32. return -100;
  33. }
  34. } else {
  35. int esquina = 0;
  36. Casilla[][] valorActual;
  37. valorActual = tablero.getMatrizTablero();
  38.  
  39. //JUGADOR DE FICHAS NEGRAS:
  40. if (playerColor == negras) {
  41.  
  42. if (valorActual[0][0].esNegra()) esquina = esquina + 15;
  43.  
  44. if (valorActual[0][columnas - 1].esNegra()) esquina = esquina + 15;
  45.  
  46. if (valorActual[filas - 1][0].esNegra()) esquina = esquina + 15;
  47.  
  48. if (valorActual[filas - 1][columnas - 1].esNegra()) esquina = esquina + 15;
  49.  
  50. //JUGADOR DE FICHAS BLANCAS:
  51. } else {
  52.  
  53. if (valorActual[0][0].esBlanca())esquina = esquina + 15;
  54.  
  55. if (valorActual[0][columnas - 1].esBlanca()) esquina = esquina + 15;
  56.  
  57. if (valorActual[filas - 1][0].esBlanca()) esquina = esquina + 15;
  58.  
  59. if (valorActual[filas - 1][columnas - 1].esBlanca()) esquina = esquina + 15;
  60. }
  61.  
  62. return score + esquina;
  63. }
  64. }
  65.  
  66.  
  67. //Una heuristica posible a usar
  68. public static int h2(Tablero tablero,int playerColor)
  69. {
  70. int score = Puntos(playerColor, tablero) - Puntos(-playerColor, tablero);
  71.  
  72. // If the game is over
  73. if (tablero.EsFinalDeJuego())
  74. {
  75. // if player has won
  76. if (score > 0)
  77. return 100;
  78. // if player has lost (or tied)
  79. else
  80. return -100;
  81. }
  82.  
  83. // if game isn't over, return relative advatage
  84. return score;
  85. }
  86.  
  87. public static int Puntos(int playerColor, Tablero tablero)
  88. {
  89. int points = 0;
  90.  
  91. for (int x = 0; x < Tablero.CANTIDAD_FILAS_DEFECTO; x++)
  92. for (int y = 0; y < Tablero.CANTIDAD_COLUMNAS_DEFECTO; y++)
  93. if (tablero.getMatrizTablero()[x][y].obtenerColorFicha() == playerColor)
  94. points++;
  95.  
  96. return points;
  97. }
  98.  
  99.  
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement