summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical/stragegies/reducer/CaseReducer.java
blob: 71de28749ed9b4011959c0a8a3d1d93bbb32540e (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
package ch.epfl.maze.physical.stragegies.reducer;

import ch.epfl.maze.physical.Daedalus;
import ch.epfl.maze.util.Direction;

import java.util.Set;
import java.util.stream.Collectors;

/**
 * A filter reducer filtering possibilities case by case.
 *
 * @author Pacien TRAN-GIRARD
 */
public interface CaseReducer extends ChoiceReducer {

    /**
     * Checks if the given choice should be kept or excluded by the filter.
     *
     * @param choice   A Direction
     * @param daedalus The Daedalus
     * @return T(The filter should keep the given choice)
     */
    boolean keepChoice(Direction choice, Daedalus daedalus);

    @Override
    default Set<Direction> reduce(Set<Direction> choices, Daedalus daedalus) {
        return choices
                .stream()
                .filter(choice -> this.keepChoice(choice, daedalus))
                .collect(Collectors.toSet());
    }

}