summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical/pacman/PacMan.java
blob: 5458dd5d17cfed5e9a923c1244992be40497efa0 (plain)
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 ch.epfl.maze.physical.pacman;

import ch.epfl.maze.physical.Animal;
import ch.epfl.maze.physical.Daedalus;
import ch.epfl.maze.physical.Prey;
import ch.epfl.maze.physical.stragegies.picker.RandomPicker;
import ch.epfl.maze.physical.stragegies.planner.DistanceCalculator;
import ch.epfl.maze.physical.stragegies.reducer.CostReducer;
import ch.epfl.maze.util.Direction;
import ch.epfl.maze.util.Vector2D;

import java.util.Set;

/**
 * Pac-Man character, from the famous game of the same name.
 *
 * @author EPFL
 * @author Pacien TRAN-GIRARD
 */
public class PacMan extends Prey implements DistanceCalculator, CostReducer, RandomPicker {

    /**
     * Constructs a new Pac-Man.
     *
     * @param position Starting position of the Pac-Man in the Daedalus
     */
    public PacMan(Vector2D position) {
        super(position);
    }

    @Override
    public int getChoiceCost(Direction choice, Daedalus daedalus) {
        return (-1) * daedalus
                .getPredatorSet()
                .stream()
                .map(pred -> this.getDistanceTo(choice, pred.getPosition()))
                .map(dist -> dist * 100.0d)
                .min(Double::compare)
                .get()
                .intValue();
    }

    @Override
    public Direction move(Set<Direction> choices, Daedalus daedalus) {
        Set<Direction> smartChoices = this.reduce(choices, daedalus);
        return this.pick(smartChoices);
    }

    @Override
    public Animal copy() {
        return new PacMan(this.getPosition());
    }

}