Beispiel #1
0
    protected override void ThinkAction()
    {
        AIRawSlimeAction action = GetActionWithAlphaBeta(gameController.GetGameState());

        // Creamos la AISlimeAction
        thoughtAction = action.CopyToRealAction(gameController);
    }
Beispiel #2
0
    public AIGameState GetSuccessor(AIRawSlimeAction action)
    {
        AIGameState succ          = GetCopy();
        int         actionSlimeId = action.GetMainSlimeId();

        // Aplicamos la accion al sucesor.
        switch (action.GetAction())
        {
        case ActionType.ATTACK:
            succ.Attack(actionSlimeId, action.GetTargetSlimeId());
            break;

        case ActionType.CONQUER:
            succ.Conquer(actionSlimeId, action.GetTileVector());
            break;

        case ActionType.SPLIT:
            succ.Split(actionSlimeId, action.GetTileVector());
            break;

        case ActionType.MOVE:
            succ.Move(actionSlimeId, action.GetTileVector());
            break;

        case ActionType.FUSION:
            succ.Fusion(actionSlimeId, action.GetTargetSlimeId());
            break;

        case ActionType.EAT:
            succ.Eat(actionSlimeId);
            break;
        }


        succ.UpdatePlayers();

        return(succ);
    }
Beispiel #3
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));
    }