-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomPlanner.java
More file actions
54 lines (45 loc) · 1.49 KB
/
Copy pathRandomPlanner.java
File metadata and controls
54 lines (45 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package planners;
import actions.Action;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import storygenerator.World;
import storygenerator.WorldProperty;
/**
* This planner picks random actions at any given time.
* @author etienne
*/
public class RandomPlanner extends Planner {
public RandomPlanner(World pWorld) {
super(pWorld);
}
@Override
public boolean makePlan() {
aActionSequence = new LinkedList<Action>();
//Get all possible actions
ArrayList<Action> allActions = aWorld.getHeroActions();
//List to hold the world state and modify it
ArrayList<WorldProperty> currentWorldState = new ArrayList<WorldProperty>();
for (WorldProperty p : aWorld.getWorldState()) {
currentWorldState.add(p);
}
//Loop to add random actions
int i = 0;
while (i < MAX_LENGTH && !aWorld.getMainCharacter().checkGoalCompletion(currentWorldState)) {
Collections.shuffle(allActions, rand);
for (Action a : allActions) {
if (a.verifyPreconditions(currentWorldState)) {
aActionSequence.add(a);
i++;
a.applyPostconditions(currentWorldState);
break;
}
}
}
return true;
}
@Override
public void executePlan() {
aWorld.executeActionSequence(aActionSequence);
}
}