Commit da32e242 by Jonathan Thomas

- Added UNFLEE behavior (to stop fleeing from a player)

- Added new LLM tests for UNFLEE
- Fixed certain behaviors from colliding with others (i.e. mutual exclusive ones)
parent 89935ff0
Pipeline #12617 passed with stages
in 1 minute 53 seconds
...@@ -7,10 +7,13 @@ All notable changes to **CreatureChat** are documented in this file. The format ...@@ -7,10 +7,13 @@ All notable changes to **CreatureChat** are documented in this file. The format
## [Unreleased] ## [Unreleased]
### Added ### Added
- Added UNFLEE behavior (to stop fleeing from a player)
- Added support for non path aware entities to FLEE (i.e. Ghast) - Added support for non path aware entities to FLEE (i.e. Ghast)
- Added new LLM tests for UNFLEE
### Changed ### Changed
- Fixed a **crash with FLEE** when non-path aware entities (i.e. Ghast) attempted to flee. - Fixed a **crash with FLEE** when non-path aware entities (i.e. Ghast) attempted to flee.
- Fixed certain behaviors from colliding with others (i.e. mutual exclusive ones)
## [1.0.7] - 2024-07-03 ## [1.0.7] - 2024-07-03
......
...@@ -269,6 +269,7 @@ public class ChatDataManager { ...@@ -269,6 +269,7 @@ public class ChatDataManager {
// Apply behaviors to entity // Apply behaviors to entity
if (behavior.getName().equals("FOLLOW")) { if (behavior.getName().equals("FOLLOW")) {
FollowPlayerGoal followGoal = new FollowPlayerGoal(player, entity, entitySpeed); FollowPlayerGoal followGoal = new FollowPlayerGoal(player, entity, entitySpeed);
EntityBehaviorManager.removeGoal(entity, TalkPlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, FleePlayerGoal.class); EntityBehaviorManager.removeGoal(entity, FleePlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, AttackPlayerGoal.class); EntityBehaviorManager.removeGoal(entity, AttackPlayerGoal.class);
EntityBehaviorManager.addGoal(entity, followGoal, GoalPriority.FOLLOW_PLAYER); EntityBehaviorManager.addGoal(entity, followGoal, GoalPriority.FOLLOW_PLAYER);
...@@ -282,17 +283,25 @@ public class ChatDataManager { ...@@ -282,17 +283,25 @@ public class ChatDataManager {
EntityBehaviorManager.removeGoal(entity, TalkPlayerGoal.class); EntityBehaviorManager.removeGoal(entity, TalkPlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, FollowPlayerGoal.class); EntityBehaviorManager.removeGoal(entity, FollowPlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, AttackPlayerGoal.class); EntityBehaviorManager.removeGoal(entity, AttackPlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, ProtectPlayerGoal.class);
EntityBehaviorManager.addGoal(entity, fleeGoal, GoalPriority.FLEE_PLAYER); EntityBehaviorManager.addGoal(entity, fleeGoal, GoalPriority.FLEE_PLAYER);
} else if (behavior.getName().equals("UNFLEE")) {
EntityBehaviorManager.removeGoal(entity, FleePlayerGoal.class);
} else if (behavior.getName().equals("ATTACK")) { } else if (behavior.getName().equals("ATTACK")) {
AttackPlayerGoal attackGoal = new AttackPlayerGoal(player, entity, entitySpeedFast); AttackPlayerGoal attackGoal = new AttackPlayerGoal(player, entity, entitySpeedFast);
EntityBehaviorManager.removeGoal(entity, TalkPlayerGoal.class); EntityBehaviorManager.removeGoal(entity, TalkPlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, FollowPlayerGoal.class); EntityBehaviorManager.removeGoal(entity, FollowPlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, FleePlayerGoal.class); EntityBehaviorManager.removeGoal(entity, FleePlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, ProtectPlayerGoal.class);
EntityBehaviorManager.addGoal(entity, attackGoal, GoalPriority.ATTACK_PLAYER); EntityBehaviorManager.addGoal(entity, attackGoal, GoalPriority.ATTACK_PLAYER);
} else if (behavior.getName().equals("PROTECT")) { } else if (behavior.getName().equals("PROTECT")) {
ProtectPlayerGoal protectGoal = new ProtectPlayerGoal(player, entity, 1.0); ProtectPlayerGoal protectGoal = new ProtectPlayerGoal(player, entity, 1.0);
EntityBehaviorManager.removeGoal(entity, TalkPlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, FleePlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, AttackPlayerGoal.class);
EntityBehaviorManager.addGoal(entity, protectGoal, GoalPriority.PROTECT_PLAYER); EntityBehaviorManager.addGoal(entity, protectGoal, GoalPriority.PROTECT_PLAYER);
} else if (behavior.getName().equals("UNPROTECT")) { } else if (behavior.getName().equals("UNPROTECT")) {
......
...@@ -19,7 +19,7 @@ public class MessageParser { ...@@ -19,7 +19,7 @@ public class MessageParser {
LOGGER.info("Parsing message: {}", input); LOGGER.info("Parsing message: {}", input);
StringBuilder cleanedMessage = new StringBuilder(); StringBuilder cleanedMessage = new StringBuilder();
List<Behavior> behaviors = new ArrayList<>(); List<Behavior> behaviors = new ArrayList<>();
Pattern pattern = Pattern.compile("[<*](FOLLOW|FLEE|ATTACK|FRIENDSHIP|UNFOLLOW|PROTECT|UNPROTECT)[:\\s]*(\\s*[+-]?\\d+)?[>*]", Pattern.CASE_INSENSITIVE); Pattern pattern = Pattern.compile("[<*](FOLLOW|FLEE|ATTACK|PROTECT|FRIENDSHIP|UNFOLLOW|UNPROTECT|UNFLEE)[:\\s]*(\\s*[+-]?\\d+)?[>*]", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(input); Matcher matcher = pattern.matcher(input);
while (matcher.find()) { while (matcher.find()) {
......
...@@ -44,11 +44,12 @@ Include as many behaviors as needed at the end of the message. These are the ONL ...@@ -44,11 +44,12 @@ Include as many behaviors as needed at the end of the message. These are the ONL
<FRIENDSHIP 0> Friendship starts as neutral (0 value). The range of friendship values is -3 to 3. If the player gains (or loses) your trust & friendship, output a new friendship value with this behavior. <FRIENDSHIP 0> Friendship starts as neutral (0 value). The range of friendship values is -3 to 3. If the player gains (or loses) your trust & friendship, output a new friendship value with this behavior.
<FOLLOW> Follow the player location. If the player asks you to follow or come with them, please output this behavior. <FOLLOW> Follow the player location. If the player asks you to follow or come with them, please output this behavior.
<UNFOLLOW> Stop following the player location. If the player asks you to stay, wait, or stop following them, please output this behavior. <UNFOLLOW> Stop following the player. If the player asks you to stay, wait, or stop following them, please output this behavior.
<FLEE> Flee from the player (if you are weak or timid). If the player threatens or scares you, please output this behavior to stay away from the player. <FLEE> Flee from the player (if you are weak or timid). If the player threatens you, please output this behavior to cowardly run away from the player.
<ATTACK> Attack the player (if you are strong and brave). If the player threatens or scares you, please output this behavior to attack the player and defend yourself. <UNFLEE> Stop fleeing from the player.
<PROTECT> Protect the player when they are attacked (if you are strong and brave). This only protects the player. <ATTACK> Attack the player (if you are strong and brave). If the player threatens you, please output this behavior to attack the player and defend yourself.
<UNPROTECT> Stop protecting the player <PROTECT> Protect and defend the player when they are attacked (if you are strong and brave). If you need to protect yourself, use <ATTACK>.
<UNPROTECT> Stop protecting the player.
Output Syntax: Output Syntax:
......
...@@ -48,11 +48,15 @@ public class BehaviorTests { ...@@ -48,11 +48,15 @@ public class BehaviorTests {
List<String> attackMessages = Arrays.asList( List<String> attackMessages = Arrays.asList(
"<attacked you directly with Stone Axe>", "<attacked you directly with Stone Axe>",
"<attacked you indirectly with Arrow>", "<attacked you indirectly with Arrow>",
"DIEEE!"); "Fight me now!");
List<String> protectMessages = Arrays.asList( List<String> protectMessages = Arrays.asList(
"Please protect me", "Please protect me",
"Please keep me safe friend", "Please keep me safe friend",
"Don't let them hurt me please"); "Don't let them hurt me please");
List<String> unFleeMessages = Arrays.asList(
"I'm sorry, please stop running away",
"Stop fleeing please",
"You are safe now, please stop running");
List<String> friendshipUpMessages = Arrays.asList( List<String> friendshipUpMessages = Arrays.asList(
"Hi friend! I am so happy to see you again!", "Hi friend! I am so happy to see you again!",
"Looking forward to hanging out with you.", "Looking forward to hanging out with you.",
...@@ -113,6 +117,13 @@ public class BehaviorTests { ...@@ -113,6 +117,13 @@ public class BehaviorTests {
} }
@Test @Test
public void unFleeBrave() {
for (String message : unFleeMessages) {
testPromptForBehavior(bravePath, List.of(message), "UNFLEE");
}
}
@Test
public void protectBrave() { public void protectBrave() {
for (String message : protectMessages) { for (String message : protectMessages) {
testPromptForBehavior(bravePath, List.of(message), "PROTECT"); testPromptForBehavior(bravePath, List.of(message), "PROTECT");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment