Example #1
0
    protected override void ThinkAction()
    {
        // Retornamos una accion aleatoria.
        AIGameState             gameState    = gameController.GetGameState();
        List <AIRawSlimeAction> legalActions = gameState.GetLegalActions();

        if (legalActions.Count != 0)
        {
            thoughtAction = legalActions[(int)((new System.Random()).Next(legalActions.Count))].CopyToRealAction(gameController);
        }
    }
Example #2
0
    private KeyValuePair <AIRawSlimeAction, double> GetMaxValueAction(AIGameState state, int depth, double alpha, double beta)
    {
        counter++;

        /*Si nos pasamos de profundidad o el fantasma no puede hacer ninguna acción, estamos ante una hoja y devolvemos
         * la puntuación del estado actual y ninguna acción, obviamente.*/
        List <AIRawSlimeAction> legalActions = state.GetLegalActions(depth > 0);

        if (depth >= this.depth || legalActions.Count <= 0)
        {
            return(new KeyValuePair <AIRawSlimeAction, double>(null, GetStateEvaluation(state)));
        }
        //Debug.Log("MAXING: " + legalActions.Count + "actions (DEPTH=" + depth + ")");

        AIRawSlimeAction bestAction = null;
        double           bestValue  = double.MinValue;

        foreach (AIRawSlimeAction action in legalActions)
        {
            AIGameState successor = state.GetSuccessor(action);
            int         succDepth = depth + 1;//successor.GetCurrentTurn() - turn;
            double      succValue;

            // Si aun es el turno del jugador de la IA, maximizamos, sino minimizamos.
            if (successor.IsGameEndedAndWinner() != null)
            {
                succValue = GetStateEvaluation(successor);
            }
            else if (playerId == successor.GetCurrentPlayer().GetId())
            {
                succValue = GetMaxValueAction(successor, succDepth, alpha, beta).Value;
            }
            else
            {
                succValue = GetMinValueAction(successor, succDepth, alpha, beta).Value;
            }

            // Actualizamos el maximo si el actual es mayor.
            if (succValue > bestValue)
            {
                bestValue  = succValue;
                bestAction = action;
            }

            // Si es valor mayor que beta (minimo actual del minValue), no hace falta seguir
            if (bestValue > beta)
            {
                return(new KeyValuePair <AIRawSlimeAction, double>(bestAction, bestValue));
            }

            // Actualizamos el mejor valor del maxValue
            if (bestValue > alpha)
            {
                alpha = bestValue;
            }

            //if(depth == 0) Debug.Log("[MAX] " + succValue + "-" + action);
        }

        //if(depth == 0) Debug.Log("[MAX] CHOSEN: " + bestValue + "-" + bestAction);
        return(new KeyValuePair <AIRawSlimeAction, double>(bestAction, bestValue));
    }