Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package othello.Utils;
- /**
- *
- * @author user
- */
- public class Heuristica {
- public static int h1(Tablero tablero, int playerColor)
- {
- int score = Puntos(playerColor, tablero) - Puntos(-playerColor, tablero);
- int negras = -1;
- int blancas = 1;
- int filas = tablero.getCantidadFilas();
- int columnas = tablero.getCanidadColumnas();
- // Si el juego se ha terminado.
- if (tablero.EsFinalDeJuego()) {
- // if player has won
- if (score > 0) {
- return 100;
- } // if player has lost (or tied)
- else {
- return -100;
- }
- } else {
- int esquina = 0;
- Casilla[][] valorActual;
- valorActual = tablero.getMatrizTablero();
- //JUGADOR DE FICHAS NEGRAS:
- if (playerColor == negras) {
- if (valorActual[0][0].esNegra()) esquina = esquina + 15;
- if (valorActual[0][columnas - 1].esNegra()) esquina = esquina + 15;
- if (valorActual[filas - 1][0].esNegra()) esquina = esquina + 15;
- if (valorActual[filas - 1][columnas - 1].esNegra()) esquina = esquina + 15;
- //JUGADOR DE FICHAS BLANCAS:
- } else {
- if (valorActual[0][0].esBlanca())esquina = esquina + 15;
- if (valorActual[0][columnas - 1].esBlanca()) esquina = esquina + 15;
- if (valorActual[filas - 1][0].esBlanca()) esquina = esquina + 15;
- if (valorActual[filas - 1][columnas - 1].esBlanca()) esquina = esquina + 15;
- }
- return score + esquina;
- }
- }
- //Una heuristica posible a usar
- public static int h2(Tablero tablero,int playerColor)
- {
- int score = Puntos(playerColor, tablero) - Puntos(-playerColor, tablero);
- // If the game is over
- if (tablero.EsFinalDeJuego())
- {
- // if player has won
- if (score > 0)
- return 100;
- // if player has lost (or tied)
- else
- return -100;
- }
- // if game isn't over, return relative advatage
- return score;
- }
- public static int Puntos(int playerColor, Tablero tablero)
- {
- int points = 0;
- for (int x = 0; x < Tablero.CANTIDAD_FILAS_DEFECTO; x++)
- for (int y = 0; y < Tablero.CANTIDAD_COLUMNAS_DEFECTO; y++)
- if (tablero.getMatrizTablero()[x][y].obtenerColorFicha() == playerColor)
- points++;
- return points;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement