forked from jakta-bdi/jakta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve broadcast example implementation
- Loading branch information
1 parent
4ff8bd3
commit c53e88b
Showing
4 changed files
with
32 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...istributed-examples/src/main/kotlin/it/unibo/jakta/agents/distributed/broadcast/Common.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package it.unibo.jakta.agents.distributed.broadcast | ||
|
||
import it.unibo.jakta.agents.bdi.actions.ExternalRequest | ||
import it.unibo.jakta.agents.bdi.actions.impl.AbstractExternalAction | ||
import it.unibo.jakta.agents.bdi.environment.Environment | ||
import it.unibo.jakta.agents.bdi.messages.Achieve | ||
import it.unibo.jakta.agents.bdi.messages.Message | ||
import it.unibo.jakta.agents.bdi.messages.Tell | ||
|
||
object Common { | ||
private val broadcastAction = object : AbstractExternalAction("broadcast", 2) { | ||
override fun action(request: ExternalRequest) { | ||
val type = request.arguments[0].castToAtom() | ||
val message = request.arguments[1].castToStruct() | ||
when (type.value) { | ||
"tell" -> broadcastMessage(Message(request.sender, Tell, message)) | ||
"achieve" -> broadcastMessage( | ||
Message(request.sender, Achieve, message), | ||
) | ||
} | ||
} | ||
} | ||
|
||
val env = Environment.of( | ||
externalActions = mapOf( | ||
broadcastAction.signature.name to broadcastAction, | ||
), | ||
) | ||
} |