Package prop.hex.domini.controladors.IA.auxiliars

Examples of prop.hex.domini.controladors.IA.auxiliars.ElementTaulaTransposicions


    int beta_2, puntuacio;
    if ( profunditat == profunditat_maxima || estat_iteracio != EstatPartida.NO_FINALITZADA )
    {
      puntuacio = funcioAvaluacio( tauler, estat_iteracio, profunditat, jugador );
      taula_transposicions.put( tauler.hashCode(),
          new ElementTaulaTransposicions( partida.getTornsJugats() + profunditat, FitesDePoda.VALOR_EXACTE,
              puntuacio, jugador ) );
      return puntuacio;
    }

    if ( taula_transposicions.containsKey( tauler.hashCode() ) )
    {
      ElementTaulaTransposicions element = taula_transposicions.get( tauler.hashCode() );
      if ( element.getProfunditat() >= partida.getTornsJugats() + profunditat )
      {
        switch ( element.getFita( jugador ) )
        {
          case FITA_INFERIOR:
            alfa = Math.max( alfa, element.getPuntuacio( jugador ) );
            break;
          case FITA_SUPERIOR:
            beta = Math.min( beta, element.getPuntuacio( jugador ) );
            break;
          case VALOR_EXACTE:
            return element.getPuntuacio( jugador );
        }

        if ( alfa >= beta )
        {
          return alfa;
        }
      }
    }

    int caselles_restants = tauler.getMida() * tauler.getMida() - tauler.getTotalFitxes();
    int max_moviments = Math.max( caselles_restants / ( int ) ( Math.sqrt( tauler.getMida() ) * 0.85 ), 7 );

    beta_2 = beta;
    boolean primer_fill = true;
    FitesDePoda fita = FitesDePoda.FITA_SUPERIOR;
    boolean[][] explorades = new boolean[tauler.getMida()][tauler.getMida()];
    int num_explorades = 0;
    while ( num_explorades < max_moviments && num_explorades < caselles_restants )
    {
      Casella actual =
          new Casella( generador.nextInt( tauler.getMida() ), generador.nextInt( tauler.getMida() ) );
      if ( tauler.esMovimentValid( contrincant, actual ) && !explorades[actual.getFila()][actual.getColumna()] )
      {
        explorades[actual.getFila()][actual.getColumna()] = true;
        num_explorades++;
        tauler.mouFitxa( contrincant, actual );
        estat_iteracio = partida.comprovaEstatPartida( actual.getFila(), actual.getColumna() );
        puntuacio = -negaMonteScout( contrincant, jugador, -beta_2, -alfa, profunditat + 1, estat_iteracio );

        if ( alfa < puntuacio && puntuacio < beta && !primer_fill )
        {
          fita = FitesDePoda.VALOR_EXACTE;
          puntuacio = -negaMonteScout( contrincant, jugador, -beta, -alfa, profunditat + 1, estat_iteracio );
        }

        tauler.treuFitxa( actual );

        if ( alfa < puntuacio )
        {
          fita = FitesDePoda.VALOR_EXACTE;
          alfa = puntuacio;
        }

        if ( alfa >= beta )
        {
          taula_transposicions.put( tauler.hashCode(),
              new ElementTaulaTransposicions( partida.getTornsJugats() + profunditat,
                  FitesDePoda.FITA_INFERIOR, alfa, jugador ) );
          return alfa;
        }

        beta_2 = alfa + 1;
        primer_fill = false;
      }
    }

    taula_transposicions.put( tauler.hashCode(),
        new ElementTaulaTransposicions( partida.getTornsJugats() + profunditat, fita, alfa, jugador ) );

    return alfa;
  }
View Full Code Here


    int beta_2, puntuacio;
    if ( cost >= pressupost || profunditat >= profunditat_maxima || estat_iteracio != EstatPartida.NO_FINALITZADA )
    {
      puntuacio = funcioAvaluacio( tauler, estat_iteracio, profunditat, jugador );
      taula_transposicions.put( tauler.hashCode(),
          new ElementTaulaTransposicions( partida.getTornsJugats() + profunditat, FitesDePoda.VALOR_EXACTE,
              puntuacio, jugador ) );
      return puntuacio;
    }

    if ( taula_transposicions.containsKey( tauler.hashCode() ) )
    {
      ElementTaulaTransposicions element = taula_transposicions.get( tauler.hashCode() );
      if ( element.getProfunditat() >= partida.getTornsJugats() + profunditat )
      {
        switch ( element.getFita( jugador ) )
        {
          case FITA_INFERIOR:
            alfa = Math.max( alfa, element.getPuntuacio( jugador ) );
            break;
          case FITA_SUPERIOR:
            beta = Math.min( beta, element.getPuntuacio( jugador ) );
            break;
          case VALOR_EXACTE:
            return element.getPuntuacio( jugador );
        }

        if ( alfa >= beta )
        {
          return alfa;
        }
      }
    }

    beta_2 = beta;
    boolean primer_fill = true;
    FitesDePoda fita = FitesDePoda.FITA_SUPERIOR;
    Set<ResistenciaCasella> moviments_ordenats = movimentsOrdenats( contrincant );
    int resistencia_minima = moviments_ordenats.iterator().next().getResistencia();

    Iterator<ResistenciaCasella> moviments = moviments_ordenats.iterator();
    ResistenciaCasella resistencia_actual;

    while ( moviments.hasNext() &&
            ( resistencia_actual = moviments.next() ).getResistencia() <= resistencia_minima + 2 )
    {
      Casella actual = resistencia_actual.getCasella();
      tauler.mouFitxa( contrincant, actual );
      estat_iteracio = partida.comprovaEstatPartida( actual.getFila(), actual.getColumna() );
      puntuacio = -sexSearch( contrincant, jugador, -beta_2, -alfa, profunditat + 1,
          cost + resistencia_actual.getResistencia(), estat_iteracio );

      if ( alfa < puntuacio && puntuacio < beta && !primer_fill )
      {
        fita = FitesDePoda.VALOR_EXACTE;
        puntuacio = -sexSearch( contrincant, jugador, -beta, -alfa, profunditat + 1,
            cost + resistencia_actual.getResistencia(), estat_iteracio );
      }

      tauler.treuFitxa( actual );

      if ( alfa < puntuacio )
      {
        fita = FitesDePoda.VALOR_EXACTE;
        alfa = puntuacio;
      }

      if ( alfa >= beta )
      {
        taula_transposicions.put( tauler.hashCode(),
            new ElementTaulaTransposicions( partida.getTornsJugats() + profunditat,
                FitesDePoda.FITA_INFERIOR, alfa, jugador ) );
        return alfa;
      }

      beta_2 = alfa + 1;
      primer_fill = false;
    }

    taula_transposicions.put( tauler.hashCode(),
        new ElementTaulaTransposicions( partida.getTornsJugats() + profunditat, fita, alfa, jugador ) );

    return alfa;
  }
View Full Code Here

TOP

Related Classes of prop.hex.domini.controladors.IA.auxiliars.ElementTaulaTransposicions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.