All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.unibo.jakta.agents.bdi.actions.impl.AbstractAction.kt Maven / Gradle / Ivy

package it.unibo.jakta.agents.bdi.actions.impl

import it.unibo.jakta.agents.bdi.actions.Action
import it.unibo.jakta.agents.bdi.actions.ActionRequest
import it.unibo.jakta.agents.bdi.actions.ActionResponse
import it.unibo.jakta.agents.bdi.actions.effects.SideEffect
import it.unibo.tuprolog.core.Substitution
import it.unibo.tuprolog.solve.Signature

abstract class AbstractAction, Req : ActionRequest> (
    override val signature: Signature,
) : Action {

    protected var result: Substitution = Substitution.empty()

    protected val effects: MutableList = mutableListOf()

    final override fun execute(request: Req): Res {
        if (request.arguments.size > signature.arity) {
            throw IllegalArgumentException("ERROR: Wrong number of arguments for action ${signature.name}")
        }
        action(request)
        val res = request.reply(result, effects.toMutableList())
        effects.clear()
        return res
    }

    override fun addResults(substitution: Substitution) {
        result = substitution
    }

    abstract fun action(request: Req)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy