-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoToAsteroidAction.java
More file actions
39 lines (31 loc) · 1.08 KB
/
GoToAsteroidAction.java
File metadata and controls
39 lines (31 loc) · 1.08 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
package grah8384;
import spacesettlers.objects.Asteroid;
import spacesettlers.objects.Ship;
import spacesettlers.objects.resources.ResourcePile;
public class GoToAsteroidAction extends GoToAction {
public GoToAsteroidAction(Ship ship, Asteroid asteroid) {
this.ship = ship;
this.goal = asteroid;
}
public boolean isApplicable(StateRepresentation state) {
return super.isApplicable(state) && state.energy.get(ship.getId()) > 1500 && state.resources.get(ship.getId()).getTotal()/state.energy.get(ship.getId()) < 1;
}
/**
* Add effects of this action to the state
* @param state
*/
public StateRepresentation effects(StateRepresentation state) {
StateRepresentation result = super.effects(state);
//Get resources from asteroid
result.addResources(ship.getId(), goal.getResources());
//Remove the asteroid from the state
result.removeObject(goal);
return result;
}
public ResourcePile getResources() {
return goal.getResources();
}
public double getPathCost(StateRepresentation state) {
return super.getPathCost(state)/goal.getResources().getTotal();
}
}