diff --git a/src/final-attempt/README.md b/src/final-attempt/README.md index fa441b3f1e318b65b6c14e3195f1e2b0fb3938f6..9ccf3b2f2a6ec4296f42e61245d278b4dc6e7daa 100644 --- a/src/final-attempt/README.md +++ b/src/final-attempt/README.md @@ -15,13 +15,42 @@ Title: RPG formalization in PDDL #### Introduction -RPG is the problem of a hero who needs to go through rooms with obstacles to escape from a dungeon. Each room can have an obstacle, a weapon or nothing. There are two obstacles, a monster and a trap, and a sword as a weapon. To fight against the monster, the hero must have the sword in his hands. Otherwise, the monster kills the hero. The disarm the trap, the hero must be free-handed. Therefore, if the hero has the sword in his hands, he will need to drop it. In this paper, the proposed formalization, described in details in the second and third paragraphs, allows $n$ heroes to escape the dungeon in different ways. The last two paragraphs present the results and conclusions. +RPG is the problem of a hero who needs to go through rooms with obstacles to escape from a dungeon. Each room can have an obstacle, a weapon or nothing. There are two obstacles, a monster and a trap, and a sword as a weapon. To fight against the monster, the hero must have the sword in his hands. Otherwise, the monster kills the hero. The disarm the trap, the hero must be free-handed. Therefore, if the hero has the sword in his hands, he will need to drop it. In this paper, the proposed formalization, described in details in the section **Problem formalization**, allows $n$ heroes to escape the dungeon in different ways. The last two paragraphs present the results and conclusions. #### Problem formalization -First, seven predicates were used to formalize the problem. `hero_at` will keep the room in which each hero is. +Eight predicates were used to formalize the problem. Five of them, `hero_at`, `goal_at`, `monster_angry`, `trap_armed` and `sword_at`, are used to define the rooms where the heroes, goals, monsters and weapons are. The `visited_room` predicate stores all rooms that have already been visited by one of the heroes. This predicate ensures that, as soon as the hero leaves, the room will be destroyed. The `valid_move` and `empty_handed` predicates store the corridors that connect the rooms and whether the hero has a sword in his hands, respectively. -As it is possible to see, the parameters shared by the predicates, are the hero and the room. Therefore, this types of data were defined in the section `:types` of PDDL. This pattern helps to better +The actions that heroes can perform are listed and explained below. It is important to note that the preconditions are described in a textual language, followed by the precondition as placed in the domain file. + +##### `:action move` + +The purpose of this action is to move the hero to the desired room, ensuring that it is a valid move. As parameters, this action receives the hero who wants to perform the action and the rooms the hero is in and wants to go, as shown below. + +``` +:parameters (?hero - hero ?from - room ?to - room) +``` + +This precondition ensures that the hero is in the room from which he is trying to move. + +``` +(hero_at ?hero ?from) +``` + +This precondition ensures that the rooms, where the hero is and where he wants to go, have a corridor between them. + +``` +(valid_move ?from ?to) +``` + +Next two preconditions ensures that none of the heroes have visited that rooms before. + +``` +(not (visited_room ?from)) +(not (visited_room ?to)) +``` + +As it is possible to see, the parameters shared by the predicates, are the hero and the room. Therefore, the types `hero` and `room` were defined in the section `:types` of PDDL domain file. According to **Haslum et al., 2019**, `:types` restricts the parameters to the specified type. Declaring types for predicates is only helpful for validators. The actual type of the parameters will be defined in the initial state declared in the problem file. @@ -29,4 +58,8 @@ The rooms can be described as a matrix $m{\times}n$. visited must be for each hero -The formalization dont get a sword when not needed \ No newline at end of file +The formalization dont get a sword when not needed + +#### References + +PDDL book \ No newline at end of file diff --git a/src/final-attempt/pb2goal.pddl b/src/final-attempt/pb2goal.pddl new file mode 100644 index 0000000000000000000000000000000000000000..fc0ae388890b44c665cbb9355f0c042f2a372aea --- /dev/null +++ b/src/final-attempt/pb2goal.pddl @@ -0,0 +1,35 @@ +(define (problem pb2goal) + (:domain rpggoal) + + (:objects + room_1 room_2 room_3 + room_4 room_5 room_6 - room + hero_1 - hero + ) + + (:init + (hero_at hero_1 room_2) + (empty_handed hero_1) + (monster_angry room_1) + (monster_angry room_5) + (sword_at room_6) + (valid_move room_1 room_2) + (valid_move room_1 room_4) + (valid_move room_2 room_1) + (valid_move room_2 room_3) + (valid_move room_2 room_5) + (valid_move room_3 room_2) + (valid_move room_3 room_6) + (valid_move room_4 room_1) + (valid_move room_4 room_5) + (valid_move room_5 room_4) + (valid_move room_5 room_2) + (valid_move room_5 room_6) + (valid_move room_6 room_5) + (valid_move room_6 room_3) + ) + + (:goal (and + (hero_at hero_1 room_4) + )) +) \ No newline at end of file diff --git a/src/final-attempt/rpg.pddl b/src/final-attempt/rpg.pddl index e798943d74831b26382d7d5070e7f1f0a00a0f54..039fef5ae85f66056e8ba683f6ab4cebe8240d4e 100644 --- a/src/final-attempt/rpg.pddl +++ b/src/final-attempt/rpg.pddl @@ -12,7 +12,7 @@ (monster_angry ?x - room) (trap_armed ?x - room) (sword_at ?x - room) - (visited ?x - room) + (visited_room ?x - room) (valid_move ?from - room ?to - room) (empty_handed ?x - hero) ) @@ -22,8 +22,8 @@ :precondition (and (hero_at ?hero ?from) ; Hero must be at ?from room. (valid_move ?from ?to) ; It must to be a valid move on the board. - (not (visited ?from)) ; The room can not have been visited. - (not (visited ?to)) ; The room can not have been visited. + (not (visited_room ?from)) ; The room can not have been visited. + (not (visited_room ?to)) ; The room can not have been visited. (not (trap_armed ?from)) ; Hero can not move with an armed trap. (not (monster_angry ?from)) ; Hero can not move with the monster angry. (not (and @@ -35,7 +35,7 @@ :effect (and (hero_at ?hero ?to) ; Hero changes position. - (visited ?from) ; ?from has now been visited. + (visited_room ?from) ; ?from has now been visited. ) ) @@ -43,7 +43,7 @@ :parameters (?hero - hero ?location - room) :precondition (and (hero_at ?hero ?location) ; Hero must be at ?location room. - (not (visited ?location)) ; The room can not have been visited. + (not (visited_room ?location)) ; The room can not have been visited. (sword_at ?location) ; Sword must be at ?location room. (empty_handed ?hero) ; Hero does not have a sword. ) diff --git a/src/final-attempt/rpggoal.pddl b/src/final-attempt/rpggoal.pddl index 7b8db19274cc1bf0522bad9ca8e46010e4663084..faf60761f83aedf7aa7e047e75fc71563be95934 100644 --- a/src/final-attempt/rpggoal.pddl +++ b/src/final-attempt/rpggoal.pddl @@ -13,7 +13,7 @@ (monster_angry ?x - room) (trap_armed ?x - room) (sword_at ?x - room) - (visited ?x - room) + (visited_room ?x - room) (valid_move ?from - room ?to - room) (empty_handed ?x - hero) ) @@ -24,8 +24,8 @@ (not (goal_at ?hero ?from)) ; Ensures that the hero has not yet reached the goal. (hero_at ?hero ?from) ; Hero must be at ?from room. (valid_move ?from ?to) ; It must to be a valid move on the board. - (not (visited ?from)) ; The room can not have been visited. - (not (visited ?to)) ; The room can not have been visited. + (not (visited_room ?from)) ; The room can not have been visited. + (not (visited_room ?to)) ; The room can not have been visited. (not (trap_armed ?from)) ; Hero can not move with an armed trap. (not (monster_angry ?from)) ; Hero can not move with the monster angry. (not (and @@ -37,7 +37,7 @@ :effect (and (hero_at ?hero ?to) ; Hero changes position. - (visited ?from) ; ?from has now been visited. + (visited_room ?from) ; ?from has now been visited. ) ) @@ -45,7 +45,7 @@ :parameters (?hero - hero ?location - room) :precondition (and (hero_at ?hero ?location) ; Hero must be at ?location room. - (not (visited ?location)) ; The room can not have been visited. + (not (visited_room ?location)) ; The room can not have been visited. (sword_at ?location) ; Sword must be at ?location room. (empty_handed ?hero) ; Hero does not have a sword. )