Dear all,
I acutally tried to post this question once before - but it seems it did't go through, so please accept my apologies if the quetion is in here twice now (in case I overlooked it somehow)...
So, I have the following problem:
My agents intention is interruped by a subintention every few hours, which also changes the target it goes to. Movement is controlled by an action with target:target. The problem is, though, that the subintention overwrites the target of the main-intention completely - so when the agent goes back to the main-intention, it defines a completely new target again, which it only should do, if target = nil - it should not set target to nil at any point in the code. Is there any elegan solution for that I can't think of - probably my brain is just stuck somehow :/
I thought of creating a second movement action, but would that change anything, as the target is apparently deleated?
Or maybe creating a list of the last target somehow - but it also seems to be a bit complicated or unelegant.
Do you have any suggestion or solution for that?
Here is the code I used for this:
The main intention and plan:
plan letsExchange intention: tp_location {
if (is_resting = false){
if (jadeite_value >0){
if (target = nil){ // if there is no defined target (tp)
write "no tp found";
do add_subintention(tp_location, define_tp_target, true); // it develops a sub-goal of finding a target to go to
do current_intention_on_hold;
} else { // if it has a target it goes there
write "my current tp is" + (target.location);
do paddle;
(...)
The definition of the target-trading partner:
plan choose_tp_target intention: define_tp_target instantaneous: true{ // to find a tp, the boat makes subtracts the tps with full stock from the others
list<point> possible_tps <- get_beliefs(new_predicate("tp_location")) collect (point(get_predicate(mental_state (each)).values["tp_location_value"]));
list<point> full_tps <- get_beliefs_with_name(tp_full_location) collect (point(get_predicate(mental_state (each)).values["tp_full_location_value"]));
possible_tps <- possible_tps - full_tps;
if (empty(possible_tps)) { // if there are no tps left, it removes the intention of exchanging
do remove_intention(tp_location, true);
if (is_home = false){
do add_subintention (define_tp_target, go_home_desire, true) strength: 10.0;
} else {
do add_subintention (define_tp_target, use_jadeite, true) strength: 10.0;
}
write "no tps left";
} else {
trading_partners current_tp <- trading_partners(one_of(possible_tps));
target <- (current_tp).location; // otherwise it picks one of the tps as a new target
}
do remove_intention(define_tp_target, true); // and removes the desire to choose a tp
}
The sub-intention to seek shelter:
plan seek_shelter intention: escape finished_when: has_emotion(fearConfirmed) {
color <- #yellow;
list<point> coast_locations <- get_beliefs(new_predicate("coast_location")) collect (point(get_predicate(mental_state (each)).values["coast_location_value"]));
target <- (coast_locations with_min_of(each.location distance_to location)).location;
do paddle;
if (location distance_to target < 0.5#km){
do add_belief (has_shelter);
do add_belief (no_danger);
do remove_emotion (fear);
do remove_emotion (fearConfirmed);
seek_shelter_mode <- false;
is_resting <- true;
write "I'm resting";
energy_level <- max_energy_level;
do remove_intention (escape, true);
}
}
And the action for the movement:
action paddle {
if (energy_level >10.0){
path paddle_path <- self goto (target:target, speed: speed, recompute_path: false, return_path:true);
my_path <-my_path = nil ? paddle_path.shape : (my_path union paddle_path.shape);
if (has_emotion (fearConfirmed)){
energy_level <- energy_level -8;}
else {
energy_level <- energy_level -5;
}
} else {
energy_level <- energy_level +10;
}
}
Thanks a lot in advance for any suggestion!! All the best,
Sheba